From: Michael M Slusarz Date: Tue, 1 Jun 2010 08:34:41 +0000 (-0600) Subject: Throw Exceptions; PEAR_Error removal X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b6422461f93ef14c20c52830caeff86fbab08b3e;p=horde.git Throw Exceptions; PEAR_Error removal --- diff --git a/horde/admin/signup_confirm.php b/horde/admin/signup_confirm.php index ae981dee2..c3ccefb59 100644 --- a/horde/admin/signup_confirm.php +++ b/horde/admin/signup_confirm.php @@ -35,10 +35,7 @@ if (hash_hmac('sha1', $user, $conf['secret_key']) != $hash) { // Deny signup. if ($action == 'deny') { - $result = $signup->removeQueuedSignup($user); - if (is_a($result, 'PEAR_Error')) { - throw new Horde_Exception_Prior($result); - } + $signup->removeQueuedSignup($user); printf(_("The signup request for user \"%s\" has been removed."), $user); exit; } @@ -71,8 +68,10 @@ if (isset($info['extra'])) { } // Add user. -if (is_a($ret = $auth->addUser($info['user_name'], $credentials), 'PEAR_Error')) { - throw new Horde_Exception(sprintf(_("There was a problem adding \"%s\" to the system: %s"), $info['user_name'], $ret->getMessage())); +try { + $auth->addUser($info['user_name'], $credentials); +} catch (Horde_Auth_Exception $e) { + throw new Horde_Exception(sprintf(_("There was a problem adding \"%s\" to the system: %s"), $info['user_name'], $e->getMessage())); } if (isset($info['extra'])) { try { diff --git a/horde/lib/Api.php b/horde/lib/Api.php index 2d44c67cd..ab8a9cc6c 100644 --- a/horde/lib/Api.php +++ b/horde/lib/Api.php @@ -197,12 +197,14 @@ class Horde_Api extends Horde_Registry_Api * Removes user data. * * @param string $user Name of user to remove data for. + * + * @throws Horde_Exception */ public function removeUserData($user) { if (!$GLOBALS['registry']->isAdmin() && $user != Horde_Auth::getAuth()) { - return PEAR::raiseError(_("You are not allowed to remove user data.")); + throw new Horde_Exception(_("You are not allowed to remove user data.")); } global $conf; @@ -254,10 +256,8 @@ class Horde_Api extends Horde_Registry_Api } } - if (!$haveError) { - return true; - } else { - return PEAR::raiseError(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user)); + if ($haveError) { + throw new Horde_Exception(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user)); } } @@ -265,11 +265,13 @@ class Horde_Api extends Horde_Registry_Api * Removes user data from all applications. * * @param string $user Name of user to remove data for. + * + * @throws Horde_Exception */ public function removeUserDataFromAllApplications($user) { if (!$GLOBALS['registry']->isAdmin() && $user != Auth::getAuth()) { - return PEAR::raiseError(_("You are not allowed to remove user data.")); + throw new Horde_Exception(_("You are not allowed to remove user data.")); } /* Error flag */ @@ -277,10 +279,6 @@ class Horde_Api extends Horde_Registry_Api /* Get all APIs */ $apis = $this->listAPIs(); - if (is_a($apis, 'PEAR_Error')) { - Horde::logMessage($apis, 'ERR'); - return PEAR::raiseError(_("No API found.")); - } foreach ($apis as $api) { if ($GLOBALS['registry']->hasAppMethod($api, 'removeUserData')) { $result = $GLOBALS['registry']->callAppMethod($api, 'removeUserData', array('args' => array($user))); @@ -295,10 +293,8 @@ class Horde_Api extends Horde_Registry_Api $haveError = true; } - if (!$haveError) { - return true; - } else { - return PEAR::raiseError(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user)); + if ($haveError) { + throw new Horde_Exception(sprintf(_("There was an error removing global data for %s. Details have been logged."), $user)); } } @@ -309,11 +305,13 @@ class Horde_Api extends Horde_Registry_Api * * @param string $name The group's name. * @param string $parent The group's parent's name. + * + * @throws Horde_Exception */ public function addGroup($name, $parent = null) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to add groups.")); + throw new Horde_Exception(_("You are not allowed to add groups.")); } require_once 'Horde/Group.php'; @@ -324,39 +322,37 @@ class Horde_Api extends Horde_Registry_Api } if (is_a($group = &$groups->newGroup($name, $parent), 'PEAR_Error')) { - return $group; + throw new Horde_Exception($group); } if (is_a($result = $groups->addGroup($group), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** * Removes a group from the groups system. * * @param string $name The group's name. + * + * @throws Horde_Exception */ public function removeGroup($name) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to delete groups.")); + throw new Horde_Exception(_("You are not allowed to delete groups.")); } require_once 'Horde/Group.php'; $groups = Group::singleton(); if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { - return $group; + throw new Horde_Exception($group); } if (is_a($result = $groups->removeGroup($group, true), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -364,25 +360,25 @@ class Horde_Api extends Horde_Registry_Api * * @param string $name The group's name. * @param string $user The user to add. + * + * @throws Horde_Exception */ public function addUserToGroup($name, $user) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change groups.")); + throw new Horde_Exception(_("You are not allowed to change groups.")); } require_once 'Horde/Group.php'; $groups = Group::singleton(); if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { - return $group; + throw new Horde_Exception($group); } if (is_a($result = $group->addUser($user), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -390,18 +386,20 @@ class Horde_Api extends Horde_Registry_Api * * @param string $name The group's name. * @param array $users The users to add. + * + * @throws Horde_Exception */ public function addUsersToGroup($name, $users) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change groups.")); + throw new Horde_Exception(_("You are not allowed to change groups.")); } require_once 'Horde/Group.php'; $groups = Group::singleton(); if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { - return $group; + throw new Horde_Exception($group); } foreach ($users as $user) { @@ -409,10 +407,8 @@ class Horde_Api extends Horde_Registry_Api } if (is_a($result = $group->save(), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -420,25 +416,25 @@ class Horde_Api extends Horde_Registry_Api * * @param string $name The group's name. * @param string $user The user to add. + * + * @throws Horde_Exception */ public function removeUserFromGroup($name, $user) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change groups.")); + throw new Horde_Exception(_("You are not allowed to change groups.")); } require_once 'Horde/Group.php'; $groups = Group::singleton(); if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { - return $group; + throw new Horde_Exception($group); } if (is_a($result = $group->removeUser($user), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -446,31 +442,31 @@ class Horde_Api extends Horde_Registry_Api * * @param string $name The group's name. * @param array $users The users to add. + * + * @throws Horde_Exception */ public function removeUsersFromGroup($name, $users) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change groups.")); + throw new Horde_Exception(_("You are not allowed to change groups.")); } require_once 'Horde/Group.php'; $groups = Group::singleton(); if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { - return $group; + throw new Horde_Exception($group); } foreach ($users as $user) { if (is_a($result = $group->removeUser($user, false), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } } if (is_a($result = $group->save(), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -479,18 +475,19 @@ class Horde_Api extends Horde_Registry_Api * @param string $name The group's name. * * @return array The user list. + * @throws Horde_Exception */ public function listUsersOfGroup($name) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to list users of groups.")); + throw new Horde_Exception(_("You are not allowed to list users of groups.")); } require_once 'Horde/Group.php'; $groups = Group::singleton(); if (is_a($group = &$groups->getGroup($name), 'PEAR_Error')) { - return $group; + throw new Horde_Exception($group); } return $group->listUsers(); @@ -506,26 +503,27 @@ class Horde_Api extends Horde_Registry_Api * @param string $shareName The share's name. * @param string $shareTitle The share's human readable title. * @param string $userName The share's owner. + * + * @throws Horde_Exception */ public function addShare($scope, $shareName, $shareTitle, $userName) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to add shares.")); + throw new Horde_Exception(_("You are not allowed to add shares.")); } $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->newShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } + $share->set('owner', $userName); $share->set('name', $shareTitle); if (is_a($result = $shares->addShare($share), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -534,24 +532,24 @@ class Horde_Api extends Horde_Registry_Api * @param string $scope The name of the share root, e.g. the * application that the share belongs to. * @param string $shareName The share's name. + * + * @throws Horde_Exception */ public function removeShare($scope, $shareName) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to delete shares.")); + throw new Horde_Exceptionr(_("You are not allowed to delete shares.")); } $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } if (is_a($result = $shares->removeShare($share), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -562,11 +560,12 @@ class Horde_Api extends Horde_Registry_Api * @param string $userName The share's owner. * * @return array The list of shares. + * @throws Horde_Exception */ public function listSharesOfOwner($scope, $userName) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to list shares.")); + throw new Horde_Exception(_("You are not allowed to list shares.")); } $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); @@ -588,18 +587,20 @@ class Horde_Api extends Horde_Registry_Api * @param string $shareName The share's name. * @param string $userName The user's name. * @param array $permissions A list of permissions (show, read, edit, delete). + * + * @throws Horde_Exception */ public function addUserPermissions($scope, $shareName, $userName, $permissions) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change shares.")); + throw new Horde_Exception(_("You are not allowed to change shares.")); } $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } $perm = &$share->getPermission(); @@ -611,26 +612,26 @@ class Horde_Api extends Horde_Registry_Api } if (is_a($result = $share->setPermission($perm), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** * Gives a group certain privileges for a share. * - * @param string $scope The name of the share root, e.g. the + * @param string $scope The name of the share root, e.g. the * application that the share belongs to. * @param string $shareName The share's name. * @param string $groupName The group's name. * @param array $permissions A list of permissions (show, read, edit, delete). + * + * @throws Horde_Exception */ public function addGroupPermissions($scope, $shareName, $groupName, $permissions) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change shares.")); + throw new Horde_Exception(_("You are not allowed to change shares.")); } require_once 'Horde/Group.php'; @@ -638,10 +639,10 @@ class Horde_Api extends Horde_Registry_Api $groups = Group::singleton(); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } if (is_a($groupId = $groups->getGroupId($groupName), 'PEAR_Error')) { - return $groupId; + throw new Horde_Exception($groupId); } $perm = &$share->getPermission(); @@ -653,10 +654,8 @@ class Horde_Api extends Horde_Registry_Api } if (is_a($result = $share->setPermission($perm), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -666,24 +665,24 @@ class Horde_Api extends Horde_Registry_Api * application that the share belongs to. * @param string $shareName The share's name. * @param string $userName The user's name. + * + * @throws Horde_Exception */ public function removeUserPermissions($scope, $shareName, $userName) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change shares.")); + throw new Horde_Exception(_("You are not allowed to change shares.")); } $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } if (is_a($result = $share->removeUser($userName), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -693,11 +692,13 @@ class Horde_Api extends Horde_Registry_Api * application that the share belongs to. * @param string $shareName The share's name. * @param string $groupName The group's name. + * + * @throws Horde_Exception */ public function removeGroupPermissions($scope, $shareName, $groupName) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to change shares.")); + throw new Horde_Exception(_("You are not allowed to change shares.")); } require_once 'Horde/Group.php'; @@ -705,17 +706,16 @@ class Horde_Api extends Horde_Registry_Api $groups = Group::singleton(); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } + if (is_a($groupId = $groups->getGroupId($groupName), 'PEAR_Error')) { - return $groupId; + throw new Horde_Exception($groupId); } if (is_a($result = $share->removeGroup($groupId), 'PEAR_Error')) { - return $result; + throw new Horde_Exception($result); } - - return true; } /** @@ -727,11 +727,12 @@ class Horde_Api extends Horde_Registry_Api * @param string $userName The user's name. * * @return array All user permissions for this share. + * @throws Horde_Exception */ public function listUserPermissions($scope, $shareName, $userName) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to list share permissions.")); + throw new Horde_Exception(_("You are not allowed to list share permissions.")); } $perm_map = array(Horde_Perms::SHOW => 'show', @@ -742,7 +743,7 @@ class Horde_Api extends Horde_Registry_Api $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } $perm = &$share->getPermission(); @@ -768,11 +769,12 @@ class Horde_Api extends Horde_Registry_Api * @param string $groupName The group's name. * * @return array All group permissions for this share. + * @throws Horde_Exception */ public function listGroupPermissions($scope, $shareName, $groupName) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to list share permissions.")); + throw new Horde_Exception(_("You are not allowed to list share permissions.")); } $perm_map = array(Horde_Perms::SHOW => 'show', @@ -783,7 +785,7 @@ class Horde_Api extends Horde_Registry_Api $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } $perm = &$share->getPermission(); @@ -809,17 +811,18 @@ class Horde_Api extends Horde_Registry_Api * @param array $permissions A list of permissions (show, read, edit, delete). * * @return array List of users with the specified permissions. + * @throws Horde_Exception */ public function listUsersOfShare($scope, $shareName, $permissions) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to list users of shares.")); + throw new Horde_Exception(_("You are not allowed to list users of shares.")); } $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } $perm = 0; @@ -842,17 +845,18 @@ class Horde_Api extends Horde_Registry_Api * @param array $permissions A list of permissions (show, read, edit, delete). * * @return array List of groups with the specified permissions. + * @throws Horde_Exception */ public function listGroupsOfShare($scope, $shareName, $permissions) { if (!$GLOBALS['registry']->isAdmin()) { - return PEAR::raiseError(_("You are not allowed to list groups of shares.")); + throw new Horde_Exception(_("You are not allowed to list groups of shares.")); } $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope($scope); if (is_a($share = &$shares->getShare($shareName), 'PEAR_Error')) { - return $share; + throw new Horde_Exception($share); } $perm = 0; diff --git a/horde/signup.php b/horde/signup.php index 4f636ac17..21cf334fd 100644 --- a/horde/signup.php +++ b/horde/signup.php @@ -34,30 +34,36 @@ $vars = Horde_Variables::getDefaultVariables(); $formsignup = new Horde_Core_Auth_Signup_Form($vars); if ($formsignup->validate()) { $formsignup->getInfo($vars, $info); - $success_message = null; + $error = $success_message = null; - if (!$conf['signup']['approve']) { - /* User can sign up directly, no intervention necessary. */ - $success = $signup->addSignup($info); - if (!is_a($success, 'PEAR_Error')) { - $success_message = sprintf(_("Added \"%s\" to the system. You can log in now."), $info['user_name']); - } - } elseif ($conf['signup']['approve']) { - /* Insert this user into a queue for admin approval. */ - $success = $signup->queueSignup($info); - if (!is_a($success, 'PEAR_Error')) { - $success_message = sprintf(_("Submitted request to add \"%s\" to the system. You cannot log in until your request has been approved."), $info['user_name']); - } - } - - if (is_a($info, 'PEAR_Error')) { + if ($info instanceof PEAR_Error) { $notification->push(sprintf(_("There was a problem adding \"%s\" to the system: %s"), $vars->get('user_name'), $info->getMessage()), 'horde.error'); - } elseif (is_a($success, 'PEAR_Error')) { - $notification->push(sprintf(_("There was a problem adding \"%s\" to the system: %s"), $info['user_name'], $success->getMessage()), 'horde.error'); } else { - $notification->push($success_message, 'horde.success'); - header('Location: ' . Horde::getServiceLink('login')->add('url', $info['url'])->setRaw(true)); - exit; + if (!$conf['signup']['approve']) { + /* User can sign up directly, no intervention necessary. */ + try { + $signup->addSignup($info); + $success_message = sprintf(_("Added \"%s\" to the system. You can log in now."), $info['user_name']); + } catch (Horde_Exception $e) { + $error = $e; + } + } elseif ($conf['signup']['approve']) { + /* Insert this user into a queue for admin approval. */ + try { + $signup->queueSignup($info); + $success_message = sprintf(_("Submitted request to add \"%s\" to the system. You cannot log in until your request has been approved."), $info['user_name']); + } catch (Horde_Exception $e) { + $error = $e; + } + } + + if ($error) { + $notification->push(sprintf(_("There was a problem adding \"%s\" to the system: %s"), $info['user_name'], $e->getMessage()), 'horde.error'); + } else { + $notification->push($success_message, 'horde.success'); + header('Location: ' . Horde::getServiceLink('login')->add('url', $info['url'])->setRaw(true)); + exit; + } } } diff --git a/horde/templates/admin/user/approve.inc b/horde/templates/admin/user/approve.inc index 28d4ae8ee..eb5d02822 100644 --- a/horde/templates/admin/user/approve.inc +++ b/horde/templates/admin/user/approve.inc @@ -1,9 +1,15 @@ +getQueuedSignups(); +} catch (Horde_Exception $e) { + $allQueued = $e; +} +?>

-getQueuedSignups() ?> - +
getMessage()) ?>
diff --git a/horde/templates/portal/edit.inc b/horde/templates/portal/edit.inc index f8e1fead0..4cf52658b 100644 --- a/horde/templates/portal/edit.inc +++ b/horde/templates/portal/edit.inc @@ -11,7 +11,7 @@ for ($row = 0; $row < $rows; ++$row): columns($row); -if (is_a($columns, 'PEAR_Error')) { +if ($columns instanceof PEAR_Error) { $columns = 0; } for ($col = 0; $col < $columns; ++$col):