From d4e9ea07e815dbcc962144180415f42bbb3d94c7 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 31 Aug 2010 18:01:21 -0600 Subject: [PATCH] Clean up application removeUserData() functions --- ingo/lib/Application.php | 13 +++----- kronolith/lib/Application.php | 7 ++--- mnemo/lib/Api.php | 42 +++++++++---------------- nag/lib/Application.php | 30 +++++------------- turba/lib/Application.php | 72 ++++++++++++++++++++----------------------- 5 files changed, 61 insertions(+), 103 deletions(-) diff --git a/ingo/lib/Application.php b/ingo/lib/Application.php index e750fe432..ba91e0b6b 100644 --- a/ingo/lib/Application.php +++ b/ingo/lib/Application.php @@ -157,21 +157,16 @@ class Ingo_Application extends Horde_Registry_Application * * @param string $user Name of user to remove data for. * - * @throws Horde_Auth_Exception. + * @throws Ingo_Exception. */ public function removeUserData($user) { - if (!$GLOBALS['registry']->isAdmin() && - ($user != $GLOBALS['registry']->getAuth())) { - throw new Horde_Auth_Exception(_("You are not allowed to remove user data.")); - } - /* Remove all filters/rules owned by the user. */ try { $GLOBALS['ingo_storage']->removeUserData($user); } catch (Ingo_Exception $e) { Horde::logMessage($e, 'ERR'); - throw new Horde_Auth_Exception($e); + throw $e; } /* Now remove all shares owned by the user. */ @@ -181,7 +176,7 @@ class Ingo_Application extends Horde_Registry_Application $share = $GLOBALS['ingo_shares']->getShare($user); $GLOBALS['ingo_shares']->removeShare($share); } catch (Horde_Share_Exception $e) { - Horde::logMessage($e->getMessage(), 'ERR'); + Horde::logMessage($e, 'ERR'); throw new Ingo_Exception($e); } @@ -192,7 +187,7 @@ class Ingo_Application extends Horde_Registry_Application foreach ($shares as $share) { $share->removeUser($user); } - } catch (Horde_Shares_Exception $e) { + } catch (Horde_Share_Exception $e) { Horde::logMessage($e, 'ERR'); } diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index ef88b2703..aac36b8eb 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -429,11 +429,6 @@ class Kronolith_Application extends Horde_Registry_Application */ public function removeUserData($user) { - if (!$GLOBALS['registry']->isAdmin() && - $user != $GLOBALS['registry']->getAuth()) { - throw new Kronolith_Exception(_("You are not allowed to remove user data.")); - } - /* Remove all events owned by the user in all calendars. */ $result = Kronolith::getDriver()->removeUserData($user); @@ -443,6 +438,7 @@ class Kronolith_Application extends Horde_Registry_Application $result = $GLOBALS['kronolith_shares']->removeShare($share); } catch (Exception $e) { Horde::logMessage($e, 'ERR'); + throw $e; } /* Get a list of all shares this user has perms to and remove the @@ -454,6 +450,7 @@ class Kronolith_Application extends Horde_Registry_Application } } catch (Horde_Share_Exception $e) { Horde::logMessage($e, 'ERR'); + throw $e; } } diff --git a/mnemo/lib/Api.php b/mnemo/lib/Api.php index 78f6ce47f..aec1b7aea 100644 --- a/mnemo/lib/Api.php +++ b/mnemo/lib/Api.php @@ -5,46 +5,38 @@ * This file defines Mnemo's external API interface. Other applications can * interact with Mnemo through this API. * - * $Horde: mnemo/lib/api.php,v 1.99 2009-11-24 04:13:44 chuck Exp $ - * * Copyright 2001-2009 The Horde Project (http://www.horde.org/) * * See the enclosed file LICENSE for license information (ASL). If you * did not receive this file, see http://www.horde.org/licenses/asl.php. * - * @since Mnemo 1.0 - * @package Mnemo + * @category Horde + * @package Mnemo */ -class Mnemo_Api extends Horde_Registry_Api { - +class Mnemo_Api extends Horde_Registry_Api +{ /** * Removes user data. * * @param string $user Name of user to remove data for. * - * @return mixed true on success | PEAR_Error on failure + * @throws Mnemo_Exception */ public function removeUserData($user) { - if (!$GLOBALS['registry']->isAdmin() && $user != $GLOBALS['registry']->getAuth()) { - return PEAR::raiseError(_("You are not allowed to remove user data.")); - } - - /* Error flag */ - $hasError = false; - /* Get the share object for later deletion */ try { $share = $GLOBALS['mnemo_shares']->getShare($user); } catch (Horde_Share_Exception $e) { - Horde::logMessage($e->getMessage(), 'ERR'); + Horde::logMessage($e), 'ERR'); } + $GLOBALS['display_notepads'] = array($user); $memos = Mnemo::listMemos(); if ($memos instanceof PEAR_Error) { - $hasError = true; - Horde::logMessage($mnemos->getMessage(), 'ERR'); + Horde::logMessage($mnemos, 'ERR'); + throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user)); } else { $uids = array(); foreach ($memos as $memo) { @@ -62,27 +54,21 @@ class Mnemo_Api extends Horde_Registry_Api { try { $GLOBALS['mnemo_shares']->removeShare($share); } catch (Horde_Share_Exception $e) { - $hasError = true; - Horde::logMessage($e->getMessage(), 'ERR'); + Horde::logMessage($e, 'ERR'); + throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user)); } } - /* Get a list of all shares this user has perms to and remove the perms */ + /* Get a list of all shares this user has perms to and remove the + * perms. */ try { $shares = $GLOBALS['mnemo_shares']->listShares($user); foreach ($shares as $share) { $share->removeUser($user); } } catch (Horde_Share_Exception $e) { - $hasError = true; Horde::logMessage($e, 'ERR'); - } - - - if ($hasError) { - return PEAR::raiseError(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user)); - } else { - return true; + throw new Mnemo_Exception(sprintf(_("There was an error removing notes for %s. Details have been logged."), $user)); } } diff --git a/nag/lib/Application.php b/nag/lib/Application.php index 95ee7f84a..98235382b 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -230,29 +230,22 @@ class Nag_Application extends Horde_Registry_Application * * @param string $user Name of user to remove data for. * - * @return mixed true on success | PEAR_Error on failure + * @throws Nag_Exception */ public function removeUserData($user) { - if (!$GLOBALS['registry']->isAdmin() && $user != $GLOBALS['registry']->getAuth()) { - return PEAR::raiseError(_("You are not allowed to remove user data.")); - } - - /* Error flag */ - $hasError = false; - /* Get the share for later deletion */ try { $share = $GLOBALS['nag_shares']->getShare($user); } catch (Horde_Share_Exception $e) { - Horde::logMessage($e->getMessage(), 'ERR'); + Horde::logMessage($e, 'ERR'); } /* Get the list of all tasks */ $tasks = Nag::listTasks(null, null, null, $user, 1); if ($tasks instanceof PEAR_Error) { - $hasError = true; - Horde::logMessage($share, 'ERR'); + Horde::logMessage($tasks, 'ERR'); + throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user)); } else { $uids = array(); $tasks->reset(); @@ -266,14 +259,13 @@ class Nag_Application extends Horde_Registry_Application } } - /* ...and finally, delete the actual share */ if (!empty($share)) { try { $GLOBALS['nag_shares']->removeShare($share); } catch (Horde_Share_Exception $e) { - $hasError = true; - Horde::logMessage($result, 'ERR'); + Horde::logMessage($e, 'ERR'); + throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user)); } } @@ -284,14 +276,8 @@ class Nag_Application extends Horde_Registry_Application $share->removeUser($user); } } catch (Horde_Share_Exception $e) { - $hasError = true; - Horde::logMessage($shares, 'ERR'); - } - - if ($hasError) { - return PEAR::raiseError(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user)); - } else { - return true; + Horde::logMessage($e, 'ERR'); + throw new Nag_Exception(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user)); } } diff --git a/turba/lib/Application.php b/turba/lib/Application.php index 579d4868f..efa52a441 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -387,18 +387,12 @@ class Turba_Application extends Horde_Registry_Application * * @param string $user Name of user to remove data for. * - * @throws Horde_Exception + * @throws Turba_Exception */ public function removeUserData($user) { - if (!$GLOBALS['registry']->isAdmin() && - ($user != $GLOBALS['registry']->getAuth())) { - throw new Horde_Exception(_("You are not allowed to remove user data.")); - } - /* We need a clean copy of the $cfgSources array here.*/ require TURBA_BASE . '/config/sources.php'; - $hasError = false; foreach ($cfgSources as $source) { if (empty($source['use_shares'])) { @@ -407,57 +401,57 @@ class Turba_Application extends Horde_Registry_Application $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($source); } catch (Turba_Exception $e) { Horde::logMessage($e, 'ERR'); - $hasError = true; - continue; + throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user)); } try { $driver->removeUserData($user); } catch (Turba_Exception $e) { Horde::logMessage($e, 'ERR'); + throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user)); } } } /* Only attempt share removal if we have shares configured */ - if (!empty($_SESSION['turba']['has_share'])) { - $shares = $GLOBALS['turba_shares']->listShares( - $user, Horde_Perms::EDIT, $user); + if (empty($_SESSION['turba']['has_share'])) { + return; + } - /* Look for the deleted user's default share and remove it */ - foreach ($shares as $share) { - $params = @unserialize($share->get('params')); - /* Only attempt to delete the user's default share */ - if (!empty($params['default'])) { - $config = Turba::getSourceFromShare($share); - try { - $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($config); - } catch (Turba_Exception $e) { - continue; - } + $shares = $GLOBALS['turba_shares']->listShares($user, Horde_Perms::EDIT, $user); - try { - $driver->removeUserData($user); - } catch (Turba_Exception $e) { - Horde::logMessage($e, 'ERR'); - $hasError = true; - } + /* Look for the deleted user's default share and remove it */ + foreach ($shares as $share) { + $params = @unserialize($share->get('params')); + + /* Only attempt to delete the user's default share */ + if (!empty($params['default'])) { + $config = Turba::getSourceFromShare($share); + try { + $driver = $GLOBALS['injector']->getInstance('Turba_Driver')->getDriver($config); + } catch (Turba_Exception $e) { + continue; } - } - /* Get a list of all shares this user has perms to and remove the perms. */ - try { - $shares = $GLOBALS['turba_shares']->listShares($user); - foreach ($shares as $share) { - $share->removeUser($user); + try { + $driver->removeUserData($user); + } catch (Turba_Exception $e) { + Horde::logMessage($e, 'ERR'); + throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user)); } - } catch (Horde_Share_Exception $e) { - Horde::logMessage($e, 'ERR'); } } - if ($hasError) { - throw new Horde_Exception(sprintf(_("There was an error removing an address book for %s"), $user)); + /* Get a list of all shares this user has perms to and remove the + * perms. */ + try { + $shares = $GLOBALS['turba_shares']->listShares($user); + foreach ($shares as $share) { + $share->removeUser($user); + } + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e, 'ERR'); + throw new Turba_Exception(sprintf(_("There was an error removing an address book for %s"), $user)); } } -- 2.11.0