forked from wikimedia/mediawiki-extensions-OpenStackManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenStackManagerHooks.php
34 lines (33 loc) · 902 Bytes
/
OpenStackManagerHooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
class OpenStackManagerHooks {
/**
* getUserPermissionsErrors hook
*
* @param Title $title
* @param User $user
* @param string $action
* @param $result
* @return bool
*/
public static function getUserPermissionsErrors( Title $title, User $user, $action, &$result ) {
if ( !$title->inNamespace( NS_HIERA ) ) {
return true;
}
if ( $action === 'create' || $action === 'edit' ) {
if ( !$user->isLoggedIn() ) {
$result = array( 'openstackmanager-notloggedin' );
return false;
}
$userLDAP = new OpenStackNovaUser();
if ( !$userLDAP->exists() ) {
$result = array( 'openstackmanager-nonovacred-admincreate' );
}
$project = $title->getText();
if ( !$userLDAP->inRole( 'projectadmin', $project ) && !$user->isAllowed( 'editallhiera' ) ) {
$result = array( 'openstackmanager-hiera-noadmin', $project );
return false;
}
}
return true;
}
}