Use Horde_Perms::hasAppPermission()
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Nov 2009 05:57:44 +0000 (22:57 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Nov 2009 05:57:44 +0000 (22:57 -0700)
24 files changed:
imp/folders.php
imp/lib/Application.php
imp/lib/Compose.php
imp/lib/Folder.php
imp/lib/IMP.php
ingo/filters.php
ingo/lib/Application.php
ingo/lib/Ingo.php
ingo/rule.php
kronolith/add.php
kronolith/data.php
kronolith/edit.php
kronolith/lib/Application.php
kronolith/lib/Kronolith.php
kronolith/lib/View/Day.php
kronolith/lib/View/EditEvent.php
kronolith/lib/View/Month.php
kronolith/new.php
kronolith/templates/edit/edit.inc
kronolith/templates/week/head.inc
nag/data.php
nag/lib/Application.php
nag/lib/Nag.php
nag/task.php

index 756379f..a43f352 100644 (file)
@@ -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");
index e53a2da..39142f6 100644 (file)
@@ -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. */
 
     /**
index 7f807f2..887bdb7 100644 (file)
@@ -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) {
index df9fdeb..ece5b71 100644 (file)
@@ -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;
index 72bd57c..4eb20b8 100644 (file)
@@ -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 .= "<option value=\"\" disabled=\"disabled\">- - - - - - - -</option>\n" .
                 '<option value="*new*">' . _("New Folder") . "</option>\n" .
                 "<option value=\"\" disabled=\"disabled\">- - - - - - - -</option>\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.
index 6505d76..cfe7d1c 100644 (file)
@@ -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) {
index b258e96..0941687 100644 (file)
@@ -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.
index a91f4fa..cc8c6cd 100644 (file)
@@ -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;
     }
 
     /**
index 0602a42..28d30c6 100644 (file)
@@ -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));
index 8119db4..771cb5c 100644 (file)
@@ -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();
index 5f63569..e551890 100644 (file)
@@ -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;
index 6e3fabd..a341617 100644 (file)
@@ -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;
index a2e5e83..d9219b4 100644 (file)
@@ -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.
index 140cef9..89c30bc 100644 (file)
@@ -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')) {
index 08bf97d..b5d9a02 100644 (file)
@@ -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();
 
index 43ccc1b..00ceeb9 100644 (file)
@@ -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[] = '<input type="submit" class="button" name="saveAsNew" value="' . _("Save As New") . '" />';
         } 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[] = '<input type="submit" class="button" name="saveAsNew" value="' . _("Save As New") . '" />';
                 }
             }
index 21cb1ff..24a32a4 100644 (file)
@@ -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';
index 0465d1f..fd15353 100644 (file)
 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'),
index b8d749e..3cea00c 100644 (file)
@@ -27,8 +27,8 @@
 <table class="striped" cellspacing="0">
 <?php if ($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())): ?>
 <!-- recurrence editing -->
 <tr>
  <td></td>
index c6c583b..a5070e5 100644 (file)
@@ -20,8 +20,8 @@ echo Horde::link($this->link(1), _("Next week"), 'iconNav', '', 'return ShowView
 <?php
 if (Kronolith::getDefaultCalendar(Horde_Perms::EDIT) &&
     (!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())) {
     $addurl = Horde_Util::addParameter('new.php',
                                  array('date' => $day->dateString(),
                                        'url' => $this->link(0, true)));
index 50dd743..0670a82 100644 (file)
@@ -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;
index 2a202c3..db620e8 100644 (file)
@@ -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.
index 8bd594e..813c2ac 100644 (file)
@@ -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');
index 0482c41..aa097af 100644 (file)
@@ -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;
         }