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 | |
parent | e5c63f4ecc78e144659bf83947a19d996f60b490 (diff) |
Handle modification of external tasks
-rw-r--r-- | app/Controller/ExternalTaskCreationController.php | 4 | ||||
-rw-r--r-- | app/Controller/ExternalTaskViewController.php | 2 | ||||
-rw-r--r-- | app/Controller/TaskModificationController.php | 51 | ||||
-rw-r--r-- | app/Core/ExternalTask/ExternalTaskProviderInterface.php | 23 | ||||
-rw-r--r-- | app/Template/external_task_modification/show.php | 26 |
5 files changed, 97 insertions, 9 deletions
diff --git a/app/Controller/ExternalTaskCreationController.php b/app/Controller/ExternalTaskCreationController.php index f2afd9aa..a1985adb 100644 --- a/app/Controller/ExternalTaskCreationController.php +++ b/app/Controller/ExternalTaskCreationController.php @@ -44,7 +44,7 @@ class ExternalTaskCreationController extends BaseController if (empty($values)) { $values = $this->request->getValues(); - $externalTask = $taskProvider->retrieve($taskProvider->buildTaskUri($values)); + $externalTask = $taskProvider->fetch($taskProvider->buildTaskUri($values)); $values = $externalTask->getFormValues() + array( 'external_uri' => $externalTask->getUri(), @@ -56,7 +56,7 @@ class ExternalTaskCreationController extends BaseController 'owner_id' => $this->userSession->getId(), ); } else { - $externalTask = $taskProvider->retrieve($values['external_uri']); + $externalTask = $taskProvider->fetch($values['external_uri']); } $this->response->html($this->template->render('external_task_creation/step2', array( diff --git a/app/Controller/ExternalTaskViewController.php b/app/Controller/ExternalTaskViewController.php index 4ffc4763..18bc15c1 100644 --- a/app/Controller/ExternalTaskViewController.php +++ b/app/Controller/ExternalTaskViewController.php @@ -17,7 +17,7 @@ class ExternalTaskViewController extends BaseController try { $task = $this->getTask(); $taskProvider = $this->externalTaskManager->getProvider($task['external_provider']); - $externalTask = $taskProvider->retrieve($task['external_uri']); + $externalTask = $taskProvider->fetch($task['external_uri']); $this->response->html($this->template->render($taskProvider->getViewTemplate(), array( 'task' => $task, 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; + } } diff --git a/app/Core/ExternalTask/ExternalTaskProviderInterface.php b/app/Core/ExternalTask/ExternalTaskProviderInterface.php index 7706a773..932912d9 100644 --- a/app/Core/ExternalTask/ExternalTaskProviderInterface.php +++ b/app/Core/ExternalTask/ExternalTaskProviderInterface.php @@ -22,12 +22,22 @@ interface ExternalTaskProviderInterface * Retrieve task from external system or cache * * @access public - * @throws \Kanboard\Core\ExternalTask\AccessForbiddenException - * @throws \Kanboard\Core\ExternalTask\NotFoundException + * @throws \Kanboard\Core\ExternalTask\ExternalTaskException * @param string $uri * @return ExternalTaskInterface */ - public function retrieve($uri); + public function fetch($uri); + + /** + * Save external task to another system + * + * @throws \Kanboard\Core\ExternalTask\ExternalTaskException + * @param string $uri + * @param array $formValues + * @param array $formErrors + * @return bool + */ + public function save($uri, array $formValues, array &$formErrors); /** * Get task import template name @@ -44,6 +54,13 @@ interface ExternalTaskProviderInterface public function getCreationFormTemplate(); /** + * Get modification form template + * + * @return string + */ + public function getModificationFormTemplate(); + + /** * Get task view template name * * @return string diff --git a/app/Template/external_task_modification/show.php b/app/Template/external_task_modification/show.php new file mode 100644 index 00000000..79dd9556 --- /dev/null +++ b/app/Template/external_task_modification/show.php @@ -0,0 +1,26 @@ +<form class="popover-form" method="post" action="<?= $this->url->href('TaskModificationController', 'update', array('task_id' => $task['id'], 'project_id' => $project['id'])) ?>"> + <?= $this->form->csrf() ?> + <?= $this->form->hidden('id', $values) ?> + <?= $this->form->hidden('project_id', $values) ?> + + <?php if (! empty($error_message)): ?> + <p class="alert alert-error"><?= $this->text->e($error_message) ?></p> + <?php else: ?> + <?= $this->render($template, array( + 'project' => $project, + 'task' => $task, + 'external_task' => $external_task, + 'tags' => $tags, + 'users_list' => $users_list, + 'categories_list' => $categories_list, + 'values' => $values, + 'errors' => $errors, + )) ?> + <?php endif ?> + + <div class="form-actions"> + <button type="submit" class="btn btn-blue"><?= t('Save') ?></button> + <?= t('or') ?> + <?= $this->url->link(t('cancel'), 'TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> + </div> +</form> |