public static hasPermission ( string $permission ) : mixed | ||
$permission | string | A permission, currently only 'max_notes'. |
Résultat | mixed | The value of the specified permission. |
public static function hasPermission($permission)
{
$perms = $GLOBALS['injector']->getInstance('Horde_Perms');
if (!$perms->exists('mnemo:' . $permission)) {
return true;
}
$allowed = $perms->getPermissions('mnemo:' . $permission, $GLOBALS['registry']->getAuth());
if (is_array($allowed)) {
switch ($permission) {
case 'max_notes':
$allowed = max($allowed);
break;
}
}
return $allowed;
}
/** * Returns an array of UIDs for all notes that the current user is authorized * to see. * * @param array|string $notepads The notepad(s) to list notes from. * * @return array An array of UIDs for all notes the user can access. * @throws Mnemo_Exception * @throws Horde_Exception_PermissionDenied */ public function listUids($notepads = null) { global $conf; if (!isset($conf['storage']['driver'])) { throw new RuntimeException('Not configured'); } // Make sure we have a valid notepad. if (empty($notepads)) { $notepads = Mnemo::getSyncNotepads(); } else { if (!is_array($notepads)) { $notepads = array($notepads); } foreach ($notepads as $notepad) { if (!Mnemo::hasPermission($notepad, Horde_Perms::READ)) { throw new Horde_Exception_PermissionDenied(); } } } // Set notepad for listMemos. $GLOBALS['display_notepads'] = $notepads; $memos = Mnemo::listMemos(); $uids = array(); foreach ($memos as $memo) { $uids[] = $memo['uid']; } return $uids; }