summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-11-07 21:26:55 -0500
committerFrederic Guillot <fred@kanboard.net>2016-11-07 21:26:55 -0500
commit83f529008a77758afcdc25959637011c3b835324 (patch)
tree8c6d26030ed0e6e72e98751c7aa227ab92715ed7 /app/Controller
parente5c63f4ecc78e144659bf83947a19d996f60b490 (diff)
Handle modification of external tasks
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/ExternalTaskCreationController.php4
-rw-r--r--app/Controller/ExternalTaskViewController.php2
-rw-r--r--app/Controller/TaskModificationController.php51
3 files changed, 51 insertions, 6 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;
+ }
}