From: Michael J. Rubinsky Date: Thu, 20 May 2010 03:39:05 +0000 (-0400) Subject: Track Horde_Share changes X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f4b1b4414324592a010911aad35dcf557561f11f;p=horde.git Track Horde_Share changes --- diff --git a/nag/lib/Api.php b/nag/lib/Api.php index fc6fbf67a..aa3eee77d 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -132,10 +132,13 @@ class Nag_Api extends Horde_Registry_Api */ public static function updateTasklist($id, $info) { - $tasklist = $GLOBALS['nag_shares']->getShare($id); - if (is_a($tasklist, 'PEAR_Error')) { - return $tasklist; + try { + $tasklist = $GLOBALS['nag_shares']->getShare($id); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Nag_Exception($e); } + return Nag::updateTasklist($tasklist, $info); } @@ -622,10 +625,10 @@ class Nag_Api extends Horde_Registry_Api } else { // Remove share and all groups/permissions. $share = $GLOBALS['nag_shares']->getShare($tasklistID); - $result = $GLOBALS['nag_shares']->removeShare($share); - if (is_a($result, 'PEAR_Error')) { - $result->code = 500; - return $result; + try { + $GLOBALS['nag_shares']->removeShare($share); + } catch (Horde_Share_Exception $e) { + throw new Nag_Exception($e->getMessage()); } } } @@ -934,13 +937,14 @@ class Nag_Api extends Horde_Registry_Api return PEAR::raiseError(_("Permission Denied")); } - $share = $GLOBALS['nag_shares']->getShare($tasklist_id); - if (is_a($share, 'PEAR_Error')) { - return $share; + try { + $share = $GLOBALS['nag_shares']->getShare($tasklist_id); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Nag_Exception($e); } - $task = Nag::getTask($tasklist_id, $task_id); - if (is_a($task, 'PEAR_Error')) { + if ($task instanceof PEAR_Error) { return $task; } @@ -1378,13 +1382,14 @@ class Nag_Api extends Horde_Registry_Api $tasklists = is_null($user) ? array_keys($GLOBALS['nag_shares']->listAllShares()) : $GLOBALS['display_tasklists']; $alarms = Nag::listAlarms($time, $tasklists); - if (is_a($alarms, 'PEAR_Error')) { + if (is_a($alarms instanceof PEAR_Error) { return $alarms; } foreach ($alarms as $alarm) { - $share = $GLOBALS['nag_shares']->getShare($alarm->tasklist); - if (is_a($share, 'PEAR_Error')) { + try { + $share = $GLOBALS['nag_shares']->getShare($alarm->tasklist); + } catch (Horde_Share_Exception $e) { continue; } if (empty($user)) { diff --git a/nag/lib/Application.php b/nag/lib/Application.php index 657a287ed..aed9603cd 100644 --- a/nag/lib/Application.php +++ b/nag/lib/Application.php @@ -242,48 +242,51 @@ class Nag_Application extends Horde_Registry_Application $hasError = false; /* Get the share for later deletion */ - $share = $GLOBALS['nag_shares']->getShare($user); - if(is_a($share, 'PEAR_Error')) { + try { + $share = $GLOBALS['nag_shares']->getShare($user); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), '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'); - unset($share); } else { - /* Get the list of all tasks */ - $tasks = Nag::listTasks(null, null, null, $user, 1); - if (is_a($tasks, 'PEAR_Error')) { - $hasError = true; - Horde::logMessage($share, 'ERR'); - } else { - $uids = array(); - $tasks->reset(); - while ($task = $tasks->each()) { - $uids[] = $task->uid; - } + $uids = array(); + $tasks->reset(); + while ($task = $tasks->each()) { + $uids[] = $task->uid; + } - /* ... and delete them. */ - foreach ($uids as $uid) { - $this->delete($uid); - } + /* ... and delete them. */ + foreach ($uids as $uid) { + $this->delete($uid); } } + /* ...and finally, delete the actual share */ if (!empty($share)) { - $result = $GLOBALS['nag_shares']->removeShare($share); - if (is_a($result, 'PEAR_Error')) { + try { + $GLOBALS['nag_shares']->removeShare($share); + } catch (Horde_Share_Exception $e) { $hasError = true; Horde::logMessage($result, 'ERR'); } } /* Now remove perms for this user from all other shares */ - $shares = $GLOBALS['nag_shares']->listShares($user); - if (is_a($shares, 'PEAR_Error')) { + try { + $shares = $GLOBALS['nag_shares']->listShares($user); + foreach ($shares as $share) { + $share->removeUser($user); + } + } catch (Horde_Share_Exception $e) { $hasError = true; Horde::logMessage($shares, 'ERR'); } - foreach ($shares as $share) { - $share->removeUser($user); - } if ($hasError) { return PEAR::raiseError(sprintf(_("There was an error removing tasks for %s. Details have been logged."), $user)); diff --git a/nag/lib/Block/summary.php b/nag/lib/Block/summary.php index 9dace3aa7..dd0cb7265 100644 --- a/nag/lib/Block/summary.php +++ b/nag/lib/Block/summary.php @@ -204,9 +204,7 @@ class Horde_Block_nag_summary extends Horde_Block { $owner = $task->tasklist; $shares = $GLOBALS['injector']->getInstance('Horde_Share')->getScope(); $share = $shares->getShare($owner); - if (!is_a($share, 'PEAR_Error')) { - $owner = $share->get('name'); - } + $owner = $share->get('name'); $html .= '' . htmlspecialchars($owner) . ' '; } diff --git a/nag/lib/Driver.php b/nag/lib/Driver.php index 8663ac4b6..500df7015 100644 --- a/nag/lib/Driver.php +++ b/nag/lib/Driver.php @@ -309,9 +309,11 @@ class Nag_Driver $log_tasklist = $this->_tasklist; if (!is_null($tasklist) && $task->tasklist != $tasklist) { /* Moving the task to another tasklist. */ - $share = $GLOBALS['nag_shares']->getShare($task->tasklist); - if (is_a($share, 'PEAR_Error')) { - return $share; + try { + $share = $GLOBALS['nag_shares']->getShare($task->tasklist); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Nag_Exception($e); } if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { @@ -319,9 +321,11 @@ class Nag_Driver return false; } - $share = $GLOBALS['nag_shares']->getShare($tasklist); - if (is_a($share, 'PEAR_Error')) { - return $share; + try { + $share = $GLOBALS['nag_shares']->getShare($tasklist); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Nag_Exception($e); } if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { @@ -329,7 +333,7 @@ class Nag_Driver } $moved = $this->_move($task->id, $tasklist); - if (is_a($moved, 'PEAR_Error')) { + if ($moved instanceof PEAR_Error) { return $moved; } $new_storage = Nag_Driver::singleton($tasklist); diff --git a/nag/lib/Driver/Kolab.php b/nag/lib/Driver/Kolab.php index bf2d6d6ae..bd1116738 100644 --- a/nag/lib/Driver/Kolab.php +++ b/nag/lib/Driver/Kolab.php @@ -1043,7 +1043,7 @@ class Nag_Driver_kolab_wrapper_new extends Nag_Driver_kolab_wrapper { function listAlarms($date) { $task_list = $this->_store->getObjects(); - if (is_a($task_list, 'PEAR_Error')) { + if ($task_list instanceof PEAR_Error) { return $task_list; } diff --git a/nag/lib/Exception.php b/nag/lib/Exception.php new file mode 100644 index 000000000..b68626176 --- /dev/null +++ b/nag/lib/Exception.php @@ -0,0 +1,14 @@ +id)] = str_repeat(' ', $task->indent * 4) . htmlentities($task->name, ENT_COMPAT, Horde_Nls::getCharset()); } $users = array(); - $share = &$GLOBALS['nag_shares']->getShare($tasklist); - if (!is_a($share, 'PEAR_Error')) { - $users = $share->listUsers(Horde_Perms::READ); - $groups = $share->listGroups(Horde_Perms::READ); - if (count($groups)) { - require_once 'Horde/Group.php'; - $horde_group = Group::singleton(); - foreach ($groups as $group) { - $users = array_merge($users, - $horde_group->listAllUsers($group)); - } + $share = $GLOBALS['nag_shares']->getShare($tasklist); + $users = $share->listUsers(Horde_Perms::READ); + $groups = $share->listGroups(Horde_Perms::READ); + if (count($groups)) { + require_once 'Horde/Group.php'; + $horde_group = Group::singleton(); + foreach ($groups as $group) { + $users = array_merge($users, + $horde_group->listAllUsers($group)); } - $users = array_flip($users); } + $users = array_flip($users); + if (count($users)) { foreach (array_keys($users) as $user) { $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getIdentity($user); diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index 473d323dc..ece4d2b39 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -368,9 +368,10 @@ class Nag if ($owneronly && !Horde_Auth::getAuth()) { return array(); } - $tasklists = $GLOBALS['nag_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name'); - if (is_a($tasklists, 'PEAR_Error')) { - Horde::logMessage($tasklists, 'ERR'); + try { + $tasklists = $GLOBALS['nag_shares']->listShares(Horde_Auth::getAuth(), $permission, $owneronly ? Horde_Auth::getAuth() : null, 0, 0, 'name'); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); return array(); } @@ -438,20 +439,18 @@ class Nag */ public static function addTasklist($info) { - $tasklist = $GLOBALS['nag_shares']->newShare(md5(microtime())); - if (is_a($tasklist, 'PEAR_Error')) { - return $tasklist; - } - $tasklist->set('name', $info['name']); - $tasklist->set('color', $info['color']); - $tasklist->set('desc', $info['description']); - if (!empty($info['system'])) { - $tasklist->set('owner', null); - } + try { + $tasklist = $GLOBALS['nag_shares']->newShare(md5(microtime())); + $tasklist->set('name', $info['name']); + $tasklist->set('color', $info['color']); + $tasklist->set('desc', $info['description']); + if (!empty($info['system'])) { + $tasklist->set('owner', null); + } - $result = $GLOBALS['nag_shares']->addShare($tasklist); - if (is_a($result, 'PEAR_Error')) { - return $result; + $GLOBALS['nag_shares']->addShare($tasklist); + } catch (Horde_Share_Exception $e) { + throw new Nag_Exception($e); } $GLOBALS['display_tasklists'][] = $tasklist->getName(); @@ -504,7 +503,7 @@ class Nag // Delete the task list. $storage = &Nag_Driver::singleton($tasklist->getName()); $result = $storage->deleteAll(); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { return PEAR::raiseError(sprintf(_("Unable to delete \"%s\": %s"), $tasklist->get('name'), $result->getMessage())); } @@ -829,9 +828,11 @@ class Nag return PEAR::raiseError('Unknown event action: ' . $action); } - $share = $GLOBALS['nag_shares']->getShare($task->tasklist); - if (is_a($share, 'PEAR_Error')) { - return $share; + try { + $share = $GLOBALS['nag_shares']->getShare($task->tasklist); + } catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Nag_Exception($e); } require_once 'Horde/Group.php'; @@ -937,15 +938,14 @@ class Nag } if ($old_task->parent_id != $task->parent_id) { $old_parent = $old_task->getParent(); - if (!is_a($old_parent, 'PEAR_Error')) { - $parent = $task->getParent(); - if (!is_a($parent, 'PEAR_Error')) { - $notification_message .= "\n - " - . sprintf(_("Changed parent task from \"%s\" to \"%s\""), - $old_parent ? $old_parent->name : _("no parent"), - $parent ? $parent->name : _("no parent")); - } + $parent = $task->getParent(); + if (!is_a($parent, 'PEAR_Error')) { + $notification_message .= "\n - " + . sprintf(_("Changed parent task from \"%s\" to \"%s\""), + $old_parent ? $old_parent->name : _("no parent"), + $parent ? $parent->name : _("no parent")); } + } if ($old_task->category != $task->category) { $notification_message .= "\n - " @@ -1389,10 +1389,10 @@ class Nag $aowner = $a->tasklist; $bowner = $b->tasklist; - if (!is_a($ashare, 'PEAR_Error') && $aowner != $ashare->get('owner')) { + if ($aowner != $ashare->get('owner')) { $aowner = $ashare->get('name'); } - if (!is_a($bshare, 'PEAR_Error') && $bowner != $bshare->get('owner')) { + if ($bowner != $bshare->get('owner')) { $bowner = $bshare->get('name'); } @@ -1421,10 +1421,10 @@ class Nag $aowner = $a->tasklist; $bowner = $b->tasklist; - if (!is_a($ashare, 'PEAR_Error') && $aowner != $ashare->get('owner')) { + if ($aowner != $ashare->get('owner')) { $aowner = $ashare->get('name'); } - if (!is_a($bshare, 'PEAR_Error') && $bowner != $bshare->get('owner')) { + if ($bowner != $bshare->get('owner')) { $bowner = $bshare->get('name'); } diff --git a/nag/lib/Task.php b/nag/lib/Task.php index ebc4a4411..ee2a25dab 100644 --- a/nag/lib/Task.php +++ b/nag/lib/Task.php @@ -705,9 +705,11 @@ class Nag_Task { $json->m = $this->methods; //$json->pv = (boolean)$this->private; - $share = $GLOBALS['nag_shares']->getShare($this->tasklist); - if (is_a($share, 'PEAR_Error')) { - return $share; + try { + $share = $GLOBALS['nag_shares']->getShare($this->tasklist); + } catch (Horde_Share_exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Nag_Exception($e); } $json->pe = $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT); $json->pd = $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE); diff --git a/nag/task.php b/nag/task.php index 02abbe0b4..9a9149035 100644 --- a/nag/task.php +++ b/nag/task.php @@ -13,29 +13,30 @@ function _delete($task_id, $tasklist_id) { if (!empty($task_id)) { $task = Nag::getTask($tasklist_id, $task_id); - if (is_a($task, 'PEAR_Error')) { + if ($task instanceof PEAR_Error) { $GLOBALS['notification']->push( sprintf(_("Error deleting task: %s"), $task->getMessage()), 'horde.error'); } else { - $share = $GLOBALS['nag_shares']->getShare($tasklist_id); - if (is_a($share, 'PEAR_Error') || - !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { - $GLOBALS['notification']->push( - _("Access denied deleting task."), 'horde.error'); + try { + $share = $GLOBALS['nag_shares']->getShare($tasklist_id); + } catch (Horde_Share_Exception $e) { + throw new Nag_Exception($e); + } + if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { + $GLOBALS['notification']->push(_("Access denied deleting task."), 'horde.error'); } else { $storage = Nag_Driver::singleton($tasklist_id); - $result = $storage->delete($task_id); - if (is_a($result, 'PEAR_Error')) { + try { + $storage->delete($task_id); + } catch (Horde_Share_Exception $e) { $GLOBALS['notification']->push( sprintf(_("There was a problem deleting %s: %s"), - $task->name, $result->getMessage()), + $task->name, $e->getMessage()), 'horde.error'); - } else { - $GLOBALS['notification']->push(sprintf(_("Deleted %s."), - $task->name), - 'horde.success'); } + $GLOBALS['notification']->push(sprintf(_("Deleted %s."), $task->name), + 'horde.success'); } } } @@ -85,10 +86,12 @@ case 'add_task': case 'modify_task': $task_id = $vars->get('task'); $tasklist_id = $vars->get('tasklist'); - $share = $GLOBALS['nag_shares']->getShare($tasklist_id); - if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("Access denied editing task: %s"), $share->getMessage()), 'horde.error'); - } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + try { + $share = $GLOBALS['nag_shares']->getShare($tasklist_id);s + } catch (Horde_Share_Exception $e) { + $notification->push(sprintf(_("Access denied editing task: %s"), $e->getMessage()), 'horde.error'); + } + if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { $notification->push(_("Access denied editing task."), 'horde.error'); } else { $task = Nag::getTask($tasklist_id, $task_id); @@ -124,12 +127,14 @@ case 'save_task': count(Nag::listTasklists(false, Horde_Perms::EDIT)) <= 1) { $info['tasklist_id'] = $info['old_tasklist'] = Nag::getDefaultTasklist(Horde_Perms::EDIT); } - $share = $GLOBALS['nag_shares']->getShare($info['tasklist_id']); - if (is_a($share, 'PEAR_Error')) { - $notification->push(sprintf(_("Access denied saving task: %s"), $share->getMessage()), 'horde.error'); + try { + $share = $GLOBALS['nag_shares']->getShare($info['tasklist_id']); + } catch (Horde_Share_Exception $e) { + $notification->push(sprintf(_("Access denied saving task: %s"), $e->getMessage()), 'horde.error'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit; - } elseif (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + } + if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { $notification->push(sprintf(_("Access denied saving task to %s."), $share->get('name')), 'horde.error'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit; @@ -178,7 +183,7 @@ case 'save_task': } /* Check our results. */ - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { $notification->push(sprintf(_("There was a problem saving the task: %s."), $result->getMessage()), 'horde.error'); } else { $notification->push(sprintf(_("Saved %s."), $info['name']), 'horde.success'); @@ -201,7 +206,7 @@ case 'complete_task': if (isset($task_id)) { $share = $GLOBALS['nag_shares']->getShare($tasklist_id); $task = Nag::getTask($tasklist_id, $task_id); - if (is_a($share, 'PEAR_Error') || !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { $notification->push(sprintf(_("Access denied completing task %s."), $task->name), 'horde.error'); } else { $task->completed = !$task->completed; @@ -211,7 +216,7 @@ case 'complete_task': $task->completed_date = null; } $result = $task->save(); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { $notification->push(sprintf(_("There was a problem completing %s: %s"), $task->name, $result->getMessage()), 'horde.error'); } else { diff --git a/nag/tasklists/delete.php b/nag/tasklists/delete.php index 3f31243fa..b3ccb0ea1 100644 --- a/nag/tasklists/delete.php +++ b/nag/tasklists/delete.php @@ -24,13 +24,15 @@ if ($tasklist_id == Horde_Auth::getAuth()) { header('Location: ' . Horde::applicationUrl('tasklists/', true)); exit; } -$tasklist = $nag_shares->getShare($tasklist_id); -if (is_a($tasklist, 'PEAR_Error')) { +try { + $tasklist = $nag_shares->getShare($tasklist_id); +} catch (Horde_Share_Exception $e) { $notification->push($tasklist, 'horde.error'); header('Location: ' . Horde::applicationUrl('tasklists/', true)); exit; -} elseif ($tasklist->get('owner') != Horde_Auth::getAuth() && - (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) { +} +if ($tasklist->get('owner') != Horde_Auth::getAuth() && + (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) { $notification->push(_("You are not allowed to delete this task list."), 'horde.error'); header('Location: ' . Horde::applicationUrl('tasklists/', true)); exit; @@ -41,7 +43,7 @@ $form = new Nag_DeleteTaskListForm($vars, $tasklist); // Execute if the form is valid (must pass with POST variables only). if ($form->validate(new Horde_Variables($_POST))) { $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { $notification->push($result, 'horde.error'); } elseif ($result) { $notification->push(sprintf(_("The task list \"%s\" has been deleted."), $tasklist->get('name')), 'horde.success'); diff --git a/nag/tasklists/edit.php b/nag/tasklists/edit.php index c48177288..dd264ef70 100644 --- a/nag/tasklists/edit.php +++ b/nag/tasklists/edit.php @@ -18,13 +18,15 @@ if (!Horde_Auth::getAuth()) { } $vars = Horde_Variables::getDefaultVariables(); -$tasklist = $nag_shares->getShare($vars->get('t')); -if (is_a($tasklist, 'PEAR_Error')) { - $notification->push($tasklist, 'horde.error'); +try { + $tasklist = $nag_shares->getShare($vars->get('t')); +} catch (Horde_Share_Exception $e) { + $notification->push($e->getMessage(), 'horde.error'); header('Location: ' . Horde::applicationUrl('tasklists/', true)); exit; -} elseif ($tasklist->get('owner') != Horde_Auth::getAuth() && - (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) { +} +if ($tasklist->get('owner') != Horde_Auth::getAuth() && + (!is_null($tasklist->get('owner')) || !Horde_Auth::isAdmin())) { $notification->push(_("You are not allowed to change this task list."), 'horde.error'); header('Location: ' . Horde::applicationUrl('tasklists/', true)); exit; @@ -35,7 +37,7 @@ $form = new Nag_EditTaskListForm($vars, $tasklist); if ($form->validate($vars)) { $original_name = $tasklist->get('name'); $result = $form->execute(); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { $notification->push($result, 'horde.error'); } else { if ($tasklist->get('name') != $original_name) { diff --git a/nag/tasklists/info.php b/nag/tasklists/info.php index df04acd0f..1a48d4e53 100644 --- a/nag/tasklists/info.php +++ b/nag/tasklists/info.php @@ -14,8 +14,9 @@ if (!Horde_Auth::getAuth()) { exit; } -$tasklist = $nag_shares->getShare(Horde_Util::getFormData('t')); -if (is_a($tasklist, 'PEAR_Error')) { +try { + $tasklist = $nag_shares->getShare(Horde_Util::getFormData('t')); +} catch (Horde_Share_Exception $e) { exit; } diff --git a/nag/templates/list.html.php b/nag/templates/list.html.php index 4a793be75..2cc68fb4e 100644 --- a/nag/templates/list.html.php +++ b/nag/templates/list.html.php @@ -43,8 +43,12 @@ if ($tasks->hasTasks()) { $share = $GLOBALS['nag_shares']->newShare('**EXTERNAL**'); $owner = $task->tasklist_name; } else { - $share = $GLOBALS['nag_shares']->getShare($task->tasklist); - $owner = is_a($share, 'PEAR_Error') ? $task->tasklist : $share->get('name'); + try { + $share = $GLOBALS['nag_shares']->getShare($task->tasklist); + $owner = $share->get('name'); + } catch (Horde_Share_Exception $e) { + $owner = $task->tasklist; + } } require NAG_TEMPLATES . '/list/task_summaries.inc'; diff --git a/nag/templates/list/task_summaries.inc b/nag/templates/list/task_summaries.inc index bacdbe377..97cc7be95 100644 --- a/nag/templates/list/task_summaries.inc +++ b/nag/templates/list/task_summaries.inc @@ -1,8 +1,7 @@ hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { +if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { if (!$task->completed) { if (!$task->childrenCompleted()) { $label = _("Incomplete sub tasks, complete them first"); @@ -33,8 +32,7 @@ if (!is_a($share, 'PEAR_Error') && hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT) && + if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT) && (!$task->private || $task->owner == Horde_Auth::getAuth())) { $label = sprintf(_("Edit \"%s\""), $task->name); echo Horde::link($task->edit_link, $label) . Horde::img('edit.png', $label) . ''; @@ -47,8 +45,7 @@ if (!is_a($share, 'PEAR_Error') && $task_name = strlen($task->name) ? htmlspecialchars($task->name) : _("[none]"); - if (!is_a($share, 'PEAR_Error') && - $share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { + if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { echo Horde::link($task->view_link, '', '', '', '', $task->desc) . $task_name . ''; } else { diff --git a/nag/templates/view/task.inc b/nag/templates/view/task.inc index 304ce4313..393ad38a9 100644 --- a/nag/templates/view/task.inc +++ b/nag/templates/view/task.inc @@ -41,7 +41,7 @@ - hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { if (empty($task->completed)) { echo Horde::link(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task')), _("Complete Task"), 'widget') . Horde::img('unchecked.png', _("Complete Task")) . ''; } else { diff --git a/nag/view.php b/nag/view.php index 7bc48e708..447ce0161 100644 --- a/nag/view.php +++ b/nag/view.php @@ -14,7 +14,7 @@ Horde_Registry::appInit('nag'); if ($uid = Horde_Util::getFormData('uid')) { $storage = Nag_Driver::singleton(); $task = $storage->getByUID($uid); - if (is_a($task, 'PEAR_Error')) { + if ($task instanceof PEAR_Error) { header('Location: ' . Horde::applicationUrl('list.php', true)); exit; } @@ -47,7 +47,7 @@ $task->loadChildren(); /* Check permissions on $tasklist_id. */ $share = $GLOBALS['nag_shares']->getShare($tasklist_id); -if (is_a($share, 'PEAR_Error') || !$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { +if (!$share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::READ)) { $notification->push(_("You do not have permission to view this tasklist."), 'horde.error'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit; @@ -99,21 +99,24 @@ Horde::addScriptFile('stripe.js', 'horde'); $taskurl = Horde_Util::addParameter('task.php', array('task' => $task_id, 'tasklist' => $tasklist_id)); -$share = $GLOBALS['nag_shares']->getShare($tasklist_id); - -if (!is_a($share, 'PEAR_Error')) { - if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { - if (!$task->completed) { - $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task')), _("Complete"), 'smallheader', '', '', _("_Complete")); - } - if (!$task->private || $task->owner == Horde_Auth::getAuth()) { - $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'modify_task')), _("Edit"), 'smallheader', '', '', _("_Edit")); - } +try { + $share = $GLOBALS['nag_shares']->getShare($tasklist_id); +} catch (Horde_Share_Exception $e) { + Horde::logMessage($e->getMessage(), 'ERR'); + throw new Nag_Exception($e); +} +if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) { + if (!$task->completed) { + $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'complete_task')), _("Complete"), 'smallheader', '', '', _("_Complete")); } - if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { - $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'delete_tasks')), _("Delete"), 'smallheader', '', $prefs->getValue('delete_opt') ? 'return window.confirm(\'' . addslashes(_("Really delete this task?")) . '\');' : '', _("_Delete")); + if (!$task->private || $task->owner == Horde_Auth::getAuth()) { + $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'modify_task')), _("Edit"), 'smallheader', '', '', _("_Edit")); } } +if ($share->hasPermission(Horde_Auth::getAuth(), Horde_Perms::DELETE)) { + $links[] = Horde::widget(Horde::applicationUrl(Horde_Util::addParameter($taskurl, 'actionID', 'delete_tasks')), _("Delete"), 'smallheader', '', $prefs->getValue('delete_opt') ? 'return window.confirm(\'' . addslashes(_("Really delete this task?")) . '\');' : '', _("_Delete")); +} + require NAG_TEMPLATES . '/common-header.inc'; require NAG_TEMPLATES . '/menu.inc';