diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-11-07 21:26:55 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-11-07 21:26:55 -0500 |
commit | 83f529008a77758afcdc25959637011c3b835324 (patch) | |
tree | 8c6d26030ed0e6e72e98751c7aa227ab92715ed7 /app/Controller/TaskModificationController.php | |
parent | e5c63f4ecc78e144659bf83947a19d996f60b490 (diff) |
Handle modification of external tasks
Diffstat (limited to 'app/Controller/TaskModificationController.php')
-rw-r--r-- | app/Controller/TaskModificationController.php | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/app/Controller/TaskModificationController.php b/app/Controller/TaskModificationController.php index f628e923..520bf70e 100644 --- a/app/Controller/TaskModificationController.php +++ b/app/Controller/TaskModificationController.php @@ -2,6 +2,10 @@ namespace Kanboard\Controller; +use Kanboard\Core\Controller\AccessForbiddenException; +use Kanboard\Core\ExternalTask\AccessForbiddenException as ExternalTaskAccessForbiddenException; +use Kanboard\Core\ExternalTask\ExternalTaskException; + /** * Task Modification controller * @@ -43,7 +47,7 @@ class TaskModificationController extends BaseController $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); $values = $this->hook->merge('controller:task-modification:form:default', $values, array('default_values' => $values)); - $this->response->html($this->template->render('task_modification/show', array( + $params = array( 'project' => $project, 'values' => $values, 'errors' => $errors, @@ -51,7 +55,29 @@ class TaskModificationController extends BaseController 'tags' => $this->taskTagModel->getList($task['id']), 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($task['project_id']), 'categories_list' => $this->categoryModel->getList($task['project_id']), - ))); + ); + + $this->renderTemplate($task, $params); + } + + protected function renderTemplate(array &$task, array &$params) + { + if (empty($task['external_uri'])) { + $this->response->html($this->template->render('task_modification/show', $params)); + } else { + + try { + $taskProvider = $this->externalTaskManager->getProvider($task['external_provider']); + $params['template'] = $taskProvider->getModificationFormTemplate(); + $params['external_task'] = $taskProvider->fetch($task['external_uri']); + } catch (ExternalTaskAccessForbiddenException $e) { + throw new AccessForbiddenException($e->getMessage()); + } catch (ExternalTaskException $e) { + $params['error_message'] = $e->getMessage(); + } + + $this->response->html($this->template->render('external_task_modification/show', $params)); + } } /** @@ -66,7 +92,7 @@ class TaskModificationController extends BaseController list($valid, $errors) = $this->taskValidator->validateModification($values); - if ($valid && $this->taskModificationModel->update($values)) { + if ($valid && $this->updateTask($task, $values, $errors)) { $this->flash->success(t('Task updated successfully.')); $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); } else { @@ -74,4 +100,23 @@ class TaskModificationController extends BaseController $this->edit($values, $errors); } } + + protected function updateTask(array &$task, array &$values, array &$errors) + { + $result = $this->taskModificationModel->update($values); + + if ($result && ! empty($task['external_uri'])) { + try { + $taskProvider = $this->externalTaskManager->getProvider($task['external_provider']); + $result = $taskProvider->save($task['external_uri'], $values, $errors); + } catch (ExternalTaskAccessForbiddenException $e) { + throw new AccessForbiddenException($e->getMessage()); + } catch (ExternalTaskException $e) { + $this->logger->error($e->getMessage()); + $result = false; + } + } + + return $result; + } } |