Skip to content

Commit

Permalink
Don't allow deletion of tasks with sub-tasks (Bug #13809).
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Jan 16, 2015
1 parent 9ba45d3 commit 0faf58d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions nag/task.php
Expand Up @@ -11,31 +11,36 @@

function _delete($task_id, $tasklist_id)
{
global $injector, $nag_shares, $notification, $registry;

if (!empty($task_id)) {
try {
$task = Nag::getTask($tasklist_id, $task_id);
$task->loadChildren();
try {
$share = $GLOBALS['nag_shares']->getShare($tasklist_id);
$share = $nag_shares->getShare($tasklist_id);
} catch (Horde_Share_Exception $e) {
throw new Nag_Exception($e);
}
if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)) {
$GLOBALS['notification']->push(_("Access denied deleting task."), 'horde.error');
if (!$share->hasPermission($registry->getAuth(), Horde_Perms::DELETE)) {
$notification->push(_("Access denied deleting task."), 'horde.error');
} elseif ($task->hasSubTasks()) {
$notification->push(_("Sub tasks exist, delete them first"), 'horde.error');
} else {
$storage = $GLOBALS['injector']->getInstance('Nag_Factory_Driver')->create($tasklist_id);
$storage = $injector->getInstance('Nag_Factory_Driver')->create($tasklist_id);
try {
$storage->delete($task_id);
} catch (Horde_Share_Exception $e) {
$GLOBALS['notification']->push(
} catch (Nag_Exception $e) {
$notification->push(
sprintf(_("There was a problem deleting %s: %s"),
$task->name, $e->getMessage()),
'horde.error');
}
$GLOBALS['notification']->push(sprintf(_("Deleted %s."), $task->name),
$notification->push(sprintf(_("Deleted %s."), $task->name),
'horde.success');
}
} catch (Nag_Exception $e) {
$GLOBALS['notification']->push(
$notification->push(
sprintf(_("Error deleting task: %s"),
$e->getMessage()), 'horde.error');
}
Expand Down
2 changes: 1 addition & 1 deletion nag/templates/view/task.inc
Expand Up @@ -9,7 +9,7 @@
<?php endif ?>
<li class="horde-icon"><?php echo Horde::widget(array('url' => Horde::url('task.php', true)->add(array('actionID' => 'add_task', 'tasklist_id' => $task->tasklist, 'parent_task' => $task->id)), 'title' => _("Create Subtask"), 'class' => 'nag-new')) ?></li>
<?php endif ?>
<?php if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE)): ?>
<?php if ($share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE) && !$task->hasSubTasks()): ?>
<li class="horde-icon"><?php echo Horde::widget(array('url' => $taskurl->add('actionID', 'delete_task'), 'onclick' => $prefs->getValue('delete_opt') ? 'return window.confirm(\'' . addslashes(_("Really delete this task?")) . '\');' : '', 'title' => _("_Delete"), 'class' => 'nag-delete')) ?></li>
<?php endif ?>
<?php if (Horde_Util::getFormData('have_search')): ?>
Expand Down

0 comments on commit 0faf58d

Please sign in to comment.