From: Michael M Slusarz Date: Thu, 4 Nov 2010 07:24:55 +0000 (-0600) Subject: Add Horde::permissionDeniedError() to provide consistent permission error handling... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=ff03750ea173b3c7edb46328c15bc8838925c1ba;p=horde.git Add Horde::permissionDeniedError() to provide consistent permission error handling across applications --- diff --git a/agora/lib/Api.php b/agora/lib/Api.php index a58f41a11..c64d4d2d9 100644 --- a/agora/lib/Api.php +++ b/agora/lib/Api.php @@ -453,11 +453,8 @@ class Agora_Api extends Horde_Registry_Api /* Check post permissions. */ if (!$messages->hasPermission(Horde_Perms::EDIT)) { - try { - return Horde::callHook('perms_denied', array('agora')); - } catch (Horde_Exception_HookNotSet $e) { - return sprintf(_("You don't have permission to post messages in forum %s."), $params['forum_id']); - } + Horde::permissionDeniedError('agora', null); + return PEAR::raiseError(sprintf(_("You don't have permission to post messages in forum %s."), $params['forum_id'])); } if (isset($params['message_id'])) { diff --git a/agora/messages/index.php b/agora/messages/index.php index 276df486c..cf9e56ae9 100644 --- a/agora/messages/index.php +++ b/agora/messages/index.php @@ -192,12 +192,8 @@ $view->rss = Horde_Util::addParameter(Horde::url('rss/messages.php', true, -1), /* Display an edit-dialogue if the thread is not locked and we can edit messages in them. */ if (!$messages->hasPermission(Horde_Perms::EDIT)) { - try { - $message = Horde::callHook('perms_denied', array('agora'), 'horde'); - } catch (Horde_Exception_HookNotset $e) { - $message = sprintf(_("You don't have permission to post messages in forum %s."), $forum['forum_name']); - } - $view->form = $message; + Horde::permissionDeniedError('agora', null); + $view->form = sprintf(_("You don't have permission to post messages in forum %s."), $forum['forum_name']); } elseif ($message['locked']) { $view->form = _("Thread locked."); } else { diff --git a/folks/templates/user/user.php b/folks/templates/user/user.php index a98da6fe9..0b0b174b8 100644 --- a/folks/templates/user/user.php +++ b/folks/templates/user/user.php @@ -380,11 +380,8 @@ case 'authenticated': $comments_reason = sprintf(_("You are on %s blacklist."), $user); } } else { - try { - $comments_reason = Horde::callHook('perms_denied', array('folks')); - } catch (Horde_Exception_HookNotSet $e) { - $comments_reason = _("Only authenticated users can post comments."); - } + Horde::permissionDeniedError('folks', null); + $comments_reason = _("Only authenticated users can post comments."); } break; diff --git a/framework/Block/lib/Horde/Block/Layout/Manager.php b/framework/Block/lib/Horde/Block/Layout/Manager.php index 8460f261f..bf422816c 100644 --- a/framework/Block/lib/Horde/Block/Layout/Manager.php +++ b/framework/Block/lib/Horde/Block/Layout/Manager.php @@ -238,12 +238,11 @@ class Horde_Block_Layout_Manager extends Horde_Block_Layout $max_blocks = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_blocks'); if (($max_blocks !== true) && ($max_blocks <= $this->count())) { - try { - $message = Horde::callHook('perms_denied', array('horde:max_blocks')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(Horde_Block_Translation::ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", $max_blocks), $max_blocks)); - } - $GLOBALS['notification']->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'horde', + 'max_blocks', + sprintf(Horde_Block_Translation::ngettext("You are not allowed to create more than %d block.", "You are not allowed to create more than %d blocks.", $max_blocks), $max_blocks) + ); break; } diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index f2bf7f883..fea39c6a7 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -2110,4 +2110,24 @@ HTML; return self::endBuffer(); } + /** + * Process a permission denied error, running a user-defined hook if + * necessary. + * + * @param string $app Application name. + * @param string $perm Permission name. + * @param string $error An error message to output via the notification + * system. + */ + static public function permissionDeniedError($app, $perm, $error = null) + { + try { + self::callHook('perms_denied', array($app, $perm)); + } catch (Horde_Exception_HookNotSet $e) {} + + if (!is_null($error)) { + $GLOBALS['notification']->push($error, 'horde.warning'); + } + } + } diff --git a/horde/config/hooks.php.dist b/horde/config/hooks.php.dist index fb6300682..e56b63b0e 100644 --- a/horde/config/hooks.php.dist +++ b/horde/config/hooks.php.dist @@ -619,23 +619,18 @@ class Horde_Hooks /** * Hook called if a user tries to make an action that is under permission * control that they don't have sufficient permissions for. It can be - * used to show the user a custom message including HTML code (you have to - * take care about HTML escaping on your own), or to interrupt the code - * flow and send the user to a different page. + * used to show the user a custom message including HTML code (via the + * notification system), or to interrupt the code flow and send the user + * to a different page. * + * @param string $app Horde application. * @param string $permission Permission that failed. - * - * @return string An error message. */ -// public function perms_denied($permission) +// public function perms_denied($app, $permission) // { -// // Example #1: Provide link to upgrade script. -// $app = (($pos = strpos($? $mission, ':')) === false) -// ? $permission -// : substr($permission, 0, $pos); -// -// // TODO: Notification -// return sprintf('Permission denied. Click HERE to upgrade %s.', $app, $GLOBALS['registry']->get('name')); +// // Example #1: Provide link to upgrade script in notification +// // message. +// $GLOBALS['notification']->push(sprintf('Permission denied. Click HERE to upgrade %s.', $app, $GLOBALS['registry']->get('name')), 'horde.error', array('content.raw')); // } @@ -645,7 +640,7 @@ class Horde_Hooks * function will be called to dynamically include users in the group. * * @param string $groupName TODO - * @param string $userName TODO + * @param string $userName TODO * * @return TODO */ diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index a9d790a00..e033d4648 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -782,12 +782,8 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator } if ($recipients > $timelimit) { - try { - $error = Horde::callHook('perms_denied', array('imp:max_timelimit')); - } catch (Horde_Exception_HookNotSet $e) { - $error = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $GLOBALS['conf']['sentmail']['params']['limit_period']), ENT_COMPAT, 'UTF-8'); - } - throw new IMP_Compose_Exception($error); + Horde::permissionDeniedError('imp', 'max_timelimit'); + throw new IMP_Compose_Exception(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $GLOBALS['conf']['sentmail']['params']['limit_period'])); } } @@ -967,12 +963,8 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator $num_recipients += count(explode(',', $recipient)); } if ($num_recipients > $max_recipients) { - try { - $message = Horde::callHook('perms_denied', array('imp:max_recipients')); - } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients."), $max_recipients), ENT_COMPAT, 'UTF-8'); - } - throw new IMP_Compose_Exception($message); + Horde::permissionDeniedError('imp', 'max_recipients'); + throw new IMP_Compose_Exception(sprintf(_("You are not allowed to send messages to more than %d recipients."), $max_recipients)); } } } diff --git a/imp/lib/Folder.php b/imp/lib/Folder.php index 10b947ebb..5d8c5de42 100644 --- a/imp/lib/Folder.php +++ b/imp/lib/Folder.php @@ -107,24 +107,23 @@ class IMP_Folder */ public function create($folder, $subscribe) { - global $conf, $notification; + global $conf, $injector, $notification; /* Check permissions. */ - if (!$GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('create_folders')) { - try { - $message = Horde::callHook('perms_denied', array('imp:create_folders')); - } catch (Horde_Exception_HookNotSet $e) { - $message = @htmlspecialchars(_("You are not allowed to create folders."), ENT_COMPAT, 'UTF-8'); - } - $notification->push($message, 'horde.error', array('content.raw')); + $perms = $injector->getInstance('Horde_Perms'); + if (!$perms->hasAppPermission('create_folders')) { + Horde::permissionDeniedError( + 'imp', + 'create_folders', + _("You are not allowed to create folders.") + ); return false; - } elseif (!$GLOBALS['injector']->getInstance('Horde_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."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_folders', array('opts' => array('value' => true)))), ENT_COMPAT, 'UTF-8'); - } - $notification->push($message, 'horde.error', array('content.raw')); + } elseif (!$perms->hasAppPermission('max_folders')) { + Horde::permissionDeniedError( + 'imp', + 'max_folders', + sprintf(_("You are not allowed to create more than %d folders."), $perms->hasAppPermission('max_folders', array('opts' => array('value' => true)))) + ); return false; } diff --git a/ingo/filters.php b/ingo/filters.php index 54a0e2806..2a8305c19 100644 --- a/ingo/filters.php +++ b/ingo/filters.php @@ -59,21 +59,19 @@ case 'rule_enable': case 'rule_copy': if (!$perms->hasAppPermission('allow_rules')) { - try { - $message = Horde::callHook('perms_denied', array('ingo:allow_rules')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(_("You are not allowed to create or edit custom rules.")); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'ingo', + 'allow_rules', + _("You are not allowed to create or edit custom rules.") + ); break 2; } elseif ($perms->hasAppPermission('max_rules') !== true && $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."), $perms->hasAppPermission('max_rules'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'ingo', + 'max_rules', + sprintf(_("You are not allowed to create more than %d rules."), $perms->hasAppPermission('max_rules')) + ); break 2; } else { $tmp = $filters->getFilter($vars->rulenumber); diff --git a/ingo/rule.php b/ingo/rule.php index 5c3d34b28..75d15095e 100644 --- a/ingo/rule.php +++ b/ingo/rule.php @@ -17,12 +17,11 @@ Horde_Registry::appInit('ingo'); /* Check rule permissions. */ $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if (!$perms->hasAppPermission('allow_rules')) { - try { - $message = Horde::callHook('perms_denied', array('ingo:allow_rules')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(_("You are not allowed to create or edit custom rules.")); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'ingo', + 'allow_rules', + _("You are not allowed to create or edit custom rules.") + ); Horde::url('filters.php', true)->redirect(); } @@ -166,12 +165,11 @@ default: if (!isset($vars->edit)) { if ($perms->hasAppPermission('max_rules') !== true && $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."), $perms->hasAppPermission('max_rules'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'ingo', + 'max_rules', + sprintf(_("You are not allowed to create more than %d rules."), $perms->hasAppPermission('max_rules')) + ); header('Location: ' . Horde::url('filters.php', true)); exit; } diff --git a/kronolith/add.php b/kronolith/add.php index 41907c630..33b68411e 100644 --- a/kronolith/add.php +++ b/kronolith/add.php @@ -51,12 +51,11 @@ do { $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->hasAppPermission('max_events') !== true && $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."), $perms->hasAppPermission('max_events'))); - } - $GLOBALS['notification']->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'kronolith', + 'max_events', + sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')) + ); break; } diff --git a/kronolith/data.php b/kronolith/data.php index 2bdb25e0a..d4e24b568 100644 --- a/kronolith/data.php +++ b/kronolith/data.php @@ -43,12 +43,11 @@ $templates = array( $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->hasAppPermission('max_events') !== true && $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."), $perms->hasAppPermission('max_events'))); - } - $notification->push($message, 'horde.warning', array('content.raw')); + Horde::permissionDeniedError( + 'kronolith', + 'max_events', + sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')) + ); $templates[Horde_Data::IMPORT_FILE] = array(KRONOLITH_TEMPLATES . '/data/export.inc'); } else { $templates[Horde_Data::IMPORT_FILE] = array(KRONOLITH_TEMPLATES . '/data/import.inc', KRONOLITH_TEMPLATES . '/data/export.inc'); @@ -260,12 +259,11 @@ if (is_array($next_step)) { $recurrences = array(); foreach ($next_step as $row) { if ($max_events !== true && $num_events >= $max_events) { - 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."), $perms->hasAppPermission('max_events'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'kronolith', + 'max_events', + sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')) + ); break; } try { diff --git a/kronolith/edit.php b/kronolith/edit.php index cf3f2f0fb..170efa697 100644 --- a/kronolith/edit.php +++ b/kronolith/edit.php @@ -28,12 +28,11 @@ function _check_max() $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->hasAppPermission('max_events') !== true && $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."), $perms->hasAppPermission('max_events'))); - } - $GLOBALS['notification']->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'kronolith', + 'max_events', + sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')) + ); return false; } return true; diff --git a/kronolith/lib/Ajax/Application.php b/kronolith/lib/Ajax/Application.php index 263aa84c5..84f1acae6 100644 --- a/kronolith/lib/Ajax/Application.php +++ b/kronolith/lib/Ajax/Application.php @@ -97,12 +97,11 @@ class Kronolith_Ajax_Application extends Horde_Core_Ajax_Application $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->hasAppPermission('max_events') !== true && $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."), $perms->hasAppPermission('max_events'))); - } - $GLOBALS['notification']->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'kronolith', + 'max_events', + sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')) + ); return $result; } } diff --git a/kronolith/new.php b/kronolith/new.php index d9deb1614..80ff1f7a9 100644 --- a/kronolith/new.php +++ b/kronolith/new.php @@ -23,12 +23,11 @@ $url = Horde::url($prefs->getValue('defaultview') . '.php', true) $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->hasAppPermission('max_events') !== true && $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."), $perms->hasAppPermission('max_events'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'kronolith', + 'max_events', + sprintf(_("You are not allowed to create more than %d events."), $perms->hasAppPermission('max_events')) + ); $url->redirect(); } diff --git a/mnemo/data.php b/mnemo/data.php index 46ad37586..156c2838d 100644 --- a/mnemo/data.php +++ b/mnemo/data.php @@ -34,12 +34,11 @@ $templates = array( ); if ($GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true && $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) { - try { - $message = Horde::callHook('perms_denied', array('mnemo:max_notes')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes'))); - } - $notification->push($message, 'horde.warning', array('content.raw')); + Horde::permissionDeniedError( + 'mnemo', + 'max_notes', + sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes')) + ); $templates[Horde_Data::IMPORT_FILE] = array(MNEMO_TEMPLATES . '/data/export.inc'); } else { $templates[Horde_Data::IMPORT_FILE] = array(MNEMO_TEMPLATES . '/data/import.inc', MNEMO_TEMPLATES . '/data/export.inc'); @@ -122,12 +121,11 @@ if (is_array($next_step)) { $num_memos = Mnemo::countMemos(); foreach ($next_step as $row) { if ($max_memos !== true && $num_memos >= $max_memos) { - try { - $message = Horde::callHook('perms_denied', array('mnemo:max_notes')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'mnemo', + 'max_notes', + sprintf(_("You are not allowed to create more than %d notes."), $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_notes')) + ); break; } diff --git a/mnemo/memo.php b/mnemo/memo.php index 1fe27c997..3ea0b8ad3 100644 --- a/mnemo/memo.php +++ b/mnemo/memo.php @@ -72,13 +72,11 @@ case 'add_memo': /* Check permissions. */ if ($injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') !== true && $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes') <= Mnemo::countMemos()) { - - try { - $message = Horde::callHook('perms_denied', array('mnemo:max_notes')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d notes."), $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'mnemo', + 'max_notes', + sprintf(_("You are not allowed to create more than %d notes."), $injector->getInstance('Horde_Perms')->hasAppPermission('max_notes')) + ); Horde::url('list.php', true)->redirect(); } /* Set up the note attributes. */ diff --git a/nag/data.php b/nag/data.php index c0da90e88..57bb5d23b 100644 --- a/nag/data.php +++ b/nag/data.php @@ -38,12 +38,11 @@ $templates = array( $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->hasAppPermission('max_tasks') !== true && $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."), $perms->hasAppPermission('max_tasks'))); - } - $notification->push($message, 'horde.warning', array('content.raw')); + Horde::permissionDeniedError( + 'nag', + 'max_tasks', + sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks')) + ); $templates[Horde_Data::IMPORT_FILE] = array(NAG_TEMPLATES . '/data/export.inc'); } else { $templates[Horde_Data::IMPORT_FILE] = array(NAG_TEMPLATES . '/data/import.inc', NAG_TEMPLATES . '/data/export.inc'); @@ -166,12 +165,11 @@ if (is_array($next_step)) { $result = null; foreach ($next_step as $row) { if ($max_tasks !== true && $num_tasks >= $max_tasks) { - 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."), $perms->hasAppPermission('max_tasks'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'nag', + 'max_tasks', + sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks')) + ); break; } diff --git a/nag/task.php b/nag/task.php index f744430b0..ed77ba097 100644 --- a/nag/task.php +++ b/nag/task.php @@ -68,12 +68,11 @@ case 'add_task': $perms = $GLOBALS['injector']->getInstance('Horde_Perms'); if ($perms->hasAppPermission('max_tasks') !== true && $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."), $perms->hasAppPermission('max_tasks'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'nag', + 'max_tasks', + sprintf(_("You are not allowed to create more than %d tasks."), $perms->hasAppPermission('max_tasks')) + ); Horde::url('list.php', true)->redirect(); } diff --git a/trean/add.php b/trean/add.php index 2b9421000..a76459e6d 100644 --- a/trean/add.php +++ b/trean/add.php @@ -20,12 +20,11 @@ case 'add_bookmark': /* Check permissions. */ if (Trean::hasPermission('max_bookmarks') !== true && Trean::hasPermission('max_bookmarks') <= $trean_shares->countBookmarks()) { - try { - $message = Horde::callHook('perms_denied', array('trean:max_bookmarks')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'trean', + 'max_bookmarks', + sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks')) + ); Horde::url('browse.php', true)->redirect(); } @@ -84,12 +83,11 @@ case 'add_folder': /* Check permissions. */ if (Trean::hasPermission('max_folders') !== true && Trean::hasPermission('max_folders') <= Trean::countFolders()) { - try { - $message = Horde::callHook('perms_denied', array('trean:max_folders')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'trean', + 'max_folders', + sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders')) + ); Horde::url('browse.php', true) ->add('f', $parent_id) ->redirect(); diff --git a/trean/data.php b/trean/data.php index 0ba672f77..2f07dff7e 100644 --- a/trean/data.php +++ b/trean/data.php @@ -53,22 +53,20 @@ Horde_Registry::appInit('trean'); $folders_exceeded = Trean::hasPermission('max_folders') !== true && Trean::hasPermission('max_folders') <= Trean::countFolders(); if ($folders_exceeded) { - try { - $message = Horde::callHook('perms_denied', array('trean:max_folders')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders'))); - } - $notification->push($message, 'horde.warning', array('content.raw')); + Horde::permissionDeniedError( + 'trean', + 'max_folders', + sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders')) + ); } $bookmarks_exceeded = Trean::hasPermission('max_bookmarks') !== true && Trean::hasPermission('max_bookmarks') <= $trean_shares->countBookmarks(); if ($bookmarks_exceeded) { - try { - $message = Horde::callHook('perms_denied', array('trean:max_bookmarks'),); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks'))); - } - $notification->push($message, 'horde.warning', array('content.raw')); + Horde::permissionDeniedError( + 'trean', + 'max_bookmarks', + sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks')) + ); } switch (Horde_Util::getFormData('actionID')) { @@ -106,12 +104,11 @@ case 'import': continue; } if ($max_folders !== true && $num_folders >= $max_folders) { - try { - $message = Horde::callHook('perms_denied', array('trean:max_folders')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'trean', + 'max_folders', + sprintf(_("You are not allowed to create more than %d folders."), Trean::hasPermission('max_folders')) + ); $stop_folders = true; continue; } @@ -132,12 +129,11 @@ case 'import': $line, $temp)) { /* A bookmark. */ if ($max_bookmarks !== true && $num_bookmarks >= $max_bookmarks) { - try { - $message = Horde::callHook('perms_denied', array('trean:max_bookmarks')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks'))); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'trean', + 'max_bookmarks', + sprintf(_("You are not allowed to create more than %d bookmarks."), Trean::hasPermission('max_bookmarks')) + ); $stop_bookmarks = true; break; } diff --git a/turba/add.php b/turba/add.php index ada57a7cd..9df85e4e2 100644 --- a/turba/add.php +++ b/turba/add.php @@ -45,12 +45,11 @@ if ($source) { $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts'); if ($max_contacts !== true && $max_contacts <= count($driver)) { - try { - $message = Horde::callHook('perms_denied', array('turba:max_contacts')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title'])); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'turba', + 'max_contacts', + sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title']) + ); $url = $url ? Horde::url($url, true) : Horde::url('index.php', true); diff --git a/turba/data.php b/turba/data.php index d483dff4c..f1ccaa244 100644 --- a/turba/data.php +++ b/turba/data.php @@ -346,12 +346,11 @@ case Horde_Data::IMPORT_FILE: $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts'); if ($max_contacts !== true && $max_contacts <= count($driver)) { - try { - $message = Horde::callHook('perms_denied', array('turba:max_contacts')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $driver->title)); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'turba', + 'max_contacts', + sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $driver->title) + ); $error = true; break; } diff --git a/turba/lib/View/Browse.php b/turba/lib/View/Browse.php index edd048aa1..ecb476378 100644 --- a/turba/lib/View/Browse.php +++ b/turba/lib/View/Browse.php @@ -148,14 +148,13 @@ class Turba_View_Browse { } $max_contacts = Turba::getExtendedPermission($targetDriver, 'max_contacts'); - if ($max_contacts !== true - && $max_contacts <= count($targetDriver)) { - try { - $message = Horde::callHook('perms_denied', array('turba:max_contacts')); - } catch (Horde_Exception_HookNotSet $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$targetSource]['title'])); - } - $notification->push($message, 'horde.error', array('content.raw')); + if ($max_contacts !== true && + $max_contacts <= count($targetDriver)) { + Horde::permissionDeniedError( + 'turba', + 'max_contacts', + sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$targetSource]['title']) + ); break; } @@ -302,12 +301,11 @@ class Turba_View_Browse { $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts'); if ($max_contacts !== true && $max_contacts <= count($driver)) { - try { - $message = Horde::callHook('perms_denied', array('turba:max_contacts')); - } catch (Horde_Exception $e) { - $message = htmlspecialchars(sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title'])); - } - $notification->push($message, 'horde.error', array('content.raw')); + Horde::permissionDeniedError( + 'turba', + 'max_contacts', + sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title']) + ); break; }