diff options
author | Simon Rettberg | 2018-02-09 16:13:17 +0100 |
---|---|---|
committer | Simon Rettberg | 2018-02-09 16:13:17 +0100 |
commit | cfa60bc6dc68699efb74342ead37865c074bc66a (patch) | |
tree | 6cb784505789838ddc3c470d1260ad3f651e3bf0 /inc/permission.inc.php | |
parent | Merge branch 'master' into permission-manager (diff) | |
download | slx-admin-cfa60bc6dc68699efb74342ead37865c074bc66a.tar.gz slx-admin-cfa60bc6dc68699efb74342ead37865c074bc66a.tar.xz slx-admin-cfa60bc6dc68699efb74342ead37865c074bc66a.zip |
Permissions: Introduce helper functions for common tasks
assertPermission ensures the user has a given permission and
halts execution otherwise.
addGlobalTags is a helper to fill an array for the rendering
process with tags associated with (missing) permissions.
Diffstat (limited to 'inc/permission.inc.php')
-rw-r--r-- | inc/permission.inc.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/inc/permission.inc.php b/inc/permission.inc.php index d04e3c3b..defa9f4d 100644 --- a/inc/permission.inc.php +++ b/inc/permission.inc.php @@ -15,5 +15,25 @@ class Permission return self::$permissions[$permission]; } + + public static function addGlobalTags(&$array, $locationid, $disabled) + { + if (!Module::isAvailable('permissionmanager')) + return; + foreach ($disabled as $perm) { + if (User::hasPermission($perm, $locationid)) + continue; + if (strpos($perm, '.') === false) { + $array[$perm]['disabled'] = 'disabled'; + continue; + } + $temp =& $array; + foreach (explode('.', $perm) as $sub) { + $temp =& $temp[$sub]; + } + $temp['disabled'] = 'disabled'; + } + } + } |