From 09947a2dd9094fee7c60fd09d52743128e7ca7c3 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 17 Sep 2014 01:59:45 -0600 Subject: [PATCH] Better permissions definitions Make this like IMP - it keeps the permission definitions together with the interpretation of the permissions --- ingo/lib/Perms.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ingo/lib/Perms.php b/ingo/lib/Perms.php index 2e177a64e70..2b44c5df630 100644 --- a/ingo/lib/Perms.php +++ b/ingo/lib/Perms.php @@ -36,18 +36,30 @@ public function __construct() { $this->_perms = array( 'max_blacklist' => array( + 'handle' => function($allowed, $opts) { + return max(array_map('intval', $allowed)); + }, 'title' => _("Maximum number of blacklist addresses."), 'type' => 'int' ), 'max_forward' => array( + 'handle' => function($allowed, $opts) { + return max(array_map('intval', $allowed)); + }, 'title' => _("Maximum number of forward addresses."), 'type' => 'int' ), 'max_rules' => array( + 'handle' => function($allowed, $opts) { + return max(array_map('intval', $allowed)); + }, 'title' => _("Maximum number of rules (0 to disable rules editing)."), 'type' => 'int' ), 'max_whitelist' => array( + 'handle' => function($allowed, $opts) { + return max(array_map('intval', $allowed)); + }, 'title' => _("Maximum number of whitelist addresses."), 'type' => 'int' ) @@ -92,16 +104,9 @@ public function hasPermission($permission, $allowed, $opts) $permission = substr($permission, $pos + 1); } - switch ($permission) { - case 'max_blacklist': - case 'max_forward': - case 'max_rules': - case 'max_whitelist': - $allowed = max(array_map('intval', $allowed)); - break; - } - - return $allowed; + return isset($this->_perms[$permission]['handle']) + ? (bool)call_user_func($this->_perms[$permission]['handle'], $allowed, $opts) + : (bool)$allowed; } /**