Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
GlobalGroupLookup | |
100.00% |
21 / 21 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getDefinedGroups | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
getRightsForGroup | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\CentralAuth\GlobalGroup; |
22 | |
23 | use IDBAccessObject; |
24 | use MediaWiki\Extension\CentralAuth\CentralAuthDatabaseManager; |
25 | |
26 | /** |
27 | * @since 1.37 |
28 | * @author Taavi "Majavah" Väänänen <hi@taavi.wtf> |
29 | */ |
30 | class GlobalGroupLookup { |
31 | /** @var CentralAuthDatabaseManager */ |
32 | private $dbManager; |
33 | |
34 | /** |
35 | * @param CentralAuthDatabaseManager $dbManager |
36 | */ |
37 | public function __construct( CentralAuthDatabaseManager $dbManager ) { |
38 | $this->dbManager = $dbManager; |
39 | } |
40 | |
41 | /** |
42 | * Returns all defined global groups. |
43 | * @param int $flags One of the IDBAccessObject::READ_* constants |
44 | * @return string[] |
45 | */ |
46 | public function getDefinedGroups( int $flags = IDBAccessObject::READ_NORMAL ): array { |
47 | if ( ( $flags & IDBAccessObject::READ_LATEST ) == IDBAccessObject::READ_LATEST ) { |
48 | $dbr = $this->dbManager->getCentralPrimaryDB(); |
49 | } else { |
50 | $dbr = $this->dbManager->getCentralReplicaDB(); |
51 | } |
52 | return $dbr->newSelectQueryBuilder() |
53 | ->select( 'ggp_group' ) |
54 | ->distinct() |
55 | ->from( 'global_group_permissions' ) |
56 | ->recency( $flags ) |
57 | ->caller( __METHOD__ ) |
58 | ->fetchFieldValues(); |
59 | } |
60 | |
61 | /** |
62 | * Returns all rights assigned to a specified global group. |
63 | * @param string $group |
64 | * @param int $flags One of the IDBAccessObject::READ_* constants |
65 | * @return string[] |
66 | */ |
67 | public function getRightsForGroup( string $group, int $flags = IDBAccessObject::READ_NORMAL ): array { |
68 | if ( ( $flags & IDBAccessObject::READ_LATEST ) == IDBAccessObject::READ_LATEST ) { |
69 | $dbr = $this->dbManager->getCentralPrimaryDB(); |
70 | } else { |
71 | $dbr = $this->dbManager->getCentralReplicaDB(); |
72 | } |
73 | return $dbr->newSelectQueryBuilder() |
74 | ->select( 'ggp_permission' ) |
75 | ->from( 'global_group_permissions' ) |
76 | ->where( [ 'ggp_group' => $group ] ) |
77 | ->recency( $flags ) |
78 | ->caller( __METHOD__ ) |
79 | ->fetchFieldValues(); |
80 | } |
81 | } |