Skip to content

Commit

Permalink
Better permissions definitions
Browse files Browse the repository at this point in the history
Make this like IMP - it keeps the permission definitions together with
the interpretation of the permissions
  • Loading branch information
slusarz committed Sep 17, 2014
1 parent a5cfa8c commit 09947a2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions ingo/lib/Perms.php
Expand Up @@ -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'
)
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 09947a2

Please sign in to comment.