From 9d4be201aaaeaac23f4b18fb6c91caca857a2f0f Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 7 Jun 2018 15:02:10 -0700 Subject: Add quick link assign me in different views --- app/Controller/TaskModificationController.php | 39 +++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'app/Controller') diff --git a/app/Controller/TaskModificationController.php b/app/Controller/TaskModificationController.php index 07e9d932..dcf9ec2a 100644 --- a/app/Controller/TaskModificationController.php +++ b/app/Controller/TaskModificationController.php @@ -14,6 +14,19 @@ use Kanboard\Core\ExternalTask\ExternalTaskException; */ class TaskModificationController extends BaseController { + public function assignToMe() + { + $task = $this->getTask(); + $values = ['id' => $task['id'], 'owner_id' => $this->userSession->getId()]; + + if (! $this->helper->projectRole->canUpdateTask($task)) { + throw new AccessForbiddenException(t('You are not allowed to update tasks assigned to someone else.')); + } + + $this->taskModificationModel->update($values); + $this->redirectAfterQuickAction($task); + } + /** * Set the start date automatically * @@ -22,12 +35,34 @@ class TaskModificationController extends BaseController public function start() { $task = $this->getTask(); - $values = array('id' => $task['id'], 'date_started' => time()); + $values = ['id' => $task['id'], 'date_started' => time()]; + if (! $this->helper->projectRole->canUpdateTask($task)) { throw new AccessForbiddenException(t('You are not allowed to update tasks assigned to someone else.')); } + $this->taskModificationModel->update($values); - $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']))); + $this->redirectAfterQuickAction($task); + } + + protected function redirectAfterQuickAction(array $task) + { + switch ($this->request->getStringParam('redirect')) { + case 'board': + $this->response->redirect($this->helper->url->to('BoardViewController', 'show', ['project_id' => $task['project_id']])); + break; + case 'list': + $this->response->redirect($this->helper->url->to('TaskListController', 'show', ['project_id' => $task['project_id']])); + break; + case 'dashboard': + $this->response->redirect($this->helper->url->to('DashboardController', 'show', [], 'project-tasks-'.$task['project_id'])); + break; + case 'dashboard-tasks': + $this->response->redirect($this->helper->url->to('DashboardController', 'tasks', ['user_id' => $this->userSession->getId()])); + break; + default: + $this->response->redirect($this->helper->url->to('TaskViewController', 'show', ['project_id' => $task['project_id'], 'task_id' => $task['id']])); + } } /** -- cgit v1.2.3