From cfa60bc6dc68699efb74342ead37865c074bc66a Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 9 Feb 2018 16:13:17 +0100 Subject: 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. --- inc/permission.inc.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'inc/permission.inc.php') 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'; + } + } + } -- cgit v1.2.3-55-g7522