Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
AutopromoteConditionHookHandler | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
onAutopromoteCondition | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 |
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\Hooks\Handlers; |
22 | |
23 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
24 | use MediaWiki\User\Hook\AutopromoteConditionHook; |
25 | |
26 | class AutopromoteConditionHookHandler implements AutopromoteConditionHook { |
27 | |
28 | /** @inheritDoc */ |
29 | public function onAutopromoteCondition( $type, $args, $user, &$result ) { |
30 | if ( $type !== APCOND_CA_INGLOBALGROUPS ) { |
31 | return; |
32 | } |
33 | |
34 | // If there is no central account for this user or if the central account is not attached to the local |
35 | // user, then consider the local user to have no global groups. |
36 | $centralUser = CentralAuthUser::getInstanceByName( $user ); |
37 | if ( !$centralUser->isAttached() ) { |
38 | $result = false; |
39 | return; |
40 | } |
41 | |
42 | // Check if the central account for this user has all the required groups for the condition to be true. |
43 | $matchingGroups = array_intersect( $args, $centralUser->getGlobalGroups() ); |
44 | $result = count( $matchingGroups ) === count( $args ); |
45 | } |
46 | } |