From: Michael M Slusarz Date: Tue, 24 Nov 2009 05:57:44 +0000 (-0700) Subject: Use Horde_Perms::hasAppPermission() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d70298977eb293a552c879d0ebb29bb9a3048a7d;p=horde.git Use Horde_Perms::hasAppPermission() --- diff --git a/imp/folders.php b/imp/folders.php index 756379f62..a43f3523a 100644 --- a/imp/folders.php +++ b/imp/folders.php @@ -392,7 +392,7 @@ if ($a_template->get('javascript')) { $a_template->set('go', _("Go")); } -$a_template->set('create_folder', !empty($GLOBALS['conf']['hooks']['permsdenied']) || (IMP::hasPermission('create_folders') && IMP::hasPermission('max_folders'))); +$a_template->set('create_folder', !empty($GLOBALS['conf']['hooks']['permsdenied']) || ($GLOBALS['perms']->hasAppPermission('create_folders') && $GLOBALS['perms']->hasAppPermission('max_folders'))); if ($prefs->getValue('subscribe')) { $a_template->set('subscribe', true); $subToggleText = ($showAll) ? _("Hide Unsubscribed") : _("Show Unsubscribed"); diff --git a/imp/lib/Application.php b/imp/lib/Application.php index e53a2dae1..39142f6c0 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -200,6 +200,38 @@ class IMP_Application extends Horde_Registry_Application ); } + /** + * Returns the specified permission for the current user. + * + * @param mixed $allowed The allowed permissions. + * @param array $opts Additinal options ('value'). + * + * @return mixed The value of the specified permission. + */ + public function hasPermission($allowed, $opts = array()) + { + if (is_array($allowed)) { + switch ($permission) { + case 'create_folders': + $allowed = (bool)count(array_filter($allowed)); + break; + + case 'max_folders': + case 'max_recipients': + case 'max_timelimit': + $allowed = max($allowed); + break; + } + } + + if (($permission == 'max_folders') && empty($opts['value'])) { + $folder = IMP_Folder::singleton(); + $allowed = $allowed > count($folder->flist_IMP(array(), false)); + } + + return $allowed; + } + /* Horde_Auth_Application methods. */ /** diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 7f807f2be..887bdb77e 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -733,7 +733,7 @@ class IMP_Compose return; } - $timelimit = IMP::hasPermission('max_timelimit'); + $timelimit = $GLOBALS['perms']->hasAppPermission('max_timelimit'); if ($timelimit !== true) { if ($conf['sentmail']['driver'] == 'none') { Horde::logMessage('The permission for the maximum number of recipients per time period has been enabled, but no backend for the sent-mail logging has been configured for IMP.', __FILE__, __LINE__, PEAR_LOG_ERR); @@ -941,7 +941,7 @@ class IMP_Compose /* Count recipients if necessary. We need to split email groups * because the group members count as separate recipients. */ if ($exceed) { - $max_recipients = IMP::hasPermission('max_recipients'); + $max_recipients = $GLOBALS['perms']->hasAppPermission('max_recipients'); if ($max_recipients !== true) { $num_recipients = 0; foreach ($addrlist as $recipient) { diff --git a/imp/lib/Folder.php b/imp/lib/Folder.php index df9fdeba7..ece5b71b0 100644 --- a/imp/lib/Folder.php +++ b/imp/lib/Folder.php @@ -245,7 +245,7 @@ class IMP_Folder global $conf, $notification; /* Check permissions. */ - if (!IMP::hasPermission('create_folders')) { + if (!$GLOBALS['perms']->hasAppPermission('create_folders')) { try { $message = Horde::callHook('perms_denied', array('imp:create_folders')); } catch (Horde_Exception_HookNotSet $e) { @@ -253,11 +253,11 @@ class IMP_Folder } $notification->push($message, 'horde.error', array('content.raw')); return false; - } elseif (!IMP::hasPermission('max_folders')) { + } elseif (!$GLOBALS['perms']->hasAppPermission('max_folders')) { try { $message = Horde::callHook('perms_denied', array('imp:max_folders')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), IMP::hasPermission('max_folders', true)), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), $GLOBALS['perms']->hasAppPermission('max_folders', array('opts' => array('value' => true)))), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.error', array('content.raw')); return false; diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 72bd57c8d..4eb20b869 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -214,8 +214,8 @@ class IMP if (!empty($options['new_folder']) && (!empty($GLOBALS['conf']['hooks']['permsdenied']) || - (self::hasPermission('create_folders') && - self::hasPermission('max_folders')))) { + ($GLOBALS['perms']->hasAppPermission('create_folders') && + $GLOBALS['perms']->hasAppPermission('max_folders')))) { $text .= "\n" . '\n" . "\n"; @@ -500,44 +500,6 @@ class IMP } /** - * Returns the specified permission for the current user. - * - * @param string $permission A permission. - * @param boolean $value If true, the method returns the value of a - * scalar permission, otherwise whether the - * permission limit has been hit already. - * - * @return mixed The value of the specified permission. - */ - static public function hasPermission($permission, $value = false) - { - if (!$GLOBALS['perms']->exists('imp:' . $permission)) { - return true; - } - - $allowed = $GLOBALS['perms']->getPermissions('imp:' . $permission); - if (is_array($allowed)) { - switch ($permission) { - case 'create_folders': - $allowed = (bool)count(array_filter($allowed)); - break; - - case 'max_folders': - case 'max_recipients': - case 'max_timelimit': - $allowed = max($allowed); - break; - } - } - if (($permission == 'max_folders') && !$value) { - $folder = IMP_Folder::singleton(); - $allowed = $allowed > count($folder->flist_IMP(array(), false)); - } - - return $allowed; - } - - /** * Build IMP's list of menu items. * * @return Horde_Menu A Horde_Menu object. diff --git a/ingo/filters.php b/ingo/filters.php index 6505d76a2..cfe7d1c8e 100644 --- a/ingo/filters.php +++ b/ingo/filters.php @@ -29,8 +29,8 @@ $actionID = Horde_Util::getFormData('actionID'); $id = Horde_Util::getFormData('rulenumber'); /* Get permissions. */ -$edit_allowed = Ingo::hasPermission('shares', Horde_Perms::EDIT); -$delete_allowed = Ingo::hasPermission('shares', Horde_Perms::DELETE); +$edit_allowed = Ingo::hasSharePermission(Horde_Perms::EDIT); +$delete_allowed = Ingo::hasSharePermission(Horde_Perms::DELETE); /* Perform requested actions. */ switch ($actionID) { @@ -60,7 +60,7 @@ case 'rule_enable': break; case 'rule_copy': - if (!Ingo::hasPermission('allow_rules')) { + if (!$GLOBALS['perms']->hasAppPermission('allow_rules')) { try { $message = Horde::callHook('perms_denied', array('ingo:allow_rules')); } catch (Horde_Exception_HookNotSet $e) { @@ -68,12 +68,12 @@ case 'rule_enable': } $notification->push($message, 'horde.error', array('content.raw')); break 2; - } elseif (Ingo::hasPermission('max_rules') !== true && - Ingo::hasPermission('max_rules') <= count($filters->getFilterList())) { + } elseif ($GLOBALS['perms']->hasAppPermission('max_rules') !== true && + $GLOBALS['perms']->hasAppPermission('max_rules') <= count($filters->getFilterList())) { try { $message = Horde::callHook('perms_denied', array('ingo:max_rules')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d rules."), Ingo::hasPermission('max_rules')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d rules."), $GLOBALS['perms']->hasAppPermission('max_rules')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.error', array('content.raw')); break 2; @@ -264,8 +264,8 @@ if (count($filter_list) == 0) { /* Create copy link. */ if (!is_null($copyurl) && (!empty($conf['hooks']['permsdenied']) || - Ingo::hasPermission('max_rules') === true || - Ingo::hasPermission('max_rules') > count($filter_list))) { + $GLOBALS['perms']->hasAppPermission('max_rules') === true || + $GLOBALS['perms']->hasAppPermission('max_rules') > count($filter_list))) { $entry['copylink'] = Horde::link($copyurl, sprintf(_("Copy %s"), $name)); $entry['copyimg'] = Horde::img('copy.png', sprintf(_("Copy %s"), $name)); } else { @@ -317,9 +317,9 @@ if (count($filter_list) == 0) { $actions = $ingo_script->availableActions(); $createrule = (!empty($actions) && (!empty($conf['hooks']['permsdenied']) || - (Ingo::hasPermission('allow_rules') && - (Ingo::hasPermission('max_rules') === true || - Ingo::hasPermission('max_rules') > count($filter_list))))); + ($GLOBALS['perms']->hasAppPermission('allow_rules') && + ($GLOBALS['perms']->hasAppPermission('max_rules') === true || + $GLOBALS['perms']->hasAppPermission('max_rules') > count($filter_list))))); $canapply = $ingo_script->canApply(); require INGO_TEMPLATES . '/filters/footer.inc'; if ($on_demand && $edit_allowed) { diff --git a/ingo/lib/Application.php b/ingo/lib/Application.php index b258e9658..094168781 100644 --- a/ingo/lib/Application.php +++ b/ingo/lib/Application.php @@ -40,6 +40,30 @@ class Ingo_Application extends Horde_Registry_Application } /** + * Returns the specified permission for the current user. + * + * @param mixed $allowed The allowed permissions. + * + * @return mixed The value of the specified permission. + */ + public function hasPermission($allowed) + { + if (is_array($allowed)) { + switch ($permission) { + case 'allow_rules': + $allowed = (bool)count(array_filter($allowed)); + break; + + case 'max_rules': + $allowed = max($allowed); + break; + } + } + + return $allowed; + } + + /** * Generate the menu to use on the prefs page. * * @return Horde_Menu A Horde_Menu object. diff --git a/ingo/lib/Ingo.php b/ingo/lib/Ingo.php index a91f4fae3..cc8c6cdf0 100644 --- a/ingo/lib/Ingo.php +++ b/ingo/lib/Ingo.php @@ -25,6 +25,9 @@ class Ingo /* getMenu() cache. */ static private $_menuCache = null; + /* hasSharePermission() cache. */ + static private $_shareCache = null; + /** * Generates a folder widget. * If an application is available that provides a folderlist method @@ -326,46 +329,19 @@ class Ingo } /** - * Returns the specified permission for the current user. - * - * @param string $permission A permission, either 'allow_rules' or - * 'max_rules'. - * - * @return mixed The value of the specified permission. + * TODO */ - static public function hasPermission($permission, $mask = null) + static public function hasSharePermission($mask = null) { - if ($permission == 'shares') { - if (!isset($GLOBALS['ingo_shares'])) { - return true; - } - static $all_perms; - if (!isset($all_perms)) { - $all_perms = $GLOBALS['ingo_shares']->getPermissions($_SESSION['ingo']['current_share'], Horde_Auth::getAuth()); - } - return $all_perms & $mask; - } - - global $perms; - - if (!$perms->exists('ingo:' . $permission)) { + if (!isset($GLOBALS['ingo_shares'])) { return true; } - $allowed = $perms->getPermissions('ingo:' . $permission); - if (is_array($allowed)) { - switch ($permission) { - case 'allow_rules': - $allowed = (bool)count(array_filter($allowed)); - break; - - case 'max_rules': - $allowed = max($allowed); - break; - } + if (is_null(self::$_shareCache)) { + self::$_shareCache = $GLOBALS['ingo_shares']->getPermissions($_SESSION['ingo']['current_share'], Horde_Auth::getAuth()); } - return $allowed; + return self::$_shareCache & $mask; } /** diff --git a/ingo/rule.php b/ingo/rule.php index 0602a42fe..28d30c631 100644 --- a/ingo/rule.php +++ b/ingo/rule.php @@ -14,7 +14,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; /* Check rule permissions. */ -if (!Ingo::hasPermission('allow_rules')) { +if (!$GLOBALS['perms']->hasAppPermission('allow_rules')) { try { $message = Horde::callHook('perms_denied', array('ingo:allow_rules')); } catch (Horde_Exception_HookNotSet $e) { @@ -50,7 +50,7 @@ case 'create_folder': case 'rule_save': case 'rule_update': case 'rule_delete': - if (!Ingo::hasPermission('shares', Horde_Perms::EDIT)) { + if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); header('Location: ' . Horde::applicationUrl('filters.php', true)); exit; @@ -126,8 +126,8 @@ case 'rule_delete': /* Save the rule. */ if ($actionID == 'rule_save' && $valid) { if (is_null($edit_number)) { - if (Ingo::hasPermission('max_rules') !== true && - Ingo::hasPermission('max_rules') <= count($filters->getFilterList())) { + if ($GLOBALS['perms']->hasAppPermission('max_rules') !== true && + $GLOBALS['perms']->hasAppPermission('max_rules') <= count($filters->getFilterList())) { header('Location: ' . Horde::applicationUrl('filters.php', true)); exit; } @@ -145,7 +145,7 @@ case 'rule_delete': header('Location: ' . Horde::applicationUrl('filters.php')); exit; } elseif ($actionID == 'rule_delete') { - if (!Ingo::hasPermission('shares', Horde_Perms::DELETE)) { + if (!Ingo::hasSharePermission(Horde_Perms::DELETE)) { $notification->push(_("You do not have permission to delete filter rules."), 'horde.error'); header('Location: ' . Horde::applicationUrl('filters.php', true)); exit; @@ -159,18 +159,18 @@ case 'rule_delete': break; default: - if (!Ingo::hasPermission('shares', Horde_Perms::EDIT)) { + if (!Ingo::hasSharePermission(Horde_Perms::EDIT)) { $notification->push(_("You do not have permission to edit filter rules."), 'horde.error'); header('Location: ' . Horde::applicationUrl('filters.php', true)); exit; } if (is_null($edit_number)) { - if (Ingo::hasPermission('max_rules') !== true && - Ingo::hasPermission('max_rules') <= count($filters->getFilterList())) { + if ($GLOBALS['perms']->hasAppPermission('max_rules') !== true && + $GLOBALS['perms']->hasAppPermission('max_rules') <= count($filters->getFilterList())) { try { $message = Horde::callHook('perms_denied', array('ingo:max_rules')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d rules."), Ingo::hasPermission('max_rules')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d rules."), $GLOBALS['perms']->hasAppPermission('max_rules')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.error', array('content.raw')); header('Location: ' . Horde::applicationUrl('filters.php', true)); diff --git a/kronolith/add.php b/kronolith/add.php index 8119db4e9..771cb5c63 100644 --- a/kronolith/add.php +++ b/kronolith/add.php @@ -25,8 +25,8 @@ if (!Horde_Util::getFormData('cancel')) { } elseif ($user == Horde_Auth::getAuth() && !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT, Horde_Auth::getAuth())) { $notification->push(sprintf(_("You do not have permission to add events to %s."), $share->get('name')), 'horde.warning'); - } elseif (Kronolith::hasPermission('max_events') === true || - Kronolith::hasPermission('max_events') > Kronolith::countEvents()) { + } elseif ($GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents()) { $event = Kronolith::getDriver(null, $calendar_id)->getEvent(); $event->readForm(); $result = $event->save(); diff --git a/kronolith/data.php b/kronolith/data.php index 5f635698b..e5518905e 100644 --- a/kronolith/data.php +++ b/kronolith/data.php @@ -33,12 +33,12 @@ $templates = array( Horde_Data::IMPORT_MAPPED => array($registry->get('templates', 'horde') . '/data/csvmap.inc'), Horde_Data::IMPORT_DATETIME => array($registry->get('templates', 'horde') . '/data/datemap.inc') ); -if (Kronolith::hasPermission('max_events') !== true && - Kronolith::hasPermission('max_events') <= Kronolith::countEvents()) { +if ($GLOBALS['perms']->hasAppPermission('max_events') !== true && + $GLOBALS['perms']->hasAppPermission('max_events') <= Kronolith::countEvents()) { try { $message = Horde::callHook('perms_denied', array('kronolith:max_events')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), Kronolith::hasPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $GLOBALS['perms']->hasAppPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.warning', array('content.raw')); $templates[Horde_Data::IMPORT_FILE] = array(KRONOLITH_TEMPLATES . '/data/export.inc'); @@ -217,7 +217,7 @@ if (!$error) { if (is_array($next_step)) { $events = array(); $error = false; - $max_events = Kronolith::hasPermission('max_events'); + $max_events = $GLOBALS['perms']->hasAppPermission('max_events'); if ($max_events !== true) { $num_events = Kronolith::countEvents(); } @@ -244,7 +244,7 @@ if (is_array($next_step)) { try { $message = Horde::callHook('perms_denied', array('kronolith:max_events')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), Kronolith::hasPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $GLOBALS['perms']->hasAppPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.error', array('content.raw')); break; diff --git a/kronolith/edit.php b/kronolith/edit.php index 6e3fabde3..a341617d4 100644 --- a/kronolith/edit.php +++ b/kronolith/edit.php @@ -24,12 +24,12 @@ function _save(&$event) function _check_max() { - if (Kronolith::hasPermission('max_events') !== true && - Kronolith::hasPermission('max_events') <= Kronolith::countEvents()) { + if ($GLOBALS['perms']->hasAppPermission('max_events') !== true && + $GLOBALS['perms']->hasAppPermission('max_events') <= Kronolith::countEvents()) { try { $message = Horde::callHook('perms_denied', array('kronolith:max_events')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), Kronolith::hasPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $GLOBALS['perms']->hasAppPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); } $GLOBALS['notification']->push($message, 'horde.error', array('content.raw')); return false; diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index a2e5e8328..d9219b457 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -24,6 +24,26 @@ class Kronolith_Application extends Horde_Registry_Application } /** + * Returns the specified permission for the current user. + * + * @param mixed $allowed The allowed permissions. + * + * @return mixed The value of the specified permission. + */ + public function hasPermission($allowed) + { + if (is_array($allowed)) { + switch ($permission) { + case 'max_events': + $allowed = max($allowed); + break; + } + } + + return $allowed; + } + + /** * Code to run when viewing prefs for this application. * * @param string $group The prefGroup name. diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 140cef939..89c30bcf6 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1733,33 +1733,6 @@ class Kronolith } /** - * Returns the specified permission for the current user. - * - * @param string $permission A permission, currently only 'max_events'. - * - * @return mixed The value of the specified permission. - */ - public static function hasPermission($permission) - { - global $perms; - - if (!$perms->exists('kronolith:' . $permission)) { - return true; - } - - $allowed = $perms->getPermissions('kronolith:' . $permission); - if (is_array($allowed)) { - switch ($permission) { - case 'max_events': - $allowed = max($allowed); - break; - } - } - - return $allowed; - } - - /** * @param string $tabname */ public static function tabs($tabname = null) @@ -2096,8 +2069,8 @@ class Kronolith $menu->add(Horde::applicationUrl($prefs->getValue('defaultview') . '.php'), _("_Today"), 'today.png', null, null, null, '__noselection'); if (self::getDefaultCalendar(Horde_Perms::EDIT) && (!empty($conf['hooks']['permsdenied']) || - self::hasPermission('max_events') === true || - self::hasPermission('max_events') > self::countEvents())) { + $GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > self::countEvents())) { $menu->add(Horde_Util::addParameter(Horde::applicationUrl('new.php'), 'url', Horde::selfUrl(true, false, true)), _("_New Event"), 'new.png'); } if ($browser->hasFeature('dom')) { diff --git a/kronolith/lib/View/Day.php b/kronolith/lib/View/Day.php index 08bf97db6..b5d9a020f 100644 --- a/kronolith/lib/View/Day.php +++ b/kronolith/lib/View/Day.php @@ -78,8 +78,8 @@ class Kronolith_View_Day extends Kronolith_Day { $first_row = true; $addLinks = Kronolith::getDefaultCalendar(Horde_Perms::EDIT) && (!empty($GLOBALS['conf']['hooks']['permsdenied']) || - Kronolith::hasPermission('max_events') === true || - Kronolith::hasPermission('max_events') > Kronolith::countEvents()); + $GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents()); $showLocation = Kronolith::viewShowLocation(); $showTime = Kronolith::viewShowTime(); diff --git a/kronolith/lib/View/EditEvent.php b/kronolith/lib/View/EditEvent.php index 43ccc1b25..00ceeb910 100644 --- a/kronolith/lib/View/EditEvent.php +++ b/kronolith/lib/View/EditEvent.php @@ -71,8 +71,8 @@ class Kronolith_View_EditEvent { if (($this->event->isRemote() || !$this->event->hasPermission(Horde_Perms::EDIT)) && (!empty($GLOBALS['conf']['hooks']['permsdenied']) || - Kronolith::hasPermission('max_events') === true || - Kronolith::hasPermission('max_events') > Kronolith::countEvents())) { + $GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents())) { $buttons[] = ''; } else { if (!$this->event->isRemote()) { @@ -81,8 +81,8 @@ class Kronolith_View_EditEvent { if ($this->event->isInitialized()) { if (!$this->event->recurs() && (!empty($conf['hooks']['permsdenied']) || - Kronolith::hasPermission('max_events') === true || - Kronolith::hasPermission('max_events') > Kronolith::countEvents())) { + $GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents())) { $buttons[] = ''; } } diff --git a/kronolith/lib/View/Month.php b/kronolith/lib/View/Month.php index 21cb1ff2c..24a32a4bf 100644 --- a/kronolith/lib/View/Month.php +++ b/kronolith/lib/View/Month.php @@ -119,8 +119,8 @@ class Kronolith_View_Month { $twentyFour = $prefs->getValue('twentyFour'); $addLinks = Kronolith::getDefaultCalendar(Horde_Perms::EDIT) && (!empty($GLOBALS['conf']['hooks']['permsdenied']) || - Kronolith::hasPermission('max_events') === true || - Kronolith::hasPermission('max_events') > Kronolith::countEvents()); + $GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents()); if ($sidebyside) { require KRONOLITH_TEMPLATES . '/month/head_side_by_side.inc'; diff --git a/kronolith/new.php b/kronolith/new.php index 0465d1f89..fd1535330 100644 --- a/kronolith/new.php +++ b/kronolith/new.php @@ -11,12 +11,12 @@ require dirname(__FILE__) . '/lib/base.php'; /* Check permissions. */ -if (Kronolith::hasPermission('max_events') !== true && - Kronolith::hasPermission('max_events') <= Kronolith::countEvents()) { +if ($GLOBALS['perms']->hasAppPermission('max_events') !== true && + $GLOBALS['perms']->hasAppPermission('max_events') <= Kronolith::countEvents()) { try { $message = Horde::callHook('perms_denied', array('kronolith:max_events')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), Kronolith::hasPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d events."), $GLOBALS['perms']->hasAppPermission('max_events')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.error', array('content.raw')); $url = Horde_Util::addParameter($prefs->getValue('defaultview') . '.php', array('month' => Horde_Util::getFormData('month'), diff --git a/kronolith/templates/edit/edit.inc b/kronolith/templates/edit/edit.inc index b8d749e2d..3cea00ca4 100644 --- a/kronolith/templates/edit/edit.inc +++ b/kronolith/templates/edit/edit.inc @@ -27,8 +27,8 @@ recurs() && (!empty($conf['hooks']['permsdenied']) || - Kronolith::hasPermission('max_events') === true || - Kronolith::hasPermission('max_events') > Kronolith::countEvents())): ?> + $GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents())): ?> diff --git a/kronolith/templates/week/head.inc b/kronolith/templates/week/head.inc index c6c583b2e..a5070e593 100644 --- a/kronolith/templates/week/head.inc +++ b/kronolith/templates/week/head.inc @@ -20,8 +20,8 @@ echo Horde::link($this->link(1), _("Next week"), 'iconNav', '', 'return ShowView Kronolith::countEvents())) { + $GLOBALS['perms']->hasAppPermission('max_events') === true || + $GLOBALS['perms']->hasAppPermission('max_events') > Kronolith::countEvents())) { $addurl = Horde_Util::addParameter('new.php', array('date' => $day->dateString(), 'url' => $this->link(0, true))); diff --git a/nag/data.php b/nag/data.php index 50dd74367..0670a8255 100644 --- a/nag/data.php +++ b/nag/data.php @@ -34,12 +34,12 @@ $templates = array( Horde_Data::IMPORT_MAPPED => array($registry->get('templates', 'horde') . '/data/csvmap.inc'), Horde_Data::IMPORT_DATETIME => array($registry->get('templates', 'horde') . '/data/datemap.inc') ); -if (Nag::hasPermission('max_tasks') !== true && - Nag::hasPermission('max_tasks') <= Nag::countTasks()) { +if ($GLOBALS['perms']->hasAppPermission('max_tasks') !== true && + $GLOBALS['perms']->hasAppPermission('max_tasks') <= Nag::countTasks()) { try { $message = Horde::callHook('perms_denied', array('nag:max_tasks')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), Nag::hasPermission('max_tasks')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), $GLOBALS['perms']->hasAppPermission('max_tasks')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.warning', array('content.raw')); $templates[Horde_Data::IMPORT_FILE] = array(NAG_TEMPLATES . '/data/export.inc'); @@ -159,7 +159,7 @@ if (is_array($next_step)) { /* Create a Nag storage instance. */ $storage = Nag_Driver::singleton($_SESSION['import_data']['target']); - $max_tasks = Nag::hasPermission('max_tasks'); + $max_tasks = $GLOBALS['perms']->hasAppPermission('max_tasks'); $num_tasks = Nag::countTasks(); $result = null; foreach ($next_step as $row) { @@ -167,7 +167,7 @@ if (is_array($next_step)) { try { $message = Horde::callHook('perms_denied', array('nag:max_tasks')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), Nag::hasPermission('max_tasks')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), $GLOBALS['perms']->hasAppPermission('max_tasks')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.error', array('content.raw')); break; diff --git a/nag/lib/Application.php b/nag/lib/Application.php index 2a202c328..db620e8fb 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -29,6 +29,26 @@ class Nag_Application extends Horde_Registry_Application } /** + * Returns the specified permission for the current user. + * + * @param mixed $allowed The allowed permissions. + * + * @return mixed The value of the specified permission. + */ + public function hasPermission($allowed) + { + if (is_array($allowed)) { + switch ($permission) { + case 'max_tasks': + $allowed = max($allowed); + break; + } + } + + return $allowed; + } + + /** * Special preferences handling on update. * * @param string $item The preference name. diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index 8bd594e9d..813c2ac2c 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -578,33 +578,6 @@ class Nag } /** - * Returns the specified permission for the current user. - * - * @param string $permission A permission, currently only 'max_tasks'. - * - * @return mixed The value of the specified permission. - */ - function hasPermission($permission) - { - global $perms; - - if (!$perms->exists('nag:' . $permission)) { - return true; - } - - $allowed = $perms->getPermissions('nag:' . $permission); - if (is_array($allowed)) { - switch ($permission) { - case 'max_tasks': - $allowed = max($allowed); - break; - } - } - - return $allowed; - } - - /** * Initial app setup code. */ function initialize() @@ -689,8 +662,8 @@ class Nag $menu->add(Horde::applicationUrl('list.php'), _("_List Tasks"), 'nag.png', null, null, null, basename($_SERVER['PHP_SELF']) == 'index.php' ? 'current' : null); if (Nag::getDefaultTasklist(Horde_Perms::EDIT) && (!empty($conf['hooks']['permsdenied']) || - Nag::hasPermission('max_tasks') === true || - Nag::hasPermission('max_tasks') > Nag::countTasks())) { + $GLOBALS['perms']->hasAppPermission('max_tasks') === true || + $GLOBALS['perms']->hasAppPermission('max_tasks') > Nag::countTasks())) { $menu->add(Horde::applicationUrl(Horde_Util::addParameter('task.php', 'actionID', 'add_task')), _("_New Task"), 'add.png', null, null, null, Horde_Util::getFormData('task') ? '__noselection' : null); if ($GLOBALS['browser']->hasFeature('dom')) { $menu->add('', _("_Quick Add"), 'add.png', null, null, 'Nag.quickAddPanel.show(); $(\'quickText\').focus(); return false;', Horde_Util::getFormData('task') ? 'quickAdd __noselection' : 'quickAdd'); diff --git a/nag/task.php b/nag/task.php index 0482c418f..aa097afdd 100644 --- a/nag/task.php +++ b/nag/task.php @@ -60,12 +60,12 @@ if (is_null($actionID)) { switch ($actionID) { case 'add_task': /* Check permissions. */ - if (Nag::hasPermission('max_tasks') !== true && - Nag::hasPermission('max_tasks') <= Nag::countTasks()) { + if ($GLOBALS['perms']->hasAppPermission('max_tasks') !== true && + $GLOBALS['perms']->hasAppPermission('max_tasks') <= Nag::countTasks()) { try { $message = Horde::callHook('perms_denied', array('nag:max_tasks')); } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), Nag::hasPermission('max_tasks')), ENT_COMPAT, Horde_Nls::getCharset()); + $message = @htmlspecialchars(sprintf(_("You are not allowed to create more than %d tasks."), $GLOBALS['perms']->hasAppPermission('max_tasks')), ENT_COMPAT, Horde_Nls::getCharset()); } $notification->push($message, 'horde.error', array('content.raw')); header('Location: ' . Horde::applicationUrl('list.php', true)); @@ -156,8 +156,8 @@ case 'save_task': $info['tasklist_id']); } else { /* Check permissions. */ - if (Nag::hasPermission('max_tasks') !== true && - Nag::hasPermission('max_tasks') <= Nag::countTasks()) { + if ($GLOBALS['perms']->hasAppPermission('max_tasks') !== true && + $GLOBALS['perms']->hasAppPermission('max_tasks') <= Nag::countTasks()) { header('Location: ' . Horde::applicationUrl('list.php', true)); exit; }