summaryrefslogtreecommitdiff
path: root/plugins/Group_assign/Controller
diff options
context:
space:
mode:
authorDzial Techniczny WMW Projekt s.c <techniczna@wmwprojekt.pl>2019-12-10 11:34:53 +0100
committerDzial Techniczny WMW Projekt s.c <techniczna@wmwprojekt.pl>2019-12-10 11:34:53 +0100
commitb8fa0246803dab40cf57d40b45984c53046f2d55 (patch)
treedc92b167c7542137c385614a1d558e57669a4339 /plugins/Group_assign/Controller
parent2a43146236fd8fb16f84398d85720ad84aa0a0b1 (diff)
Plugins directory and local modifications
Diffstat (limited to 'plugins/Group_assign/Controller')
-rw-r--r--plugins/Group_assign/Controller/GroupAssignTaskCreationController.php175
-rw-r--r--plugins/Group_assign/Controller/GroupAssignTaskModificationController.php208
2 files changed, 383 insertions, 0 deletions
diff --git a/plugins/Group_assign/Controller/GroupAssignTaskCreationController.php b/plugins/Group_assign/Controller/GroupAssignTaskCreationController.php
new file mode 100644
index 00000000..f7dadbee
--- /dev/null
+++ b/plugins/Group_assign/Controller/GroupAssignTaskCreationController.php
@@ -0,0 +1,175 @@
+<?php
+
+namespace Kanboard\Plugin\Group_assign\Controller;
+
+use Kanboard\Plugin\Group_assign\Model\MultiselectModel;
+use Kanboard\Plugin\Group_assign\Model\MultiselectMemberModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\ColumnModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskProjectDuplicationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ColorModel;
+use Kanboard\Controller\BaseController;
+use Kanboard\Core\Controller\PageNotFoundException;
+
+
+class GroupAssignTaskCreationController extends BaseController
+{
+ /**
+ * Display a form to create a new task
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ * @throws PageNotFoundException
+ */
+ public function show(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+ $swimlanesList = $this->swimlaneModel->getList($project['id'], false, true);
+ $values += $this->prepareValues($project['is_private'], $swimlanesList);
+
+ $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values));
+ $values = $this->hook->merge('controller:task-creation:form:default', $values, array('default_values' => $values));
+
+ $this->response->html($this->template->render('task_creation/show', array(
+ 'project' => $project,
+ 'errors' => $errors,
+ 'values' => $values + array('project_id' => $project['id']),
+ 'columns_list' => $this->columnModel->getList($project['id']),
+ 'users_list' => $this->projectUserRoleModel->getAssignableUsersList($project['id'], true, false, $project['is_private'] == 1),
+ 'categories_list' => $this->categoryModel->getList($project['id']),
+ 'swimlanes_list' => $swimlanesList,
+ )));
+ }
+
+ /**
+ * Validate and save a new task
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+ $values['project_id'] = $project['id'];
+ if (isset($values['owner_ms']) && !empty($values['owner_ms'])) {
+ $ms_id = $this->multiselectModel->create();
+ foreach ($values['owner_ms'] as $user) {
+ $this->multiselectMemberModel->addUser($ms_id, $user);
+ }
+ unset($values['owner_ms']);
+ $values['owner_ms'] = $ms_id;
+ }
+
+ list($valid, $errors) = $this->taskValidator->validateCreation($values);
+
+ if (! $valid) {
+ $this->flash->failure(t('Unable to create your task.'));
+ $this->show($values, $errors);
+ } else if (! $this->helper->projectRole->canCreateTaskInColumn($project['id'], $values['column_id'])) {
+ $this->flash->failure(t('You cannot create tasks in this column.'));
+ $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])), true);
+ } else {
+ $task_id = $this->taskCreationModel->create($values);
+
+ if ($task_id > 0) {
+ $this->flash->success(t('Task created successfully.'));
+ $this->afterSave($project, $values, $task_id);
+ } else {
+ $this->flash->failure(t('Unable to create this task.'));
+ $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])), true);
+ }
+ }
+ }
+
+ /**
+ * Duplicate created tasks to multiple projects
+ *
+ * @throws PageNotFoundException
+ */
+ public function duplicateProjects()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+
+ if (isset($values['project_ids'])) {
+ foreach ($values['project_ids'] as $project_id) {
+ $this->taskProjectDuplicationModel->duplicateToProject($values['task_id'], $project_id);
+ }
+ }
+
+ $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])), true);
+ }
+
+ /**
+ * Executed after the task is saved
+ *
+ * @param array $project
+ * @param array $values
+ * @param integer $task_id
+ */
+ protected function afterSave(array $project, array &$values, $task_id)
+ {
+ if (isset($values['duplicate_multiple_projects']) && $values['duplicate_multiple_projects'] == 1) {
+ $this->chooseProjects($project, $task_id);
+ } elseif (isset($values['another_task']) && $values['another_task'] == 1) {
+ $this->show(array(
+ 'owner_id' => $values['owner_id'],
+ 'color_id' => $values['color_id'],
+ 'category_id' => isset($values['category_id']) ? $values['category_id'] : 0,
+ 'column_id' => $values['column_id'],
+ 'swimlane_id' => isset($values['swimlane_id']) ? $values['swimlane_id'] : 0,
+ 'another_task' => 1,
+ ));
+ } else {
+ $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])), true);
+ }
+ }
+
+ /**
+ * Prepare form values
+ *
+ * @access protected
+ * @param bool $isPrivateProject
+ * @param array $swimlanesList
+ * @return array
+ */
+ protected function prepareValues($isPrivateProject, array $swimlanesList)
+ {
+ $values = array(
+ 'swimlane_id' => $this->request->getIntegerParam('swimlane_id', key($swimlanesList)),
+ 'column_id' => $this->request->getIntegerParam('column_id'),
+ 'color_id' => $this->colorModel->getDefaultColor(),
+ );
+
+ if ($isPrivateProject) {
+ $values['owner_id'] = $this->userSession->getId();
+ }
+
+ return $values;
+ }
+
+ /**
+ * Choose projects
+ *
+ * @param array $project
+ * @param integer $task_id
+ */
+ protected function chooseProjects(array $project, $task_id)
+ {
+ $task = $this->taskFinderModel->getById($task_id);
+ $projects = $this->projectUserRoleModel->getActiveProjectsByUser($this->userSession->getId());
+ unset($projects[$project['id']]);
+
+ $this->response->html($this->template->render('task_creation/duplicate_projects', array(
+ 'project' => $project,
+ 'task' => $task,
+ 'projects_list' => $projects,
+ 'values' => array('task_id' => $task['id'])
+ )));
+ }
+}
diff --git a/plugins/Group_assign/Controller/GroupAssignTaskModificationController.php b/plugins/Group_assign/Controller/GroupAssignTaskModificationController.php
new file mode 100644
index 00000000..b975c3d9
--- /dev/null
+++ b/plugins/Group_assign/Controller/GroupAssignTaskModificationController.php
@@ -0,0 +1,208 @@
+<?php
+
+namespace Kanboard\Plugin\Group_assign\Controller;
+
+use Kanboard\Plugin\Group_assign\Model\MultiselectModel;
+use Kanboard\Plugin\Group_assign\Model\MultiselectMemberModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\ColumnModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskProjectDuplicationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ColorModel;
+use Kanboard\Controller\BaseController;
+use Kanboard\Core\Controller\PageNotFoundException;
+
+
+/**
+ * Group Assign Task Modification controller
+ *
+ * @package Kanboard\Plugin\Group_assign\
+ * @author Craig Crosby
+ */
+class GroupAssignTaskModificationController 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
+ *
+ * @access public
+ */
+ public function start()
+ {
+ $task = $this->getTask();
+ $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->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']]));
+ }
+ }
+
+ /**
+ * Display a form to edit a task
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ * @throws \Kanboard\Core\Controller\AccessForbiddenException
+ * @throws \Kanboard\Core\Controller\PageNotFoundException
+ */
+ public function edit(array $values = array(), array $errors = array())
+ {
+ $task = $this->getTask();
+
+ if (! $this->helper->projectRole->canUpdateTask($task)) {
+ throw new AccessForbiddenException(t('You are not allowed to update tasks assigned to someone else.'));
+ }
+
+ $project = $this->projectModel->getById($task['project_id']);
+
+ if (empty($values)) {
+ $values = $task;
+ }
+
+ $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));
+
+ $params = array(
+ 'project' => $project,
+ 'values' => $values,
+ 'errors' => $errors,
+ 'task' => $task,
+ '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));
+ }
+ }
+
+ /**
+ * Validate and update a task
+ *
+ * @access public
+ */
+ public function update()
+ {
+ $previousMembers = array();
+ $task = $this->getTask();
+ $values = $this->request->getValues();
+ $values['id'] = $task['id'];
+ $values['project_id'] = $task['project_id'];
+ if (isset($values['owner_ms']) && !empty($values['owner_ms'])) {
+ if (!empty($task['owner_ms'])) {
+ $ms_id = $task['owner_ms'];
+ $previousMembers = $this->multiselectMemberModel->getMembers($ms_id);
+ $this->multiselectMemberModel->removeAllUsers($ms_id);
+ } else {
+ $ms_id = $this->multiselectModel->create();
+ }
+ foreach ($values['owner_ms'] as $user) {
+ if ($user !== 0) { $this->multiselectMemberModel->addUser($ms_id, $user); }
+ }
+ unset($values['owner_ms']);
+ $values['owner_ms'] = $ms_id;
+
+ $newMembersSet = $this->multiselectMemberModel->getMembers($values['owner_ms']);
+ if (sort($previousMembers) !== sort($newMembersSet)) { $this->multiselectMemberModel->assigneeChanged($task, $values); }
+
+ if ($values['owner_gp'] !== $task['owner_gp']) { $this->multiselectMemberModel->assigneeChanged($task, $values); }
+ } else {
+ $this->multiselectMemberModel->removeAllUsers($task['owner_ms']);
+ }
+
+ list($valid, $errors) = $this->taskValidator->validateModification($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 {
+ $this->flash->failure(t('Unable to update your task.'));
+ $this->edit($values, $errors);
+ }
+ }
+
+ protected function updateTask(array &$task, array &$values, array &$errors)
+ {
+ if (isset($values['owner_id']) && $values['owner_id'] != $task['owner_id'] && !$this->helper->projectRole->canChangeAssignee($task)) {
+ throw new AccessForbiddenException(t('You are not allowed to change the assignee.'));
+ }
+
+ if (! $this->helper->projectRole->canUpdateTask($task)) {
+ throw new AccessForbiddenException(t('You are not allowed to update tasks assigned to someone else.'));
+ }
+
+ $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;
+ }
+}