From 4a230d331ec220fc32a48525afb308af0d9787fa Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 10:25:13 -0400 Subject: Added application and project roles validation for API procedure calls --- app/Api/Procedure/ActionProcedure.php | 91 +++++++++++ app/Api/Procedure/AppProcedure.php | 47 ++++++ app/Api/Procedure/BaseProcedure.php | 86 +++++++++++ app/Api/Procedure/BoardProcedure.php | 25 +++ app/Api/Procedure/CategoryProcedure.php | 59 ++++++++ app/Api/Procedure/ColumnProcedure.php | 51 +++++++ app/Api/Procedure/CommentProcedure.php | 62 ++++++++ app/Api/Procedure/GroupMemberProcedure.php | 37 +++++ app/Api/Procedure/GroupProcedure.php | 49 ++++++ app/Api/Procedure/LinkProcedure.php | 111 ++++++++++++++ app/Api/Procedure/MeProcedure.php | 72 +++++++++ app/Api/Procedure/ProjectPermissionProcedure.php | 69 +++++++++ app/Api/Procedure/ProjectProcedure.php | 106 +++++++++++++ app/Api/Procedure/SubtaskProcedure.php | 74 +++++++++ app/Api/Procedure/SubtaskTimeTrackingProcedure.php | 39 +++++ app/Api/Procedure/SwimlaneProcedure.php | 91 +++++++++++ app/Api/Procedure/TaskFileProcedure.php | 70 +++++++++ app/Api/Procedure/TaskLinkProcedure.php | 85 +++++++++++ app/Api/Procedure/TaskProcedure.php | 167 +++++++++++++++++++++ app/Api/Procedure/UserProcedure.php | 131 ++++++++++++++++ 20 files changed, 1522 insertions(+) create mode 100644 app/Api/Procedure/ActionProcedure.php create mode 100644 app/Api/Procedure/AppProcedure.php create mode 100644 app/Api/Procedure/BaseProcedure.php create mode 100644 app/Api/Procedure/BoardProcedure.php create mode 100644 app/Api/Procedure/CategoryProcedure.php create mode 100644 app/Api/Procedure/ColumnProcedure.php create mode 100644 app/Api/Procedure/CommentProcedure.php create mode 100644 app/Api/Procedure/GroupMemberProcedure.php create mode 100644 app/Api/Procedure/GroupProcedure.php create mode 100644 app/Api/Procedure/LinkProcedure.php create mode 100644 app/Api/Procedure/MeProcedure.php create mode 100644 app/Api/Procedure/ProjectPermissionProcedure.php create mode 100644 app/Api/Procedure/ProjectProcedure.php create mode 100644 app/Api/Procedure/SubtaskProcedure.php create mode 100644 app/Api/Procedure/SubtaskTimeTrackingProcedure.php create mode 100644 app/Api/Procedure/SwimlaneProcedure.php create mode 100644 app/Api/Procedure/TaskFileProcedure.php create mode 100644 app/Api/Procedure/TaskLinkProcedure.php create mode 100644 app/Api/Procedure/TaskProcedure.php create mode 100644 app/Api/Procedure/UserProcedure.php (limited to 'app/Api/Procedure') diff --git a/app/Api/Procedure/ActionProcedure.php b/app/Api/Procedure/ActionProcedure.php new file mode 100644 index 00000000..4043dbb9 --- /dev/null +++ b/app/Api/Procedure/ActionProcedure.php @@ -0,0 +1,91 @@ +actionManager->getAvailableActions(); + } + + public function getAvailableActionEvents() + { + return $this->eventManager->getAll(); + } + + public function getCompatibleActionEvents($action_name) + { + return $this->actionManager->getCompatibleEvents($action_name); + } + + public function removeAction($action_id) + { + ActionAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeAction', $action_id); + return $this->actionModel->remove($action_id); + } + + public function getActions($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getActions', $project_id); + return $this->actionModel->getAllByProject($project_id); + } + + public function createAction($project_id, $event_name, $action_name, array $params) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createAction', $project_id); + $values = array( + 'project_id' => $project_id, + 'event_name' => $event_name, + 'action_name' => $action_name, + 'params' => $params, + ); + + list($valid, ) = $this->actionValidator->validateCreation($values); + + if (! $valid) { + return false; + } + + // Check if the action exists + $actions = $this->actionManager->getAvailableActions(); + + if (! isset($actions[$action_name])) { + return false; + } + + // Check the event + $action = $this->actionManager->getAction($action_name); + + if (! in_array($event_name, $action->getEvents())) { + return false; + } + + $required_params = $action->getActionRequiredParameters(); + + // Check missing parameters + foreach ($required_params as $param => $value) { + if (! isset($params[$param])) { + return false; + } + } + + // Check extra parameters + foreach ($params as $param => $value) { + if (! isset($required_params[$param])) { + return false; + } + } + + return $this->actionModel->create($values); + } +} diff --git a/app/Api/Procedure/AppProcedure.php b/app/Api/Procedure/AppProcedure.php new file mode 100644 index 00000000..60af4a60 --- /dev/null +++ b/app/Api/Procedure/AppProcedure.php @@ -0,0 +1,47 @@ +timezoneModel->getCurrentTimezone(); + } + + public function getVersion() + { + return APP_VERSION; + } + + public function getDefaultTaskColor() + { + return $this->colorModel->getDefaultColor(); + } + + public function getDefaultTaskColors() + { + return $this->colorModel->getDefaultColors(); + } + + public function getColorList() + { + return $this->colorModel->getList(); + } + + public function getApplicationRoles() + { + return $this->role->getApplicationRoles(); + } + + public function getProjectRoles() + { + return $this->role->getProjectRoles(); + } +} diff --git a/app/Api/Procedure/BaseProcedure.php b/app/Api/Procedure/BaseProcedure.php new file mode 100644 index 00000000..0aa43428 --- /dev/null +++ b/app/Api/Procedure/BaseProcedure.php @@ -0,0 +1,86 @@ +container)->check($procedure); + UserAuthorization::getInstance($this->container)->check($this->getClassName(), $procedure); + } + + protected function formatTask($task) + { + if (! empty($task)) { + $task['url'] = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true); + $task['color'] = $this->colorModel->getColorProperties($task['color_id']); + } + + return $task; + } + + protected function formatTasks($tasks) + { + if (! empty($tasks)) { + foreach ($tasks as &$task) { + $task = $this->formatTask($task); + } + } + + return $tasks; + } + + protected function formatProject($project) + { + if (! empty($project)) { + $project['url'] = array( + 'board' => $this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id']), '', true), + 'calendar' => $this->helper->url->to('CalendarController', 'show', array('project_id' => $project['id']), '', true), + 'list' => $this->helper->url->to('TaskListController', 'show', array('project_id' => $project['id']), '', true), + ); + } + + return $project; + } + + protected function formatProjects($projects) + { + if (! empty($projects)) { + foreach ($projects as &$project) { + $project = $this->formatProject($project); + } + } + + return $projects; + } + + protected function filterValues(array $values) + { + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + return $values; + } + + protected function getClassName() + { + $reflection = new ReflectionClass(get_called_class()); + return $reflection->getShortName(); + } +} diff --git a/app/Api/Procedure/BoardProcedure.php b/app/Api/Procedure/BoardProcedure.php new file mode 100644 index 00000000..674b5466 --- /dev/null +++ b/app/Api/Procedure/BoardProcedure.php @@ -0,0 +1,25 @@ +container)->check($this->getClassName(), 'getBoard', $project_id); + + return BoardFormatter::getInstance($this->container) + ->withProjectId($project_id) + ->withQuery($this->taskFinderModel->getExtendedQuery()) + ->format(); + } +} diff --git a/app/Api/Procedure/CategoryProcedure.php b/app/Api/Procedure/CategoryProcedure.php new file mode 100644 index 00000000..3ebbd908 --- /dev/null +++ b/app/Api/Procedure/CategoryProcedure.php @@ -0,0 +1,59 @@ +container)->check($this->getClassName(), 'getCategory', $category_id); + return $this->categoryModel->getById($category_id); + } + + public function getAllCategories($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllCategories', $project_id); + return $this->categoryModel->getAll($project_id); + } + + public function removeCategory($category_id) + { + CategoryAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeCategory', $category_id); + return $this->categoryModel->remove($category_id); + } + + public function createCategory($project_id, $name) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createCategory', $project_id); + + $values = array( + 'project_id' => $project_id, + 'name' => $name, + ); + + list($valid, ) = $this->categoryValidator->validateCreation($values); + return $valid ? $this->categoryModel->create($values) : false; + } + + public function updateCategory($id, $name) + { + CategoryAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateCategory', $id); + + $values = array( + 'id' => $id, + 'name' => $name, + ); + + list($valid, ) = $this->categoryValidator->validateModification($values); + return $valid && $this->categoryModel->update($values); + } +} diff --git a/app/Api/Procedure/ColumnProcedure.php b/app/Api/Procedure/ColumnProcedure.php new file mode 100644 index 00000000..ab9d173b --- /dev/null +++ b/app/Api/Procedure/ColumnProcedure.php @@ -0,0 +1,51 @@ +container)->check($this->getClassName(), 'getColumns', $project_id); + return $this->columnModel->getAll($project_id); + } + + public function getColumn($column_id) + { + ColumnAuthorization::getInstance($this->container)->check($this->getClassName(), 'getColumn', $column_id); + return $this->columnModel->getById($column_id); + } + + public function updateColumn($column_id, $title, $task_limit = 0, $description = '') + { + ColumnAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateColumn', $column_id); + return $this->columnModel->update($column_id, $title, $task_limit, $description); + } + + public function addColumn($project_id, $title, $task_limit = 0, $description = '') + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addColumn', $project_id); + return $this->columnModel->create($project_id, $title, $task_limit, $description); + } + + public function removeColumn($column_id) + { + ColumnAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeColumn', $column_id); + return $this->columnModel->remove($column_id); + } + + public function changeColumnPosition($project_id, $column_id, $position) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeColumnPosition', $project_id); + return $this->columnModel->changePosition($project_id, $column_id, $position); + } +} diff --git a/app/Api/Procedure/CommentProcedure.php b/app/Api/Procedure/CommentProcedure.php new file mode 100644 index 00000000..019a49bb --- /dev/null +++ b/app/Api/Procedure/CommentProcedure.php @@ -0,0 +1,62 @@ +container)->check($this->getClassName(), 'getComment', $comment_id); + return $this->commentModel->getById($comment_id); + } + + public function getAllComments($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllComments', $task_id); + return $this->commentModel->getAll($task_id); + } + + public function removeComment($comment_id) + { + CommentAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeComment', $comment_id); + return $this->commentModel->remove($comment_id); + } + + public function createComment($task_id, $user_id, $content, $reference = '') + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createComment', $task_id); + + $values = array( + 'task_id' => $task_id, + 'user_id' => $user_id, + 'comment' => $content, + 'reference' => $reference, + ); + + list($valid, ) = $this->commentValidator->validateCreation($values); + + return $valid ? $this->commentModel->create($values) : false; + } + + public function updateComment($id, $content) + { + CommentAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateComment', $id); + + $values = array( + 'id' => $id, + 'comment' => $content, + ); + + list($valid, ) = $this->commentValidator->validateModification($values); + return $valid && $this->commentModel->update($values); + } +} diff --git a/app/Api/Procedure/GroupMemberProcedure.php b/app/Api/Procedure/GroupMemberProcedure.php new file mode 100644 index 00000000..081d6ac8 --- /dev/null +++ b/app/Api/Procedure/GroupMemberProcedure.php @@ -0,0 +1,37 @@ +groupMemberModel->getGroups($user_id); + } + + public function getGroupMembers($group_id) + { + return $this->groupMemberModel->getMembers($group_id); + } + + public function addGroupMember($group_id, $user_id) + { + return $this->groupMemberModel->addUser($group_id, $user_id); + } + + public function removeGroupMember($group_id, $user_id) + { + return $this->groupMemberModel->removeUser($group_id, $user_id); + } + + public function isGroupMember($group_id, $user_id) + { + return $this->groupMemberModel->isMember($group_id, $user_id); + } +} diff --git a/app/Api/Procedure/GroupProcedure.php b/app/Api/Procedure/GroupProcedure.php new file mode 100644 index 00000000..804940a2 --- /dev/null +++ b/app/Api/Procedure/GroupProcedure.php @@ -0,0 +1,49 @@ +groupModel->create($name, $external_id); + } + + public function updateGroup($group_id, $name = null, $external_id = null) + { + $values = array( + 'id' => $group_id, + 'name' => $name, + 'external_id' => $external_id, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + return $this->groupModel->update($values); + } + + public function removeGroup($group_id) + { + return $this->groupModel->remove($group_id); + } + + public function getGroup($group_id) + { + return $this->groupModel->getById($group_id); + } + + public function getAllGroups() + { + return $this->groupModel->getAll(); + } +} diff --git a/app/Api/Procedure/LinkProcedure.php b/app/Api/Procedure/LinkProcedure.php new file mode 100644 index 00000000..b4cecf3a --- /dev/null +++ b/app/Api/Procedure/LinkProcedure.php @@ -0,0 +1,111 @@ +linkModel->getById($link_id); + } + + /** + * Get a link by name + * + * @access public + * @param string $label + * @return array + */ + public function getLinkByLabel($label) + { + return $this->linkModel->getByLabel($label); + } + + /** + * Get the opposite link id + * + * @access public + * @param integer $link_id Link id + * @return integer + */ + public function getOppositeLinkId($link_id) + { + return $this->linkModel->getOppositeLinkId($link_id); + } + + /** + * Get all links + * + * @access public + * @return array + */ + public function getAllLinks() + { + return $this->linkModel->getAll(); + } + + /** + * Create a new link label + * + * @access public + * @param string $label + * @param string $opposite_label + * @return boolean|integer + */ + public function createLink($label, $opposite_label = '') + { + $values = array( + 'label' => $label, + 'opposite_label' => $opposite_label, + ); + + list($valid, ) = $this->linkValidator->validateCreation($values); + return $valid ? $this->linkModel->create($label, $opposite_label) : false; + } + + /** + * Update a link + * + * @access public + * @param integer $link_id + * @param integer $opposite_link_id + * @param string $label + * @return boolean + */ + public function updateLink($link_id, $opposite_link_id, $label) + { + $values = array( + 'id' => $link_id, + 'opposite_id' => $opposite_link_id, + 'label' => $label, + ); + + list($valid, ) = $this->linkValidator->validateModification($values); + return $valid && $this->linkModel->update($values); + } + + /** + * Remove a link a the relation to its opposite + * + * @access public + * @param integer $link_id + * @return boolean + */ + public function removeLink($link_id) + { + return $this->linkModel->remove($link_id); + } +} diff --git a/app/Api/Procedure/MeProcedure.php b/app/Api/Procedure/MeProcedure.php new file mode 100644 index 00000000..e59e6522 --- /dev/null +++ b/app/Api/Procedure/MeProcedure.php @@ -0,0 +1,72 @@ +sessionStorage->user; + } + + public function getMyDashboard() + { + $user_id = $this->userSession->getId(); + $projects = $this->projectModel->getQueryColumnStats($this->projectPermissionModel->getActiveProjectIds($user_id))->findAll(); + $tasks = $this->taskFinderModel->getUserQuery($user_id)->findAll(); + + return array( + 'projects' => $this->formatProjects($projects), + 'tasks' => $this->formatTasks($tasks), + 'subtasks' => $this->subtaskModel->getUserQuery($user_id, array(SubtaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))->findAll(), + ); + } + + public function getMyActivityStream() + { + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); + return $this->helper->projectActivity->getProjectsEvents($project_ids, 100); + } + + public function createMyPrivateProject($name, $description = null) + { + if ($this->configModel->get('disable_private_project', 0) == 1) { + return false; + } + + $values = array( + 'name' => $name, + 'description' => $description, + 'is_private' => 1, + ); + + list($valid, ) = $this->projectValidator->validateCreation($values); + return $valid ? $this->projectModel->create($values, $this->userSession->getId(), true) : false; + } + + public function getMyProjectsList() + { + return $this->projectUserRoleModel->getProjectsByUser($this->userSession->getId()); + } + + public function getMyOverdueTasks() + { + return $this->taskFinderModel->getOverdueTasksByUser($this->userSession->getId()); + } + + public function getMyProjects() + { + $project_ids = $this->projectPermissionModel->getActiveProjectIds($this->userSession->getId()); + $projects = $this->projectModel->getAllByIds($project_ids); + + return $this->formatProjects($projects); + } +} diff --git a/app/Api/Procedure/ProjectPermissionProcedure.php b/app/Api/Procedure/ProjectPermissionProcedure.php new file mode 100644 index 00000000..e22e1d62 --- /dev/null +++ b/app/Api/Procedure/ProjectPermissionProcedure.php @@ -0,0 +1,69 @@ +container)->check($this->getClassName(), 'getProjectUsers', $project_id); + return $this->projectUserRoleModel->getAllUsers($project_id); + } + + public function getAssignableUsers($project_id, $prepend_unassigned = false) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAssignableUsers', $project_id); + return $this->projectUserRoleModel->getAssignableUsersList($project_id, $prepend_unassigned); + } + + public function addProjectUser($project_id, $user_id, $role = Role::PROJECT_MEMBER) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addProjectUser', $project_id); + return $this->projectUserRoleModel->addUser($project_id, $user_id, $role); + } + + public function addProjectGroup($project_id, $group_id, $role = Role::PROJECT_MEMBER) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addProjectGroup', $project_id); + return $this->projectGroupRoleModel->addGroup($project_id, $group_id, $role); + } + + public function removeProjectUser($project_id, $user_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProjectUser', $project_id); + return $this->projectUserRoleModel->removeUser($project_id, $user_id); + } + + public function removeProjectGroup($project_id, $group_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProjectGroup', $project_id); + return $this->projectGroupRoleModel->removeGroup($project_id, $group_id); + } + + public function changeProjectUserRole($project_id, $user_id, $role) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeProjectUserRole', $project_id); + return $this->projectUserRoleModel->changeUserRole($project_id, $user_id, $role); + } + + public function changeProjectGroupRole($project_id, $group_id, $role) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeProjectGroupRole', $project_id); + return $this->projectGroupRoleModel->changeGroupRole($project_id, $group_id, $role); + } + + public function getProjectUserRole($project_id, $user_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectUserRole', $project_id); + return $this->projectUserRoleModel->getUserRole($project_id, $user_id); + } +} diff --git a/app/Api/Procedure/ProjectProcedure.php b/app/Api/Procedure/ProjectProcedure.php new file mode 100644 index 00000000..9187f221 --- /dev/null +++ b/app/Api/Procedure/ProjectProcedure.php @@ -0,0 +1,106 @@ +container)->check($this->getClassName(), 'getProjectById', $project_id); + return $this->formatProject($this->projectModel->getById($project_id)); + } + + public function getProjectByName($name) + { + $project = $this->projectModel->getByName($name); + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByName', $project['id']); + return $this->formatProject($project); + } + + public function getAllProjects() + { + return $this->formatProjects($this->projectModel->getAll()); + } + + public function removeProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProject', $project_id); + return $this->projectModel->remove($project_id); + } + + public function enableProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableProject', $project_id); + return $this->projectModel->enable($project_id); + } + + public function disableProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableProject', $project_id); + return $this->projectModel->disable($project_id); + } + + public function enableProjectPublicAccess($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableProjectPublicAccess', $project_id); + return $this->projectModel->enablePublicAccess($project_id); + } + + public function disableProjectPublicAccess($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableProjectPublicAccess', $project_id); + return $this->projectModel->disablePublicAccess($project_id); + } + + public function getProjectActivities(array $project_ids) + { + foreach ($project_ids as $project_id) { + ProjectAuthorization::getInstance($this->container) + ->check($this->getClassName(), 'getProjectActivities', $project_id); + } + + return $this->helper->projectActivity->getProjectsEvents($project_ids); + } + + public function getProjectActivity($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectActivity', $project_id); + return $this->helper->projectActivity->getProjectEvents($project_id); + } + + public function createProject($name, $description = null, $owner_id = 0, $identifier = null) + { + $values = array( + 'name' => $name, + 'description' => $description, + 'identifier' => $identifier, + ); + + list($valid, ) = $this->projectValidator->validateCreation($values); + return $valid ? $this->projectModel->create($values, $owner_id, $this->userSession->isLogged()) : false; + } + + public function updateProject($project_id, $name, $description = null, $owner_id = null, $identifier = null) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateProject', $project_id); + + $values = $this->filterValues(array( + 'id' => $project_id, + 'name' => $name, + 'description' => $description, + 'owner_id' => $owner_id, + 'identifier' => $identifier, + )); + + list($valid, ) = $this->projectValidator->validateModification($values); + return $valid && $this->projectModel->update($values); + } +} diff --git a/app/Api/Procedure/SubtaskProcedure.php b/app/Api/Procedure/SubtaskProcedure.php new file mode 100644 index 00000000..e2400912 --- /dev/null +++ b/app/Api/Procedure/SubtaskProcedure.php @@ -0,0 +1,74 @@ +container)->check($this->getClassName(), 'getSubtask', $subtask_id); + return $this->subtaskModel->getById($subtask_id); + } + + public function getAllSubtasks($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllSubtasks', $task_id); + return $this->subtaskModel->getAll($task_id); + } + + public function removeSubtask($subtask_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeSubtask', $subtask_id); + return $this->subtaskModel->remove($subtask_id); + } + + public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createSubtask', $task_id); + + $values = array( + 'title' => $title, + 'task_id' => $task_id, + 'user_id' => $user_id, + 'time_estimated' => $time_estimated, + 'time_spent' => $time_spent, + 'status' => $status, + ); + + list($valid, ) = $this->subtaskValidator->validateCreation($values); + return $valid ? $this->subtaskModel->create($values) : false; + } + + public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateSubtask', $task_id); + + $values = array( + 'id' => $id, + 'task_id' => $task_id, + 'title' => $title, + 'user_id' => $user_id, + 'time_estimated' => $time_estimated, + 'time_spent' => $time_spent, + 'status' => $status, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + list($valid, ) = $this->subtaskValidator->validateApiModification($values); + return $valid && $this->subtaskModel->update($values); + } +} diff --git a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php new file mode 100644 index 00000000..5d1988d6 --- /dev/null +++ b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php @@ -0,0 +1,39 @@ +container)->check($this->getClassName(), 'hasSubtaskTimer', $subtask_id); + return $this->subtaskTimeTrackingModel->hasTimer($subtask_id, $user_id); + } + + public function logSubtaskStartTime($subtask_id, $user_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskStartTime', $subtask_id); + return $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $user_id); + } + + public function logSubtaskEndTime($subtask_id,$user_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskEndTime', $subtask_id); + return $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $user_id); + } + + public function getSubtaskTimeSpent($subtask_id,$user_id) + { + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSubtaskTimeSpent', $subtask_id); + return $this->subtaskTimeTrackingModel->getTimeSpent($subtask_id, $user_id); + } +} diff --git a/app/Api/Procedure/SwimlaneProcedure.php b/app/Api/Procedure/SwimlaneProcedure.php new file mode 100644 index 00000000..9b7d181d --- /dev/null +++ b/app/Api/Procedure/SwimlaneProcedure.php @@ -0,0 +1,91 @@ +container)->check($this->getClassName(), 'getActiveSwimlanes', $project_id); + return $this->swimlaneModel->getSwimlanes($project_id); + } + + public function getAllSwimlanes($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllSwimlanes', $project_id); + return $this->swimlaneModel->getAll($project_id); + } + + public function getSwimlaneById($swimlane_id) + { + $swimlane = $this->swimlaneModel->getById($swimlane_id); + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSwimlaneById', $swimlane['project_id']); + return $swimlane; + } + + public function getSwimlaneByName($project_id, $name) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSwimlaneByName', $project_id); + return $this->swimlaneModel->getByName($project_id, $name); + } + + public function getSwimlane($swimlane_id) + { + return $this->swimlaneModel->getById($swimlane_id); + } + + public function getDefaultSwimlane($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getDefaultSwimlane', $project_id); + return $this->swimlaneModel->getDefault($project_id); + } + + public function addSwimlane($project_id, $name, $description = '') + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'addSwimlane', $project_id); + return $this->swimlaneModel->create(array('project_id' => $project_id, 'name' => $name, 'description' => $description)); + } + + public function updateSwimlane($swimlane_id, $name, $description = null) + { + $values = array('id' => $swimlane_id, 'name' => $name); + + if (!is_null($description)) { + $values['description'] = $description; + } + + return $this->swimlaneModel->update($values); + } + + public function removeSwimlane($project_id, $swimlane_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeSwimlane', $project_id); + return $this->swimlaneModel->remove($project_id, $swimlane_id); + } + + public function disableSwimlane($project_id, $swimlane_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'disableSwimlane', $project_id); + return $this->swimlaneModel->disable($project_id, $swimlane_id); + } + + public function enableSwimlane($project_id, $swimlane_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'enableSwimlane', $project_id); + return $this->swimlaneModel->enable($project_id, $swimlane_id); + } + + public function changeSwimlanePosition($project_id, $swimlane_id, $position) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'changeSwimlanePosition', $project_id); + return $this->swimlaneModel->changePosition($project_id, $swimlane_id, $position); + } +} diff --git a/app/Api/Procedure/TaskFileProcedure.php b/app/Api/Procedure/TaskFileProcedure.php new file mode 100644 index 00000000..5aa7ea0b --- /dev/null +++ b/app/Api/Procedure/TaskFileProcedure.php @@ -0,0 +1,70 @@ +container)->check($this->getClassName(), 'getTaskFile', $file_id); + return $this->taskFileModel->getById($file_id); + } + + public function getAllTaskFiles($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTaskFiles', $task_id); + return $this->taskFileModel->getAll($task_id); + } + + public function downloadTaskFile($file_id) + { + TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'downloadTaskFile', $file_id); + + try { + $file = $this->taskFileModel->getById($file_id); + + if (! empty($file)) { + return base64_encode($this->objectStorage->get($file['path'])); + } + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + + return ''; + } + + public function createTaskFile($project_id, $task_id, $filename, $blob) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createTaskFile', $project_id); + + try { + return $this->taskFileModel->uploadContent($task_id, $filename, $blob); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + public function removeTaskFile($file_id) + { + TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeTaskFile', $file_id); + return $this->taskFileModel->remove($file_id); + } + + public function removeAllTaskFiles($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeAllTaskFiles', $task_id); + return $this->taskFileModel->removeAll($task_id); + } +} diff --git a/app/Api/Procedure/TaskLinkProcedure.php b/app/Api/Procedure/TaskLinkProcedure.php new file mode 100644 index 00000000..375266fb --- /dev/null +++ b/app/Api/Procedure/TaskLinkProcedure.php @@ -0,0 +1,85 @@ +container)->check($this->getClassName(), 'getTaskLinkById', $task_link_id); + return $this->taskLinkModel->getById($task_link_id); + } + + /** + * Get all links attached to a task + * + * @access public + * @param integer $task_id Task id + * @return array + */ + public function getAllTaskLinks($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTaskLinks', $task_id); + return $this->taskLinkModel->getAll($task_id); + } + + /** + * Create a new link + * + * @access public + * @param integer $task_id Task id + * @param integer $opposite_task_id Opposite task id + * @param integer $link_id Link id + * @return integer Task link id + */ + public function createTaskLink($task_id, $opposite_task_id, $link_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createTaskLink', $task_id); + return $this->taskLinkModel->create($task_id, $opposite_task_id, $link_id); + } + + /** + * Update a task link + * + * @access public + * @param integer $task_link_id Task link id + * @param integer $task_id Task id + * @param integer $opposite_task_id Opposite task id + * @param integer $link_id Link id + * @return boolean + */ + public function updateTaskLink($task_link_id, $task_id, $opposite_task_id, $link_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTaskLink', $task_id); + return $this->taskLinkModel->update($task_link_id, $task_id, $opposite_task_id, $link_id); + } + + /** + * Remove a link between two tasks + * + * @access public + * @param integer $task_link_id + * @return boolean + */ + public function removeTaskLink($task_link_id) + { + TaskLinkAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeTaskLink', $task_link_id); + return $this->taskLinkModel->remove($task_link_id); + } +} diff --git a/app/Api/Procedure/TaskProcedure.php b/app/Api/Procedure/TaskProcedure.php new file mode 100644 index 00000000..2d29a4ef --- /dev/null +++ b/app/Api/Procedure/TaskProcedure.php @@ -0,0 +1,167 @@ +container)->check($this->getClassName(), 'searchTasks', $project_id); + return $this->taskLexer->build($query)->withFilter(new TaskProjectFilter($project_id))->toArray(); + } + + public function getTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTask', $task_id); + return $this->formatTask($this->taskFinderModel->getById($task_id)); + } + + public function getTaskByReference($project_id, $reference) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getTaskByReference', $project_id); + return $this->formatTask($this->taskFinderModel->getByReference($project_id, $reference)); + } + + public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllTasks', $project_id); + return $this->formatTasks($this->taskFinderModel->getAll($project_id, $status_id)); + } + + public function getOverdueTasks() + { + return $this->taskFinderModel->getOverdueTasks(); + } + + public function getOverdueTasksByProject($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getOverdueTasksByProject', $project_id); + return $this->taskFinderModel->getOverdueTasksByProject($project_id); + } + + public function openTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'openTask', $task_id); + return $this->taskStatusModel->open($task_id); + } + + public function closeTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'closeTask', $task_id); + return $this->taskStatusModel->close($task_id); + } + + public function removeTask($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeTask', $task_id); + return $this->taskModel->remove($task_id); + } + + public function moveTaskPosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'moveTaskPosition', $project_id); + return $this->taskPositionModel->movePosition($project_id, $task_id, $column_id, $position, $swimlane_id); + } + + public function moveTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'moveTaskToProject', $project_id); + return $this->taskDuplicationModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + } + + public function duplicateTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'duplicateTaskToProject', $project_id); + return $this->taskDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + } + + public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, + $date_due = '', $description = '', $category_id = 0, $score = 0, $swimlane_id = 0, $priority = 0, + $recurrence_status = 0, $recurrence_trigger = 0, $recurrence_factor = 0, $recurrence_timeframe = 0, + $recurrence_basedate = 0, $reference = '') + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createTask', $project_id); + + if ($owner_id !== 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { + return false; + } + + if ($this->userSession->isLogged()) { + $creator_id = $this->userSession->getId(); + } + + $values = array( + 'title' => $title, + 'project_id' => $project_id, + 'color_id' => $color_id, + 'column_id' => $column_id, + 'owner_id' => $owner_id, + 'creator_id' => $creator_id, + 'date_due' => $date_due, + 'description' => $description, + 'category_id' => $category_id, + 'score' => $score, + 'swimlane_id' => $swimlane_id, + 'recurrence_status' => $recurrence_status, + 'recurrence_trigger' => $recurrence_trigger, + 'recurrence_factor' => $recurrence_factor, + 'recurrence_timeframe' => $recurrence_timeframe, + 'recurrence_basedate' => $recurrence_basedate, + 'reference' => $reference, + 'priority' => $priority, + ); + + list($valid, ) = $this->taskValidator->validateCreation($values); + + return $valid ? $this->taskCreationModel->create($values) : false; + } + + public function updateTask($id, $title = null, $color_id = null, $owner_id = null, + $date_due = null, $description = null, $category_id = null, $score = null, $priority = null, + $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null, + $recurrence_timeframe = null, $recurrence_basedate = null, $reference = null) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateTask', $id); + $project_id = $this->taskFinderModel->getProjectId($id); + + if ($project_id === 0) { + return false; + } + + if ($owner_id !== null && $owner_id != 0 && ! $this->projectPermissionModel->isAssignable($project_id, $owner_id)) { + return false; + } + + $values = $this->filterValues(array( + 'id' => $id, + 'title' => $title, + 'color_id' => $color_id, + 'owner_id' => $owner_id, + 'date_due' => $date_due, + 'description' => $description, + 'category_id' => $category_id, + 'score' => $score, + 'recurrence_status' => $recurrence_status, + 'recurrence_trigger' => $recurrence_trigger, + 'recurrence_factor' => $recurrence_factor, + 'recurrence_timeframe' => $recurrence_timeframe, + 'recurrence_basedate' => $recurrence_basedate, + 'reference' => $reference, + 'priority' => $priority, + )); + + list($valid) = $this->taskValidator->validateApiModification($values); + return $valid && $this->taskModificationModel->update($values); + } +} diff --git a/app/Api/Procedure/UserProcedure.php b/app/Api/Procedure/UserProcedure.php new file mode 100644 index 00000000..145f85bf --- /dev/null +++ b/app/Api/Procedure/UserProcedure.php @@ -0,0 +1,131 @@ +userModel->getById($user_id); + } + + public function getUserByName($username) + { + return $this->userModel->getByUsername($username); + } + + public function getAllUsers() + { + return $this->userModel->getAll(); + } + + public function removeUser($user_id) + { + return $this->userModel->remove($user_id); + } + + public function disableUser($user_id) + { + return $this->userModel->disable($user_id); + } + + public function enableUser($user_id) + { + return $this->userModel->enable($user_id); + } + + public function isActiveUser($user_id) + { + return $this->userModel->isActive($user_id); + } + + public function createUser($username, $password, $name = '', $email = '', $role = Role::APP_USER) + { + $values = array( + 'username' => $username, + 'password' => $password, + 'confirmation' => $password, + 'name' => $name, + 'email' => $email, + 'role' => $role, + ); + + list($valid, ) = $this->userValidator->validateCreation($values); + return $valid ? $this->userModel->create($values) : false; + } + + /** + * Create LDAP user in the database + * + * Only "anonymous" and "proxy" LDAP authentication are supported by this method + * + * User information will be fetched from the LDAP server + * + * @access public + * @param string $username + * @return bool|int + */ + public function createLdapUser($username) + { + if (LDAP_BIND_TYPE === 'user') { + $this->logger->error('LDAP authentication "user" is not supported by this API call'); + return false; + } + + try { + + $ldap = LdapClient::connect(); + $ldap->setLogger($this->logger); + $user = LdapUser::getUser($ldap, $username); + + if ($user === null) { + $this->logger->info('User not found in LDAP server'); + return false; + } + + if ($user->getUsername() === '') { + throw new LogicException('Username not found in LDAP profile, check the parameter LDAP_USER_ATTRIBUTE_USERNAME'); + } + + $values = array( + 'username' => $user->getUsername(), + 'name' => $user->getName(), + 'email' => $user->getEmail(), + 'role' => $user->getRole(), + 'is_ldap_user' => 1, + ); + + return $this->userModel->create($values); + + } catch (LdapException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + public function updateUser($id, $username = null, $name = null, $email = null, $role = null) + { + $values = $this->filterValues(array( + 'id' => $id, + 'username' => $username, + 'name' => $name, + 'email' => $email, + 'role' => $role, + )); + + list($valid, ) = $this->userValidator->validateApiModification($values); + return $valid && $this->userModel->update($values); + } +} -- cgit v1.2.3 From b48c0cecbb1f687641594430260a67938d870cbb Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 11:57:28 -0400 Subject: Added new arguments to project API calls and update composer.json --- ChangeLog | 1 + app/Api/Procedure/BaseProcedure.php | 1 - app/Api/Procedure/ProjectProcedure.php | 6 +- app/Validator/ProjectValidator.php | 8 +- composer.json | 31 +-- composer.lock | 297 +++++++------------------ doc/api-project-procedures.markdown | 2 +- doc/requirements.markdown | 2 +- tests/integration/ProjectProcedureTest.php | 29 +++ tests/units/Validator/ProjectValidatorTest.php | 12 +- 10 files changed, 143 insertions(+), 246 deletions(-) (limited to 'app/Api/Procedure') diff --git a/ChangeLog b/ChangeLog index 42af8ee3..550a7ada 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ New features: Improvements: +* Added argument owner_id and identifier to project API calls * Rewrite integration tests to run with Docker containers * Use the same task form layout everywhere * Remove some tasks dropdown menus that are now available with task edit form diff --git a/app/Api/Procedure/BaseProcedure.php b/app/Api/Procedure/BaseProcedure.php index 0aa43428..e31b3027 100644 --- a/app/Api/Procedure/BaseProcedure.php +++ b/app/Api/Procedure/BaseProcedure.php @@ -2,7 +2,6 @@ namespace Kanboard\Api\Procedure; -use JsonRPC\Exception\AccessDeniedException; use Kanboard\Api\Authorization\ProcedureAuthorization; use Kanboard\Api\Authorization\UserAuthorization; use Kanboard\Core\Base; diff --git a/app/Api/Procedure/ProjectProcedure.php b/app/Api/Procedure/ProjectProcedure.php index 9187f221..fe6b63e2 100644 --- a/app/Api/Procedure/ProjectProcedure.php +++ b/app/Api/Procedure/ProjectProcedure.php @@ -78,17 +78,17 @@ class ProjectProcedure extends BaseProcedure public function createProject($name, $description = null, $owner_id = 0, $identifier = null) { - $values = array( + $values = $this->filterValues(array( 'name' => $name, 'description' => $description, 'identifier' => $identifier, - ); + )); list($valid, ) = $this->projectValidator->validateCreation($values); return $valid ? $this->projectModel->create($values, $owner_id, $this->userSession->isLogged()) : false; } - public function updateProject($project_id, $name, $description = null, $owner_id = null, $identifier = null) + public function updateProject($project_id, $name = null, $description = null, $owner_id = null, $identifier = null) { ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateProject', $project_id); diff --git a/app/Validator/ProjectValidator.php b/app/Validator/ProjectValidator.php index 9ef59111..8c6117a4 100644 --- a/app/Validator/ProjectValidator.php +++ b/app/Validator/ProjectValidator.php @@ -28,7 +28,7 @@ class ProjectValidator extends BaseValidator new Validators\Integer('priority_start', t('This value must be an integer')), new Validators\Integer('priority_end', t('This value must be an integer')), new Validators\Integer('is_active', t('This value must be an integer')), - new Validators\Required('name', t('The project name is required')), + new Validators\NotEmpty('name', t('This field cannot be empty')), new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50), new Validators\MaxLength('identifier', t('The maximum length is %d characters', 50), 50), new Validators\MaxLength('start_date', t('The maximum length is %d characters', 10), 10), @@ -47,11 +47,15 @@ class ProjectValidator extends BaseValidator */ public function validateCreation(array $values) { + $rules = array( + new Validators\Required('name', t('The project name is required')), + ); + if (! empty($values['identifier'])) { $values['identifier'] = strtoupper($values['identifier']); } - $v = new Validator($values, $this->commonValidationRules()); + $v = new Validator($values, array_merge($this->commonValidationRules(), $rules)); return array( $v->execute(), diff --git a/composer.json b/composer.json index bcac020e..d82f3f0c 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "discard-changes": true }, "require" : { - "php" : ">=5.3.3", + "php" : ">=5.3.9", "ext-gd" : "*", "ext-mbstring" : "*", "ext-hash" : "*", @@ -23,21 +23,21 @@ "ext-ctype" : "*", "ext-filter" : "*", "ext-session" : "*", - "christian-riesen/otp" : "1.4", - "eluceo/ical": "0.8.0", + "christian-riesen/otp" : "1.4.3", + "eluceo/ical": "0.10.1", "erusev/parsedown" : "1.6.0", "fguillot/json-rpc" : "1.2.1", "fguillot/picodb" : "1.0.12", "fguillot/simpleLogger" : "1.0.1", - "fguillot/simple-validator" : "1.0.0", + "fguillot/simple-validator" : "1.0.1", "fguillot/simple-queue" : "1.0.1", - "paragonie/random_compat": "@stable", - "pimple/pimple" : "~3.0", - "ramsey/array_column": "@stable", - "swiftmailer/swiftmailer" : "~5.4", - "symfony/console" : "~2.7", - "symfony/event-dispatcher" : "~2.7", - "gregwar/captcha": "1.*" + "paragonie/random_compat": "2.0.2", + "pimple/pimple" : "3.0.2", + "ramsey/array_column": "1.1.3", + "swiftmailer/swiftmailer" : "5.4.2", + "symfony/console" : "2.8.7", + "symfony/event-dispatcher" : "2.7.14", + "gregwar/captcha": "1.1.1" }, "autoload" : { "classmap" : ["app/"], @@ -50,9 +50,10 @@ ] }, "require-dev" : { - "symfony/yaml" : "2.1", - "symfony/stopwatch" : "~2.6", - "phpunit/phpunit" : "4.8.*", - "phpunit/phpunit-selenium": "^2.0" + "phpdocumentor/reflection-docblock": "2.0.4", + "symfony/yaml": "2.8.7", + "symfony/stopwatch" : "2.6.13", + "phpunit/phpunit" : "4.8.26", + "phpunit/phpunit-selenium": "2.0.2" } } diff --git a/composer.lock b/composer.lock index e6a72582..03c5e523 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "283af0b856598f5bc3d8ee0b226959e5", - "content-hash": "18c0bbff5406ceb8b567d9655de26746", + "hash": "ab5b2c960b3a6d9f93883606269085e0", + "content-hash": "bd5f17c3382d7f85e33a68023927704c", "packages": [ { "name": "christian-riesen/base32", @@ -63,22 +63,25 @@ }, { "name": "christian-riesen/otp", - "version": "1.4", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/ChristianRiesen/otp.git", - "reference": "a209b8bbd975d96d6b5287f8658562061adef1f8" + "reference": "20a539ce6280eb029030f4e7caefd5709a75e1ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ChristianRiesen/otp/zipball/a209b8bbd975d96d6b5287f8658562061adef1f8", - "reference": "a209b8bbd975d96d6b5287f8658562061adef1f8", + "url": "https://api.github.com/repos/ChristianRiesen/otp/zipball/20a539ce6280eb029030f4e7caefd5709a75e1ad", + "reference": "20a539ce6280eb029030f4e7caefd5709a75e1ad", "shasum": "" }, "require": { "christian-riesen/base32": ">=1.0", "php": ">=5.3.0" }, + "suggest": { + "paragonie/random_compat": "Optional polyfill for a more secure random generator for pre PHP7 versions" + }, "type": "library", "autoload": { "psr-0": { @@ -107,20 +110,20 @@ "rfc6238", "totp" ], - "time": "2015-02-12 09:11:49" + "time": "2015-10-08 08:17:59" }, { "name": "eluceo/ical", - "version": "0.8.0", + "version": "0.10.1", "source": { "type": "git", "url": "https://github.com/markuspoerschke/iCal.git", - "reference": "a291711851d1538e2726ffe95862aa5e340ddb9a" + "reference": "2dd99c12c0aa961c541380ab0c113135e14af33e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/markuspoerschke/iCal/zipball/a291711851d1538e2726ffe95862aa5e340ddb9a", - "reference": "a291711851d1538e2726ffe95862aa5e340ddb9a", + "url": "https://api.github.com/repos/markuspoerschke/iCal/zipball/2dd99c12c0aa961c541380ab0c113135e14af33e", + "reference": "2dd99c12c0aa961c541380ab0c113135e14af33e", "shasum": "" }, "require": { @@ -160,7 +163,7 @@ "ics", "php calendar" ], - "time": "2015-07-12 18:19:30" + "time": "2016-06-09 09:08:55" }, { "name": "erusev/parsedown", @@ -331,16 +334,16 @@ }, { "name": "fguillot/simple-validator", - "version": "1.0.0", + "version": "v1.0.1", "source": { "type": "git", "url": "https://github.com/fguillot/simpleValidator.git", - "reference": "9579993f3dd0f03053b28fec1e7b9990edc3947b" + "reference": "23b0a99c5f11ad74d05f8845feaafbcfd9223eda" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/simpleValidator/zipball/9579993f3dd0f03053b28fec1e7b9990edc3947b", - "reference": "9579993f3dd0f03053b28fec1e7b9990edc3947b", + "url": "https://api.github.com/repos/fguillot/simpleValidator/zipball/23b0a99c5f11ad74d05f8845feaafbcfd9223eda", + "reference": "23b0a99c5f11ad74d05f8845feaafbcfd9223eda", "shasum": "" }, "require": { @@ -363,7 +366,7 @@ ], "description": "Simple validator library", "homepage": "https://github.com/fguillot/simpleValidator", - "time": "2015-08-29 00:44:37" + "time": "2016-06-26 15:09:26" }, { "name": "fguillot/simpleLogger", @@ -742,16 +745,16 @@ }, { "name": "symfony/event-dispatcher", - "version": "v2.8.7", + "version": "v2.7.14", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "2a6b8713f8bdb582058cfda463527f195b066110" + "reference": "d3e09ed1224503791f31b913d22196f65f9afed5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2a6b8713f8bdb582058cfda463527f195b066110", - "reference": "2a6b8713f8bdb582058cfda463527f195b066110", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d3e09ed1224503791f31b913d22196f65f9afed5", + "reference": "d3e09ed1224503791f31b913d22196f65f9afed5", "shasum": "" }, "require": { @@ -759,10 +762,10 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~2.0,>=2.0.5|~3.0.0", - "symfony/dependency-injection": "~2.6|~3.0.0", - "symfony/expression-language": "~2.6|~3.0.0", - "symfony/stopwatch": "~2.3|~3.0.0" + "symfony/config": "~2.0,>=2.0.5", + "symfony/dependency-injection": "~2.6", + "symfony/expression-language": "~2.6", + "symfony/stopwatch": "~2.3" }, "suggest": { "symfony/dependency-injection": "", @@ -771,7 +774,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.8-dev" + "dev-master": "2.7-dev" } }, "autoload": { @@ -798,7 +801,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2016-06-06 11:11:27" + "time": "2016-06-06 11:03:51" }, { "name": "symfony/polyfill-mbstring", @@ -915,136 +918,39 @@ ], "time": "2015-06-14 21:17:01" }, - { - "name": "phpdocumentor/reflection-common", - "version": "1.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "shasum": "" - }, - "require": { - "php": ">=5.5" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" - } - ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", - "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" - ], - "time": "2015-12-27 11:43:31" - }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.1.0", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd" + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/9270140b940ff02e58ec577c237274e92cd40cdd", - "reference": "9270140b940ff02e58ec577c237274e92cd40cdd", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", + "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", "shasum": "" }, "require": { - "php": ">=5.5", - "phpdocumentor/reflection-common": "^1.0@dev", - "phpdocumentor/type-resolver": "^0.2.0", - "webmozart/assert": "^1.0" + "php": ">=5.3.3" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2016-06-10 09:48:41" - }, - { - "name": "phpdocumentor/type-resolver", - "version": "0.2", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b39c7a5b194f9ed7bd0dd345c751007a41862443", - "reference": "b39c7a5b194f9ed7bd0dd345c751007a41862443", - "shasum": "" - }, - "require": { - "php": ">=5.5", - "phpdocumentor/reflection-common": "^1.0" + "phpunit/phpunit": "~4.0" }, - "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "suggest": { + "dflydev/markdown": "~1.0", + "erusev/parsedown": "~1.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ + "psr-0": { + "phpDocumentor": [ "src/" ] } @@ -1056,10 +962,10 @@ "authors": [ { "name": "Mike van Riel", - "email": "me@mikevanriel.com" + "email": "mike.vanriel@naenius.com" } ], - "time": "2016-06-10 07:14:17" + "time": "2015-02-03 12:10:50" }, { "name": "phpspec/prophecy", @@ -1932,34 +1838,35 @@ }, { "name": "symfony/stopwatch", - "version": "v2.8.7", + "version": "v2.6.13", + "target-dir": "Symfony/Component/Stopwatch", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "5e628055488bcc42dbace3af65be435d094e37e4" + "reference": "a0d91f2f4e2c60bd78f13388aa68f9d7cab8c987" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5e628055488bcc42dbace3af65be435d094e37e4", - "reference": "5e628055488bcc42dbace3af65be435d094e37e4", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/a0d91f2f4e2c60bd78f13388aa68f9d7cab8c987", + "reference": "a0d91f2f4e2c60bd78f13388aa68f9d7cab8c987", "shasum": "" }, "require": { - "php": ">=5.3.9" + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.8-dev" + "dev-master": "2.6-dev" } }, "autoload": { - "psr-4": { + "psr-0": { "Symfony\\Component\\Stopwatch\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1977,115 +1884,65 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2016-06-06 11:11:27" + "time": "2015-07-01 18:23:01" }, { "name": "symfony/yaml", - "version": "v2.1.0", - "target-dir": "Symfony/Component/Yaml", + "version": "v2.8.7", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "f18e004fc975707bb4695df1dbbe9b0d8c8b7715" + "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/f18e004fc975707bb4695df1dbbe9b0d8c8b7715", - "reference": "f18e004fc975707bb4695df1dbbe9b0d8c8b7715", + "url": "https://api.github.com/repos/symfony/yaml/zipball/815fabf3f48c7d1df345a69d1ad1a88f59757b34", + "reference": "815fabf3f48c7d1df345a69d1ad1a88f59757b34", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "2.8-dev" } }, "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml": "" - } + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, { "name": "Fabien Potencier", "email": "fabien@symfony.com" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2012-08-22 13:48:41" - }, - { - "name": "webmozart/assert", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", - "reference": "30eed06dd6bc88410a4ff7f77b6d22f3ce13dbde", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ + }, { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "time": "2015-08-24 13:29:44" + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2016-06-06 11:11:27" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "paragonie/random_compat": 0, - "ramsey/array_column": 0 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.3", + "php": ">=5.3.9", "ext-gd": "*", "ext-mbstring": "*", "ext-hash": "*", diff --git a/doc/api-project-procedures.markdown b/doc/api-project-procedures.markdown index 3f8d33c2..d375852c 100644 --- a/doc/api-project-procedures.markdown +++ b/doc/api-project-procedures.markdown @@ -186,7 +186,7 @@ Response example: - Purpose: **Update a project** - Parameters: - **project_id** (integer, required) - - **name** (string, required) + - **name** (string, optional) - **description** (string, optional) - **owner_id** (integer, optional) - **identifier** (string, optional) diff --git a/doc/requirements.markdown b/doc/requirements.markdown index 9943465a..f6c9b309 100644 --- a/doc/requirements.markdown +++ b/doc/requirements.markdown @@ -51,7 +51,7 @@ Kanboard is pre-configured to work with Apache (URL rewriting). | PHP Version | |----------------| -| PHP >= 5.3.3 | +| PHP >= 5.3.9 | | PHP 5.4 | | PHP 5.5 | | PHP 5.6 | diff --git a/tests/integration/ProjectProcedureTest.php b/tests/integration/ProjectProcedureTest.php index 1ebd48ae..a4b65241 100644 --- a/tests/integration/ProjectProcedureTest.php +++ b/tests/integration/ProjectProcedureTest.php @@ -13,6 +13,8 @@ class ProjectProcedureTest extends BaseProcedureTest $this->assertGetProjectByName(); $this->assertGetAllProjects(); $this->assertUpdateProject(); + $this->assertUpdateProjectIdentifier(); + $this->assertCreateProjectWithIdentifier(); $this->assertGetProjectActivity(); $this->assertGetProjectsActivity(); $this->assertEnableDisableProject(); @@ -69,6 +71,33 @@ class ProjectProcedureTest extends BaseProcedureTest $this->assertTrue($this->app->updateProject(array('project_id' => $this->projectId, 'name' => $this->projectName))); } + public function assertUpdateProjectIdentifier() + { + $this->assertTrue($this->app->updateProject(array( + 'project_id' => $this->projectId, + 'identifier' => 'MYPROJECT', + ))); + + $project = $this->app->getProjectById($this->projectId); + $this->assertNotNull($project); + $this->assertEquals($this->projectName, $project['name']); + $this->assertEquals('MYPROJECT', $project['identifier']); + } + + public function assertCreateProjectWithIdentifier() + { + $projectId = $this->app->createProject(array( + 'name' => 'My project with an identifier', + 'identifier' => 'MYPROJECTWITHIDENTIFIER', + )); + + $this->assertNotFalse($projectId); + + $project = $this->app->getProjectById($projectId); + $this->assertEquals('My project with an identifier', $project['name']); + $this->assertEquals('MYPROJECTWITHIDENTIFIER', $project['identifier']); + } + public function assertEnableDisableProject() { $this->assertTrue($this->app->disableProject($this->projectId)); diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php index 07de6c25..e1e2f077 100644 --- a/tests/units/Validator/ProjectValidatorTest.php +++ b/tests/units/Validator/ProjectValidatorTest.php @@ -55,13 +55,19 @@ class ProjectValidatorTest extends Base $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); + $r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); + $r = $validator->validateModification(array('id' => 1, 'identifier' => '')); $this->assertTrue($r[0]); - $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); + $r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => '')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => null)); $this->assertFalse($r[0]); } } -- cgit v1.2.3 From c110dffefe259c13e60193fb81ebb9d4b79504de Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 12:34:20 -0400 Subject: Added new API call: "getProjectByIdentifier" --- ChangeLog | 5 +++-- app/Api/Procedure/ProjectProcedure.php | 7 +++++++ tests/integration/ProjectProcedureTest.php | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'app/Api/Procedure') diff --git a/ChangeLog b/ChangeLog index 550a7ada..883cc6cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,14 +4,15 @@ Version 1.0.31 (unreleased) New features: * Added application and project roles validation for API procedure calls +* Added new API call: "getProjectByIdentifier" Improvements: * Added argument owner_id and identifier to project API calls * Rewrite integration tests to run with Docker containers * Use the same task form layout everywhere -* Remove some tasks dropdown menus that are now available with task edit form -* Make embedded documentation available in multiple languages +* Removed some tasks dropdown menus that are now available with task edit form +* Make embedded documentation readable in multiple languages (if a translation is available) Bug fixes: diff --git a/app/Api/Procedure/ProjectProcedure.php b/app/Api/Procedure/ProjectProcedure.php index fe6b63e2..a580c8d9 100644 --- a/app/Api/Procedure/ProjectProcedure.php +++ b/app/Api/Procedure/ProjectProcedure.php @@ -25,6 +25,13 @@ class ProjectProcedure extends BaseProcedure return $this->formatProject($project); } + public function getProjectByIdentifier($identifier) + { + $project = $this->formatProject($this->projectModel->getByIdentifier($identifier)); + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getProjectByIdentifier', $project['id']); + return $this->formatProject($project); + } + public function getAllProjects() { return $this->formatProjects($this->projectModel->getAll()); diff --git a/tests/integration/ProjectProcedureTest.php b/tests/integration/ProjectProcedureTest.php index a4b65241..69c2464f 100644 --- a/tests/integration/ProjectProcedureTest.php +++ b/tests/integration/ProjectProcedureTest.php @@ -93,7 +93,8 @@ class ProjectProcedureTest extends BaseProcedureTest $this->assertNotFalse($projectId); - $project = $this->app->getProjectById($projectId); + $project = $this->app->getProjectByIdentifier('MYPROJECTWITHIDENTIFIER'); + $this->assertEquals($projectId, $project['id']); $this->assertEquals('My project with an identifier', $project['name']); $this->assertEquals('MYPROJECTWITHIDENTIFIER', $project['identifier']); } -- cgit v1.2.3 From 3d34681610854474cb9dbdd93886dbcf0e208a99 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 14:33:53 -0400 Subject: Added new API calls for external task links --- ChangeLog | 1 + app/Api/Procedure/TaskExternalLinkProcedure.php | 106 ++++++++++ app/Core/ExternalLink/ExternalLinkManager.php | 24 +++ app/ServiceProvider/ApiProvider.php | 2 + app/ServiceProvider/AuthenticationProvider.php | 1 + doc/api-external-task-link-procedures.markdown | 221 +++++++++++++++++++++ doc/api-internal-task-link-procedures.markdown | 187 +++++++++++++++++ doc/api-json-rpc.markdown | 2 + doc/api-link-procedures.markdown | 185 ----------------- .../integration/TaskExternalLinkProcedureTest.php | 98 +++++++++ 10 files changed, 642 insertions(+), 185 deletions(-) create mode 100644 app/Api/Procedure/TaskExternalLinkProcedure.php create mode 100644 doc/api-external-task-link-procedures.markdown create mode 100644 doc/api-internal-task-link-procedures.markdown create mode 100644 tests/integration/TaskExternalLinkProcedureTest.php (limited to 'app/Api/Procedure') diff --git a/ChangeLog b/ChangeLog index 883cc6cf..85966ed8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ New features: * Added application and project roles validation for API procedure calls * Added new API call: "getProjectByIdentifier" +* Added new API calls for external task links Improvements: diff --git a/app/Api/Procedure/TaskExternalLinkProcedure.php b/app/Api/Procedure/TaskExternalLinkProcedure.php new file mode 100644 index 00000000..05ec6906 --- /dev/null +++ b/app/Api/Procedure/TaskExternalLinkProcedure.php @@ -0,0 +1,106 @@ +externalLinkManager->getTypes(); + } + + public function getExternalTaskLinkProviderDependencies($providerName) + { + try { + return $this->externalLinkManager->getProvider($providerName)->getDependencies(); + } catch (ExternalLinkProviderNotFound $e) { + $this->logger->error(__METHOD__.': '.$e->getMessage()); + return false; + } + } + + public function getExternalTaskLinkById($task_id, $link_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getExternalTaskLink', $task_id); + return $this->taskExternalLinkModel->getById($link_id); + } + + public function getAllExternalTaskLinks($task_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getExternalTaskLinks', $task_id); + return $this->taskExternalLinkModel->getAll($task_id); + } + + public function createExternalTaskLink($task_id, $url, $dependency, $type = ExternalLinkManager::TYPE_AUTO, $title = '') + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'createExternalTaskLink', $task_id); + + try { + $provider = $this->externalLinkManager + ->setUserInputText($url) + ->setUserInputType($type) + ->find(); + + $link = $provider->getLink(); + + $values = array( + 'task_id' => $task_id, + 'title' => $title ?: $link->getTitle(), + 'url' => $link->getUrl(), + 'link_type' => $provider->getType(), + 'dependency' => $dependency, + ); + + list($valid, $errors) = $this->externalLinkValidator->validateCreation($values); + + if (! $valid) { + $this->logger->error(__METHOD__.': '.var_export($errors)); + return false; + } + + return $this->taskExternalLinkModel->create($values); + } catch (ExternalLinkProviderNotFound $e) { + $this->logger->error(__METHOD__.': '.$e->getMessage()); + } + + return false; + } + + public function updateExternalTaskLink($task_id, $link_id, $title = null, $url = null, $dependency = null) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'updateExternalTaskLink', $task_id); + + $link = $this->taskExternalLinkModel->getById($link_id); + $values = $this->filterValues(array( + 'title' => $title, + 'url' => $url, + 'dependency' => $dependency, + )); + + $values = array_merge($link, $values); + list($valid, $errors) = $this->externalLinkValidator->validateModification($values); + + if (! $valid) { + $this->logger->error(__METHOD__.': '.var_export($errors)); + return false; + } + + return $this->taskExternalLinkModel->update($values); + } + + public function removeExternalTaskLink($task_id, $link_id) + { + TaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeExternalTaskLink', $task_id); + return $this->taskExternalLinkModel->remove($link_id); + } +} diff --git a/app/Core/ExternalLink/ExternalLinkManager.php b/app/Core/ExternalLink/ExternalLinkManager.php index 804e6b34..5a037999 100644 --- a/app/Core/ExternalLink/ExternalLinkManager.php +++ b/app/Core/ExternalLink/ExternalLinkManager.php @@ -152,6 +152,30 @@ class ExternalLinkManager extends Base return $this; } + /** + * Set provider type + * + * @access public + * @param string $userInputType + * @return ExternalLinkManager + */ + public function setUserInputType($userInputType) + { + $this->userInputType = $userInputType; + return $this; + } + + /** + * Set external link + * @param string $userInputText + * @return ExternalLinkManager + */ + public function setUserInputText($userInputText) + { + $this->userInputText = $userInputText; + return $this; + } + /** * Find a provider that user input * diff --git a/app/ServiceProvider/ApiProvider.php b/app/ServiceProvider/ApiProvider.php index f88d9b4f..194bee5b 100644 --- a/app/ServiceProvider/ApiProvider.php +++ b/app/ServiceProvider/ApiProvider.php @@ -9,6 +9,7 @@ use Kanboard\Api\Procedure\BoardProcedure; use Kanboard\Api\Procedure\CategoryProcedure; use Kanboard\Api\Procedure\ColumnProcedure; use Kanboard\Api\Procedure\CommentProcedure; +use Kanboard\Api\Procedure\TaskExternalLinkProcedure; use Kanboard\Api\Procedure\TaskFileProcedure; use Kanboard\Api\Procedure\GroupProcedure; use Kanboard\Api\Procedure\GroupMemberProcedure; @@ -65,6 +66,7 @@ class ApiProvider implements ServiceProviderInterface ->withObject(new SwimlaneProcedure($container)) ->withObject(new TaskProcedure($container)) ->withObject(new TaskLinkProcedure($container)) + ->withObject(new TaskExternalLinkProcedure($container)) ->withObject(new UserProcedure($container)) ->withObject(new GroupProcedure($container)) ->withObject(new GroupMemberProcedure($container)) diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index 751fe514..34b81b9d 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -204,6 +204,7 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('SwimlaneProcedure', '*', Role::PROJECT_MANAGER); $acl->add('TaskFileProcedure', '*', Role::PROJECT_MEMBER); $acl->add('TaskLinkProcedure', '*', Role::PROJECT_MEMBER); + $acl->add('TaskExternalLinkProcedure', array('createExternalTaskLink', 'updateExternalTaskLink', 'removeExternalTaskLink'), Role::PROJECT_MEMBER); $acl->add('TaskProcedure', '*', Role::PROJECT_MEMBER); return $acl; diff --git a/doc/api-external-task-link-procedures.markdown b/doc/api-external-task-link-procedures.markdown new file mode 100644 index 00000000..2858be86 --- /dev/null +++ b/doc/api-external-task-link-procedures.markdown @@ -0,0 +1,221 @@ +Internal Task Links API Procedures +================================== + +## getExternalTaskLinkTypes + +- Purpose: **Get all registered external link providers** +- Parameters: **none** +- Result on success: **dict** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"getExternalTaskLinkTypes","id":477370568} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": { + "auto": "Auto", + "attachment": "Attachment", + "file": "Local File", + "weblink": "Web Link" + }, + "id": 477370568 +} +``` + +## getExternalTaskLinkProviderDependencies + +- Purpose: **Get available dependencies for a given provider** +- Parameters: + - **providerName** (string, required) +- Result on success: **dict** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"getExternalTaskLinkProviderDependencies","id":124790226,"params":["weblink"]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": { + "related": "Related" + }, + "id": 124790226 +} +``` + +## createExternalTaskLink + +- Purpose: **Create a new external link** +- Parameters: + - **task_id** (integer, required) + - **url** (string, required) + - **dependency** (string, required) + - **type** (string, optional) + - **title** (string, optional) +- Result on success: **link_id** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"createExternalTaskLink","id":924217495,"params":[9,"http:\/\/localhost\/document.pdf","related","attachment"]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": 1, + "id": 924217495 +} +``` + +## updateExternalTaskLink + +- Purpose: **Update external task link** +- Parameters: + - **task_id** (integer, required) + - **link_id** (integer, required) + - **title** (string, required) + - **url** (string, required) + - **dependency** (string, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc":"2.0", + "method":"updateExternalTaskLink", + "id":1123562620, + "params": { + "task_id":9, + "link_id":1, + "title":"New title" + } +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 1123562620 +} +``` + +## getExternalTaskLinkById + +- Purpose: **Get an external task link** +- Parameters: + - **task_id** (integer, required) + - **link_id** (integer, required) +- Result on success: **dict** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"getExternalTaskLinkById","id":2107066744,"params":[9,1]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": { + "id": "1", + "link_type": "attachment", + "dependency": "related", + "title": "document.pdf", + "url": "http:\/\/localhost\/document.pdf", + "date_creation": "1466965256", + "date_modification": "1466965256", + "task_id": "9", + "creator_id": "0" + }, + "id": 2107066744 +} +``` + +## getAllExternalTaskLinks + +- Purpose: **Get all external links attached to a task** +- Parameters: + - **task_id** (integer, required) +- Result on success: **list of external links** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"getAllExternalTaskLinks","id":2069307223,"params":[9]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": [ + { + "id": "1", + "link_type": "attachment", + "dependency": "related", + "title": "New title", + "url": "http:\/\/localhost\/document.pdf", + "date_creation": "1466965256", + "date_modification": "1466965256", + "task_id": "9", + "creator_id": "0", + "creator_name": null, + "creator_username": null, + "dependency_label": "Related", + "type": "Attachment" + } + ], + "id": 2069307223 +} +``` + +## removeExternalTaskLink + +- Purpose: **Remove an external link** +- Parameters: + - **task_id** (integer, required) + - **link_id** (integer, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"removeExternalTaskLink","id":552055660,"params":[9,1]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 552055660 +} +``` diff --git a/doc/api-internal-task-link-procedures.markdown b/doc/api-internal-task-link-procedures.markdown new file mode 100644 index 00000000..859228de --- /dev/null +++ b/doc/api-internal-task-link-procedures.markdown @@ -0,0 +1,187 @@ +Internal Task Links API Procedures +================================== + +## createTaskLink + +- Purpose: **Create a link between two tasks** +- Parameters: + - **task_id** (integer, required) + - **opposite_task_id** (integer, required) + - **link_id** (integer, required) +- Result on success: **task_link_id** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "createTaskLink", + "id": 509742912, + "params": [ + 2, + 3, + 1 + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 509742912, + "result": 1 +} +``` + +## updateTaskLink + +- Purpose: **Update task link** +- Parameters: + - **task_link_id** (integer, required) + - **task_id** (integer, required) + - **opposite_task_id** (integer, required) + - **link_id** (integer, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "updateTaskLink", + "id": 669037109, + "params": [ + 1, + 2, + 4, + 2 + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 669037109, + "result": true +} +``` + +## getTaskLinkById + +- Purpose: **Get a task link** +- Parameters: + - **task_link_id** (integer, required) +- Result on success: **task link properties** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getTaskLinkById", + "id": 809885202, + "params": [ + 1 + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 809885202, + "result": { + "id": "1", + "link_id": "1", + "task_id": "2", + "opposite_task_id": "3" + } +} +``` + +## getAllTaskLinks + +- Purpose: **Get all links related to a task** +- Parameters: + - **task_id** (integer, required) +- Result on success: **list of task link** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getAllTaskLinks", + "id": 810848359, + "params": [ + 2 + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 810848359, + "result": [ + { + "id": "1", + "task_id": "3", + "label": "relates to", + "title": "B", + "is_active": "1", + "project_id": "1", + "task_time_spent": "0", + "task_time_estimated": "0", + "task_assignee_id": "0", + "task_assignee_username": null, + "task_assignee_name": null, + "column_title": "Backlog" + } + ] +} +``` + +## removeTaskLink + +- Purpose: **Remove a link between two tasks** +- Parameters: + - **task_link_id** (integer, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "removeTaskLink", + "id": 473028226, + "params": [ + 1 + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 473028226, + "result": true +} +``` diff --git a/doc/api-json-rpc.markdown b/doc/api-json-rpc.markdown index 0f922a7c..8e783e71 100644 --- a/doc/api-json-rpc.markdown +++ b/doc/api-json-rpc.markdown @@ -60,6 +60,8 @@ Usage - [Subtasks](api-subtask-procedures.markdown) - [Files](api-file-procedures.markdown) - [Links](api-link-procedures.markdown) +- [Internal Task Links](api-internal-task-link-procedures.markdown) +- [External Task Links](api-external-task-link-procedures.markdown) - [Comments](api-comment-procedures.markdown) - [Users](api-user-procedures.markdown) - [Groups](api-group-procedures.markdown) diff --git a/doc/api-link-procedures.markdown b/doc/api-link-procedures.markdown index 6113316f..44e78a2a 100644 --- a/doc/api-link-procedures.markdown +++ b/doc/api-link-procedures.markdown @@ -283,188 +283,3 @@ Response example: "result": true } ``` - -## createTaskLink - -- Purpose: **Create a link between two tasks** -- Parameters: - - **task_id** (integer, required) - - **opposite_task_id** (integer, required) - - **link_id** (integer, required) -- Result on success: **task_link_id** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "createTaskLink", - "id": 509742912, - "params": [ - 2, - 3, - 1 - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 509742912, - "result": 1 -} -``` - -## updateTaskLink - -- Purpose: **Update task link** -- Parameters: - - **task_link_id** (integer, required) - - **task_id** (integer, required) - - **opposite_task_id** (integer, required) - - **link_id** (integer, required) -- Result on success: **true** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "updateTaskLink", - "id": 669037109, - "params": [ - 1, - 2, - 4, - 2 - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 669037109, - "result": true -} -``` - -## getTaskLinkById - -- Purpose: **Get a task link** -- Parameters: - - **task_link_id** (integer, required) -- Result on success: **task link properties** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "getTaskLinkById", - "id": 809885202, - "params": [ - 1 - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 809885202, - "result": { - "id": "1", - "link_id": "1", - "task_id": "2", - "opposite_task_id": "3" - } -} -``` - -## getAllTaskLinks - -- Purpose: **Get all links related to a task** -- Parameters: - - **task_id** (integer, required) -- Result on success: **list of task link** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "getAllTaskLinks", - "id": 810848359, - "params": [ - 2 - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 810848359, - "result": [ - { - "id": "1", - "task_id": "3", - "label": "relates to", - "title": "B", - "is_active": "1", - "project_id": "1", - "task_time_spent": "0", - "task_time_estimated": "0", - "task_assignee_id": "0", - "task_assignee_username": null, - "task_assignee_name": null, - "column_title": "Backlog" - } - ] -} -``` - -## removeTaskLink - -- Purpose: **Remove a link between two tasks** -- Parameters: - - **task_link_id** (integer, required) -- Result on success: **true** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "removeTaskLink", - "id": 473028226, - "params": [ - 1 - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 473028226, - "result": true -} -``` diff --git a/tests/integration/TaskExternalLinkProcedureTest.php b/tests/integration/TaskExternalLinkProcedureTest.php new file mode 100644 index 00000000..47ff53ad --- /dev/null +++ b/tests/integration/TaskExternalLinkProcedureTest.php @@ -0,0 +1,98 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertGetExternalTaskLinkTypes(); + $this->assertGetExternalTaskLinkProviderDependencies(); + $this->assertGetExternalTaskLinkProviderDependenciesWithProviderNotFound(); + $this->assertCreateExternalTaskLink(); + $this->assertUpdateExternalTaskLink(); + $this->assertGetAllExternalTaskLinks(); + $this->assertRemoveExternalTaskLink(); + } + + public function assertGetExternalTaskLinkTypes() + { + $expected = array( + 'auto' => 'Auto', + 'attachment' => 'Attachment', + 'file' => 'Local File', + 'weblink' => 'Web Link', + ); + + $types = $this->app->getExternalTaskLinkTypes(); + $this->assertEquals($expected, $types); + } + + public function assertGetExternalTaskLinkProviderDependencies() + { + $expected = array( + 'related' => 'Related', + ); + + $dependencies = $this->app->getExternalTaskLinkProviderDependencies('weblink'); + + $this->assertEquals($expected, $dependencies); + } + + public function assertGetExternalTaskLinkProviderDependenciesWithProviderNotFound() + { + $this->assertFalse($this->app->getExternalTaskLinkProviderDependencies('foobar')); + } + + public function assertCreateExternalTaskLink() + { + $url = 'http://localhost/document.pdf'; + $this->linkId = $this->app->createExternalTaskLink($this->taskId, $url, 'related', 'attachment'); + $this->assertNotFalse($this->linkId); + + $link = $this->app->getExternalTaskLinkById($this->taskId, $this->linkId); + $this->assertEquals($this->linkId, $link['id']); + $this->assertEquals($this->taskId, $link['task_id']); + $this->assertEquals('document.pdf', $link['title']); + $this->assertEquals($url, $link['url']); + $this->assertEquals('related', $link['dependency']); + $this->assertEquals(0, $link['creator_id']); + } + + public function assertUpdateExternalTaskLink() + { + $this->assertTrue($this->app->updateExternalTaskLink(array( + 'task_id' => $this->taskId, + 'link_id' => $this->linkId, + 'title' => 'New title', + ))); + + $link = $this->app->getExternalTaskLinkById($this->taskId, $this->linkId); + $this->assertEquals($this->linkId, $link['id']); + $this->assertEquals($this->taskId, $link['task_id']); + $this->assertEquals('New title', $link['title']); + $this->assertEquals('related', $link['dependency']); + $this->assertEquals(0, $link['creator_id']); + } + + public function assertGetAllExternalTaskLinks() + { + $links = $this->app->getAllExternalTaskLinks($this->taskId); + $this->assertCount(1, $links); + $this->assertEquals($this->linkId, $links[0]['id']); + $this->assertEquals($this->taskId, $links[0]['task_id']); + $this->assertEquals('New title', $links[0]['title']); + $this->assertEquals('related', $links[0]['dependency']); + $this->assertEquals(0, $links[0]['creator_id']); + } + + public function assertRemoveExternalTaskLink() + { + $this->assertTrue($this->app->removeExternalTaskLink($this->taskId, $this->linkId)); + } +} -- cgit v1.2.3 From f62112983635a281108575bb69bb90df6bed68b7 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 15:17:38 -0400 Subject: Added new API calls for project attachements --- ChangeLog | 2 +- app/Api/Procedure/ProjectFileProcedure.php | 68 +++++++ app/Api/Procedure/SubtaskTimeTrackingProcedure.php | 6 +- app/Api/Procedure/TaskFileProcedure.php | 4 +- app/ServiceProvider/ApiProvider.php | 2 + app/ServiceProvider/AuthenticationProvider.php | 1 + doc/api-file-procedures.markdown | 217 -------------------- doc/api-json-rpc.markdown | 3 +- doc/api-project-file-procedures.markdown | 221 +++++++++++++++++++++ doc/api-task-file-procedures.markdown | 217 ++++++++++++++++++++ tests/docker/entrypoint.sh | 2 +- tests/integration/ProjectFileProcedureTest.php | 66 ++++++ tests/integration/TaskFileProcedureTest.php | 2 +- 13 files changed, 585 insertions(+), 226 deletions(-) create mode 100644 app/Api/Procedure/ProjectFileProcedure.php delete mode 100644 doc/api-file-procedures.markdown create mode 100644 doc/api-project-file-procedures.markdown create mode 100644 doc/api-task-file-procedures.markdown create mode 100644 tests/integration/ProjectFileProcedureTest.php (limited to 'app/Api/Procedure') diff --git a/ChangeLog b/ChangeLog index 85966ed8..7a56139c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,7 @@ New features: * Added application and project roles validation for API procedure calls * Added new API call: "getProjectByIdentifier" -* Added new API calls for external task links +* Added new API calls for external task links, project attachments Improvements: diff --git a/app/Api/Procedure/ProjectFileProcedure.php b/app/Api/Procedure/ProjectFileProcedure.php new file mode 100644 index 00000000..48466ce3 --- /dev/null +++ b/app/Api/Procedure/ProjectFileProcedure.php @@ -0,0 +1,68 @@ +container)->check($this->getClassName(), 'getProjectFile', $project_id); + return $this->projectFileModel->getById($file_id); + } + + public function getAllProjectFiles($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'getAllProjectFiles', $project_id); + return $this->projectFileModel->getAll($project_id); + } + + public function downloadProjectFile($project_id, $file_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'downloadProjectFile', $project_id); + + try { + $file = $this->projectFileModel->getById($file_id); + + if (! empty($file)) { + return base64_encode($this->objectStorage->get($file['path'])); + } + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + + return ''; + } + + public function createProjectFile($project_id, $filename, $blob) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'createProjectFile', $project_id); + + try { + return $this->projectFileModel->uploadContent($project_id, $filename, $blob); + } catch (ObjectStorageException $e) { + $this->logger->error(__METHOD__.': '.$e->getMessage()); + return false; + } + } + + public function removeProjectFile($project_id, $file_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeProjectFile', $project_id); + return $this->projectFileModel->remove($file_id); + } + + public function removeAllProjectFiles($project_id) + { + ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'removeAllProjectFiles', $project_id); + return $this->projectFileModel->removeAll($project_id); + } +} diff --git a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php index 5d1988d6..b6d1102a 100644 --- a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php +++ b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php @@ -5,7 +5,7 @@ namespace Kanboard\Api\Procedure; use Kanboard\Api\Authorization\SubtaskAuthorization; /** - * Subtask Time Tracking API controller + * Subtask Time Tracking API controller * * @package Kanboard\Api\Procedure * @author Frederic Guillot @@ -25,13 +25,13 @@ class SubtaskTimeTrackingProcedure extends BaseProcedure return $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $user_id); } - public function logSubtaskEndTime($subtask_id,$user_id) + public function logSubtaskEndTime($subtask_id, $user_id) { SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskEndTime', $subtask_id); return $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $user_id); } - public function getSubtaskTimeSpent($subtask_id,$user_id) + public function getSubtaskTimeSpent($subtask_id, $user_id) { SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'getSubtaskTimeSpent', $subtask_id); return $this->subtaskTimeTrackingModel->getTimeSpent($subtask_id, $user_id); diff --git a/app/Api/Procedure/TaskFileProcedure.php b/app/Api/Procedure/TaskFileProcedure.php index 5aa7ea0b..bd006578 100644 --- a/app/Api/Procedure/TaskFileProcedure.php +++ b/app/Api/Procedure/TaskFileProcedure.php @@ -30,7 +30,7 @@ class TaskFileProcedure extends BaseProcedure public function downloadTaskFile($file_id) { TaskFileAuthorization::getInstance($this->container)->check($this->getClassName(), 'downloadTaskFile', $file_id); - + try { $file = $this->taskFileModel->getById($file_id); @@ -51,7 +51,7 @@ class TaskFileProcedure extends BaseProcedure try { return $this->taskFileModel->uploadContent($task_id, $filename, $blob); } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); + $this->logger->error(__METHOD__.': '.$e->getMessage()); return false; } } diff --git a/app/ServiceProvider/ApiProvider.php b/app/ServiceProvider/ApiProvider.php index 194bee5b..5cf6231c 100644 --- a/app/ServiceProvider/ApiProvider.php +++ b/app/ServiceProvider/ApiProvider.php @@ -9,6 +9,7 @@ use Kanboard\Api\Procedure\BoardProcedure; use Kanboard\Api\Procedure\CategoryProcedure; use Kanboard\Api\Procedure\ColumnProcedure; use Kanboard\Api\Procedure\CommentProcedure; +use Kanboard\Api\Procedure\ProjectFileProcedure; use Kanboard\Api\Procedure\TaskExternalLinkProcedure; use Kanboard\Api\Procedure\TaskFileProcedure; use Kanboard\Api\Procedure\GroupProcedure; @@ -58,6 +59,7 @@ class ApiProvider implements ServiceProviderInterface ->withObject(new CategoryProcedure($container)) ->withObject(new CommentProcedure($container)) ->withObject(new TaskFileProcedure($container)) + ->withObject(new ProjectFileProcedure($container)) ->withObject(new LinkProcedure($container)) ->withObject(new ProjectProcedure($container)) ->withObject(new ProjectPermissionProcedure($container)) diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index 34b81b9d..978bc05b 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -202,6 +202,7 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('SubtaskProcedure', '*', Role::PROJECT_MEMBER); $acl->add('SubtaskTimeTrackingProcedure', '*', Role::PROJECT_MEMBER); $acl->add('SwimlaneProcedure', '*', Role::PROJECT_MANAGER); + $acl->add('ProjectFileProcedure', '*', Role::PROJECT_MEMBER); $acl->add('TaskFileProcedure', '*', Role::PROJECT_MEMBER); $acl->add('TaskLinkProcedure', '*', Role::PROJECT_MEMBER); $acl->add('TaskExternalLinkProcedure', array('createExternalTaskLink', 'updateExternalTaskLink', 'removeExternalTaskLink'), Role::PROJECT_MEMBER); diff --git a/doc/api-file-procedures.markdown b/doc/api-file-procedures.markdown deleted file mode 100644 index 930be733..00000000 --- a/doc/api-file-procedures.markdown +++ /dev/null @@ -1,217 +0,0 @@ -API File Procedures -=================== - -## createTaskFile - -- Purpose: **Create and upload a new task attachment** -- Parameters: - - **project_id** (integer, required) - - **task_id** (integer, required) - - **filename** (integer, required) - - **blob** File content encoded in base64 (string, required) -- Result on success: **file_id** -- Result on failure: **false** -- Note: **The maximum file size depends of your PHP configuration, this method should not be used to upload large files** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "createTaskFile", - "id": 94500810, - "params": [ - 1, - 1, - "My file", - "cGxhaW4gdGV4dCBmaWxl" - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 94500810, - "result": 1 -} -``` - -## getAllTaskFiles - -- Purpose: **Get all files attached to task** -- Parameters: - - **task_id** (integer, required) -- Result on success: **list of files** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "getAllTaskFiles", - "id": 1880662820, - "params": { - "task_id": 1 - } -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 1880662820, - "result": [ - { - "id": "1", - "name": "My file", - "path": "1\/1\/0db4d0a897a4c852f6e12f0239d4805f7b4ab596", - "is_image": "0", - "task_id": "1", - "date": "1432509941", - "user_id": "0", - "size": "15", - "username": null, - "user_name": null - } - ] -} -``` - -## getTaskFile - -- Purpose: **Get file information** -- Parameters: - - **file_id** (integer, required) -- Result on success: **file properties** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "getTaskFile", - "id": 318676852, - "params": [ - "1" - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 318676852, - "result": { - "id": "1", - "name": "My file", - "path": "1\/1\/0db4d0a897a4c852f6e12f0239d4805f7b4ab596", - "is_image": "0", - "task_id": "1", - "date": "1432509941", - "user_id": "0", - "size": "15" - } -} -``` - -## downloadTaskFile - -- Purpose: **Download file contents (encoded in base64)** -- Parameters: - - **file_id** (integer, required) -- Result on success: **base64 encoded string** -- Result on failure: **empty string** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "downloadTaskFile", - "id": 235943344, - "params": [ - "1" - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 235943344, - "result": "cGxhaW4gdGV4dCBmaWxl" -} -``` - -## removeTaskFile - -- Purpose: **Remove file** -- Parameters: - - **file_id** (integer, required) -- Result on success: **true** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "removeTaskFile", - "id": 447036524, - "params": [ - "1" - ] -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 447036524, - "result": true -} -``` - -## removeAllTaskFiles - -- Purpose: **Remove all files associated to a task** -- Parameters: - - **task_id** (integer, required) -- Result on success: **true** -- Result on failure: **false** - -Request example: - -```json -{ - "jsonrpc": "2.0", - "method": "removeAllTaskFiles", - "id": 593312993, - "params": { - "task_id": 1 - } -} -``` - -Response example: - -```json -{ - "jsonrpc": "2.0", - "id": 593312993, - "result": true -} -``` diff --git a/doc/api-json-rpc.markdown b/doc/api-json-rpc.markdown index 8e783e71..6498b0cc 100644 --- a/doc/api-json-rpc.markdown +++ b/doc/api-json-rpc.markdown @@ -58,7 +58,8 @@ Usage - [Automatic Actions](api-action-procedures.markdown) - [Tasks](api-task-procedures.markdown) - [Subtasks](api-subtask-procedures.markdown) -- [Files](api-file-procedures.markdown) +- [Task Files](api-task-file-procedures.markdown) +- [Project Files](api-project-file-procedures.markdown) - [Links](api-link-procedures.markdown) - [Internal Task Links](api-internal-task-link-procedures.markdown) - [External Task Links](api-external-task-link-procedures.markdown) diff --git a/doc/api-project-file-procedures.markdown b/doc/api-project-file-procedures.markdown new file mode 100644 index 00000000..fdc5da1a --- /dev/null +++ b/doc/api-project-file-procedures.markdown @@ -0,0 +1,221 @@ +Project File API Procedures +=========================== + +## createProjectFile + +- Purpose: **Create and upload a new project attachment** +- Parameters: + - **project_id** (integer, required) + - **filename** (integer, required) + - **blob** File content encoded in base64 (string, required) +- Result on success: **file_id** +- Result on failure: **false** +- Note: **The maximum file size depends of your PHP configuration, this method should not be used to upload large files** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "createProjectFile", + "id": 94500810, + "params": [ + 1, + "My file", + "cGxhaW4gdGV4dCBmaWxl" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 94500810, + "result": 1 +} +``` + +## getAllProjectFiles + +- Purpose: **Get all files attached to a project** +- Parameters: + - **project_id** (integer, required) +- Result on success: **list of files** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getAllProjectFiles", + "id": 1880662820, + "params": { + "project_id": 1 + } +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 1880662820, + "result": [ + { + "id": "1", + "name": "My file", + "path": "1\/1\/0db4d0a897a4c852f6e12f0239d4805f7b4ab596", + "is_image": "0", + "project_id": "1", + "date": "1432509941", + "user_id": "0", + "size": "15", + "username": null, + "user_name": null + } + ] +} +``` + +## getProjectFile + +- Purpose: **Get file information** +- Parameters: + - **project_id** (integer, required) + - **file_id** (integer, required) +- Result on success: **file properties** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getProjectFile", + "id": 318676852, + "params": [ + "42", + "1" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 318676852, + "result": { + "id": "1", + "name": "My file", + "path": "1\/1\/0db4d0a897a4c852f6e12f0239d4805f7b4ab596", + "is_image": "0", + "project_id": "1", + "date": "1432509941", + "user_id": "0", + "size": "15" + } +} +``` + +## downloadProjectFile + +- Purpose: **Download project file contents (encoded in base64)** +- Parameters: + - **project_id** (integer, required) + - **file_id** (integer, required) +- Result on success: **base64 encoded string** +- Result on failure: **empty string** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "downloadProjectFile", + "id": 235943344, + "params": [ + "1", + "1" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 235943344, + "result": "cGxhaW4gdGV4dCBmaWxl" +} +``` + +## removeProjectFile + +- Purpose: **Remove a file associated to a project** +- Parameters: + - **project_id** (integer, required) + - **file_id** (integer, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "removeProjectFile", + "id": 447036524, + "params": [ + "1", + "1" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 447036524, + "result": true +} +``` + +## removeAllProjectFiles + +- Purpose: **Remove all files associated to a project** +- Parameters: + - **project_id** (integer, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "removeAllProjectFiles", + "id": 593312993, + "params": { + "project_id": 1 + } +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 593312993, + "result": true +} +``` diff --git a/doc/api-task-file-procedures.markdown b/doc/api-task-file-procedures.markdown new file mode 100644 index 00000000..51840bea --- /dev/null +++ b/doc/api-task-file-procedures.markdown @@ -0,0 +1,217 @@ +Task File API Procedures +======================== + +## createTaskFile + +- Purpose: **Create and upload a new task attachment** +- Parameters: + - **project_id** (integer, required) + - **task_id** (integer, required) + - **filename** (integer, required) + - **blob** File content encoded in base64 (string, required) +- Result on success: **file_id** +- Result on failure: **false** +- Note: **The maximum file size depends of your PHP configuration, this method should not be used to upload large files** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "createTaskFile", + "id": 94500810, + "params": [ + 1, + 1, + "My file", + "cGxhaW4gdGV4dCBmaWxl" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 94500810, + "result": 1 +} +``` + +## getAllTaskFiles + +- Purpose: **Get all files attached to task** +- Parameters: + - **task_id** (integer, required) +- Result on success: **list of files** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getAllTaskFiles", + "id": 1880662820, + "params": { + "task_id": 1 + } +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 1880662820, + "result": [ + { + "id": "1", + "name": "My file", + "path": "1\/1\/0db4d0a897a4c852f6e12f0239d4805f7b4ab596", + "is_image": "0", + "task_id": "1", + "date": "1432509941", + "user_id": "0", + "size": "15", + "username": null, + "user_name": null + } + ] +} +``` + +## getTaskFile + +- Purpose: **Get file information** +- Parameters: + - **file_id** (integer, required) +- Result on success: **file properties** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "getTaskFile", + "id": 318676852, + "params": [ + "1" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 318676852, + "result": { + "id": "1", + "name": "My file", + "path": "1\/1\/0db4d0a897a4c852f6e12f0239d4805f7b4ab596", + "is_image": "0", + "task_id": "1", + "date": "1432509941", + "user_id": "0", + "size": "15" + } +} +``` + +## downloadTaskFile + +- Purpose: **Download file contents (encoded in base64)** +- Parameters: + - **file_id** (integer, required) +- Result on success: **base64 encoded string** +- Result on failure: **empty string** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "downloadTaskFile", + "id": 235943344, + "params": [ + "1" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 235943344, + "result": "cGxhaW4gdGV4dCBmaWxl" +} +``` + +## removeTaskFile + +- Purpose: **Remove file** +- Parameters: + - **file_id** (integer, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "removeTaskFile", + "id": 447036524, + "params": [ + "1" + ] +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 447036524, + "result": true +} +``` + +## removeAllTaskFiles + +- Purpose: **Remove all files associated to a task** +- Parameters: + - **task_id** (integer, required) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{ + "jsonrpc": "2.0", + "method": "removeAllTaskFiles", + "id": 593312993, + "params": { + "task_id": 1 + } +} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "id": 593312993, + "result": true +} +``` diff --git a/tests/docker/entrypoint.sh b/tests/docker/entrypoint.sh index a88c7ed8..5a37ae4e 100755 --- a/tests/docker/entrypoint.sh +++ b/tests/docker/entrypoint.sh @@ -23,7 +23,7 @@ case "$1" in /var/www/html/vendor/phpunit/phpunit/phpunit -c /var/www/html/tests/integration.sqlite.xml ;; "integration-test-postgres") - wait_schema_creation 5 + wait_schema_creation 10 /var/www/html/vendor/phpunit/phpunit/phpunit -c /var/www/html/tests/integration.postgres.xml ;; "integration-test-mysql") diff --git a/tests/integration/ProjectFileProcedureTest.php b/tests/integration/ProjectFileProcedureTest.php new file mode 100644 index 00000000..8ac70d87 --- /dev/null +++ b/tests/integration/ProjectFileProcedureTest.php @@ -0,0 +1,66 @@ +assertCreateTeamProject(); + $this->assertCreateProjectFile(); + $this->assertGetProjectFile(); + $this->assertDownloadProjectFile(); + $this->assertGetAllFiles(); + $this->assertRemoveProjectFile(); + $this->assertRemoveAllProjectFiles(); + } + + public function assertCreateProjectFile() + { + $this->fileId = $this->app->createProjectFile($this->projectId, 'My file.txt', base64_encode('plain text file')); + $this->assertNotFalse($this->fileId); + } + + public function assertGetProjectFile() + { + $file = $this->app->getProjectFile($this->projectId, $this->fileId); + $this->assertNotEmpty($file); + $this->assertEquals('My file.txt', $file['name']); + } + + public function assertDownloadProjectFile() + { + $content = $this->app->downloadProjectFile($this->projectId, $this->fileId); + $this->assertNotEmpty($content); + $this->assertEquals('plain text file', base64_decode($content)); + } + + public function assertGetAllFiles() + { + $files = $this->app->getAllProjectFiles($this->projectId); + $this->assertCount(1, $files); + $this->assertEquals('My file.txt', $files[0]['name']); + } + + public function assertRemoveProjectFile() + { + $this->assertTrue($this->app->removeProjectFile($this->projectId, $this->fileId)); + + $files = $this->app->getAllProjectFiles($this->projectId); + $this->assertEmpty($files); + } + + public function assertRemoveAllProjectFiles() + { + $this->assertCreateProjectFile(); + $this->assertCreateProjectFile(); + + $this->assertTrue($this->app->removeAllProjectFiles($this->projectId)); + + $files = $this->app->getAllProjectFiles($this->projectId); + $this->assertEmpty($files); + } +} diff --git a/tests/integration/TaskFileProcedureTest.php b/tests/integration/TaskFileProcedureTest.php index 61155555..60909ecd 100644 --- a/tests/integration/TaskFileProcedureTest.php +++ b/tests/integration/TaskFileProcedureTest.php @@ -21,7 +21,7 @@ class TaskFileProcedureTest extends BaseProcedureTest public function assertCreateTaskFile() { - $this->fileId = $this->app->createTaskFile(1, $this->taskId, 'My file', base64_encode('plain text file')); + $this->fileId = $this->app->createTaskFile($this->projectId, $this->taskId, 'My file', base64_encode('plain text file')); $this->assertNotFalse($this->fileId); } -- cgit v1.2.3 From 82623f1a212a3a79507ede69586c561efa675224 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 15:47:02 -0400 Subject: Added API calls for subtask time tracking --- ChangeLog | 2 +- app/Api/Procedure/SubtaskTimeTrackingProcedure.php | 8 +- doc/api-json-rpc.markdown | 1 + doc/api-subtask-time-tracking-procedures.markdown | 102 +++++++++++++++++++++ tests/integration/BaseProcedureTest.php | 11 +++ tests/integration/SubtaskProcedureTest.php | 11 --- .../SubtaskTimeTrackingProcedureTest.php | 46 ++++++++++ 7 files changed, 165 insertions(+), 16 deletions(-) create mode 100644 doc/api-subtask-time-tracking-procedures.markdown create mode 100644 tests/integration/SubtaskTimeTrackingProcedureTest.php (limited to 'app/Api/Procedure') diff --git a/ChangeLog b/ChangeLog index 7a56139c..eccff6a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,7 @@ New features: * Added application and project roles validation for API procedure calls * Added new API call: "getProjectByIdentifier" -* Added new API calls for external task links, project attachments +* Added new API calls for external task links, project attachments and subtask time tracking Improvements: diff --git a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php index b6d1102a..5ceaa08d 100644 --- a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php +++ b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php @@ -19,15 +19,15 @@ class SubtaskTimeTrackingProcedure extends BaseProcedure return $this->subtaskTimeTrackingModel->hasTimer($subtask_id, $user_id); } - public function logSubtaskStartTime($subtask_id, $user_id) + public function setSubtaskStartTime($subtask_id, $user_id) { - SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskStartTime', $subtask_id); + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'setSubtaskStartTime', $subtask_id); return $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $user_id); } - public function logSubtaskEndTime($subtask_id, $user_id) + public function setSubtaskEndTime($subtask_id, $user_id) { - SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskEndTime', $subtask_id); + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'setSubtaskEndTime', $subtask_id); return $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $user_id); } diff --git a/doc/api-json-rpc.markdown b/doc/api-json-rpc.markdown index 6498b0cc..ab1056f0 100644 --- a/doc/api-json-rpc.markdown +++ b/doc/api-json-rpc.markdown @@ -58,6 +58,7 @@ Usage - [Automatic Actions](api-action-procedures.markdown) - [Tasks](api-task-procedures.markdown) - [Subtasks](api-subtask-procedures.markdown) +- [Subtask Time Tracking](api-subtask-time-tracking-procedures.markdown) - [Task Files](api-task-file-procedures.markdown) - [Project Files](api-project-file-procedures.markdown) - [Links](api-link-procedures.markdown) diff --git a/doc/api-subtask-time-tracking-procedures.markdown b/doc/api-subtask-time-tracking-procedures.markdown new file mode 100644 index 00000000..67447623 --- /dev/null +++ b/doc/api-subtask-time-tracking-procedures.markdown @@ -0,0 +1,102 @@ +Subtask Time Tracking API procedures +==================================== + +## hasSubtaskTimer + +- Purpose: **Check if a timer is started for the given subtask and user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"hasSubtaskTimer","id":1786995697,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 1786995697 +} +``` + +## setSubtaskStartTime + +- Purpose: **Start subtask timer for a user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"setSubtaskStartTime","id":1168991769,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 1168991769 +} +``` + +## setSubtaskEndTime + +- Purpose: **Stop subtask timer for a user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"setSubtaskEndTime","id":1026607603,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 1026607603 +} +``` + +## getSubtaskTimeSpent + +- Purpose: **Get time spent on a subtask for a user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **number of hours** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"getSubtaskTimeSpent","id":738527378,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": 1.5, + "id": 738527378 +} +``` diff --git a/tests/integration/BaseProcedureTest.php b/tests/integration/BaseProcedureTest.php index e3382e82..beb13ff7 100644 --- a/tests/integration/BaseProcedureTest.php +++ b/tests/integration/BaseProcedureTest.php @@ -17,6 +17,7 @@ abstract class BaseProcedureTest extends PHPUnit_Framework_TestCase protected $projectId = 0; protected $taskTitle = 'My task'; protected $taskId = 0; + protected $subtaskId = 0; protected $groupName1 = 'My Group A'; protected $groupName2 = 'My Group B'; @@ -119,4 +120,14 @@ abstract class BaseProcedureTest extends PHPUnit_Framework_TestCase $this->taskId = $this->app->createTask(array('title' => $this->taskTitle, 'project_id' => $this->projectId)); $this->assertNotFalse($this->taskId); } + + public function assertCreateSubtask() + { + $this->subtaskId = $this->app->createSubtask(array( + 'task_id' => $this->taskId, + 'title' => 'subtask #1', + )); + + $this->assertNotFalse($this->subtaskId); + } } diff --git a/tests/integration/SubtaskProcedureTest.php b/tests/integration/SubtaskProcedureTest.php index 7ab4ef0b..b9868e6f 100644 --- a/tests/integration/SubtaskProcedureTest.php +++ b/tests/integration/SubtaskProcedureTest.php @@ -5,7 +5,6 @@ require_once __DIR__.'/BaseProcedureTest.php'; class SubtaskProcedureTest extends BaseProcedureTest { protected $projectName = 'My project to test subtasks'; - private $subtaskId = 0; public function testAll() { @@ -18,16 +17,6 @@ class SubtaskProcedureTest extends BaseProcedureTest $this->assertRemoveSubtask(); } - public function assertCreateSubtask() - { - $this->subtaskId = $this->app->createSubtask(array( - 'task_id' => $this->taskId, - 'title' => 'subtask #1', - )); - - $this->assertNotFalse($this->subtaskId); - } - public function assertGetSubtask() { $subtask = $this->app->getSubtask($this->subtaskId); diff --git a/tests/integration/SubtaskTimeTrackingProcedureTest.php b/tests/integration/SubtaskTimeTrackingProcedureTest.php new file mode 100644 index 00000000..6c45c983 --- /dev/null +++ b/tests/integration/SubtaskTimeTrackingProcedureTest.php @@ -0,0 +1,46 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertCreateSubtask(); + $this->assertHasNoTimer(); + $this->assertStartTimer(); + $this->assertHasTimer(); + $this->assertStopTimer(); + $this->assertHasNoTimer(); + $this->assertGetSubtaskTimeSpent(); + } + + public function assertHasNoTimer() + { + $this->assertFalse($this->app->hasSubtaskTimer($this->subtaskId, $this->userUserId)); + } + + public function assertHasTimer() + { + $this->assertTrue($this->app->hasSubtaskTimer($this->subtaskId, $this->userUserId)); + } + + public function assertStartTimer() + { + $this->assertTrue($this->app->setSubtaskStartTime($this->subtaskId, $this->userUserId)); + } + + public function assertStopTimer() + { + $this->assertTrue($this->app->setSubtaskEndTime($this->subtaskId, $this->userUserId)); + } + + public function assertGetSubtaskTimeSpent() + { + $this->assertEquals(0, $this->app->getSubtaskTimeSpent($this->subtaskId, $this->userUserId)); + } +} -- cgit v1.2.3 From 3fcc0cb9183f9ff32ce7a3c615258bcf53c385ed Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 2 Jul 2016 14:44:26 -0400 Subject: Handle tags and tasks move/duplication to another project --- app/Action/TaskDuplicateAnotherProject.php | 2 +- app/Action/TaskMoveAnotherProject.php | 2 +- app/Api/Procedure/TaskProcedure.php | 4 +- app/Controller/TaskDuplicationController.php | 4 +- app/Core/Base.php | 4 + app/Model/TagDuplicationModel.php | 67 +++ app/Model/TaskDuplicationModel.php | 156 +---- app/Model/TaskModel.php | 2 +- app/Model/TaskProjectDuplicationModel.php | 60 ++ app/Model/TaskProjectMoveModel.php | 67 +++ app/Model/TaskRecurrenceModel.php | 87 +++ app/Model/TaskTagModel.php | 17 + app/ServiceProvider/ClassProvider.php | 4 + app/Subscriber/RecurringTaskSubscriber.php | 6 +- tests/units/Model/TaskDuplicationTest.php | 667 ++------------------- .../Model/TaskProjectDuplicationModelTest.php | 369 ++++++++++++ tests/units/Model/TaskProjectMoveModelTest.php | 269 +++++++++ tests/units/Model/TaskRecurrenceModelTest.php | 90 +++ tests/units/Model/TaskTagModelTest.php | 21 + 19 files changed, 1121 insertions(+), 777 deletions(-) create mode 100644 app/Model/TagDuplicationModel.php create mode 100644 app/Model/TaskProjectDuplicationModel.php create mode 100644 app/Model/TaskProjectMoveModel.php create mode 100644 app/Model/TaskRecurrenceModel.php create mode 100644 tests/units/Model/TaskProjectDuplicationModelTest.php create mode 100644 tests/units/Model/TaskProjectMoveModelTest.php create mode 100644 tests/units/Model/TaskRecurrenceModelTest.php (limited to 'app/Api/Procedure') diff --git a/app/Action/TaskDuplicateAnotherProject.php b/app/Action/TaskDuplicateAnotherProject.php index 1d4a2f13..d70d2ee8 100644 --- a/app/Action/TaskDuplicateAnotherProject.php +++ b/app/Action/TaskDuplicateAnotherProject.php @@ -76,7 +76,7 @@ class TaskDuplicateAnotherProject extends Base public function doAction(array $data) { $destination_column_id = $this->columnModel->getFirstColumnId($this->getParam('project_id')); - return (bool) $this->taskDuplicationModel->duplicateToProject($data['task_id'], $this->getParam('project_id'), null, $destination_column_id); + return (bool) $this->taskProjectDuplicationModel->duplicateToProject($data['task_id'], $this->getParam('project_id'), null, $destination_column_id); } /** diff --git a/app/Action/TaskMoveAnotherProject.php b/app/Action/TaskMoveAnotherProject.php index 73ad4b69..66635a63 100644 --- a/app/Action/TaskMoveAnotherProject.php +++ b/app/Action/TaskMoveAnotherProject.php @@ -75,7 +75,7 @@ class TaskMoveAnotherProject extends Base */ public function doAction(array $data) { - return $this->taskDuplicationModel->moveToProject($data['task_id'], $this->getParam('project_id')); + return $this->taskProjectMoveModel->moveToProject($data['task_id'], $this->getParam('project_id')); } /** diff --git a/app/Api/Procedure/TaskProcedure.php b/app/Api/Procedure/TaskProcedure.php index 2d29a4ef..8661deef 100644 --- a/app/Api/Procedure/TaskProcedure.php +++ b/app/Api/Procedure/TaskProcedure.php @@ -77,13 +77,13 @@ class TaskProcedure extends BaseProcedure public function moveTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) { ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'moveTaskToProject', $project_id); - return $this->taskDuplicationModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + return $this->taskProjectMoveModel->moveToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); } public function duplicateTaskToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) { ProjectAuthorization::getInstance($this->container)->check($this->getClassName(), 'duplicateTaskToProject', $project_id); - return $this->taskDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + return $this->taskProjectDuplicationModel->duplicateToProject($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); } public function createTask($title, $project_id, $color_id = '', $column_id = 0, $owner_id = 0, $creator_id = 0, diff --git a/app/Controller/TaskDuplicationController.php b/app/Controller/TaskDuplicationController.php index 6a475374..915bf8f8 100644 --- a/app/Controller/TaskDuplicationController.php +++ b/app/Controller/TaskDuplicationController.php @@ -50,7 +50,7 @@ class TaskDuplicationController extends BaseController $values = $this->request->getValues(); list($valid, ) = $this->taskValidator->validateProjectModification($values); - if ($valid && $this->taskDuplicationModel->moveToProject($task['id'], + if ($valid && $this->taskProjectMoveModel->moveToProject($task['id'], $values['project_id'], $values['swimlane_id'], $values['column_id'], @@ -80,7 +80,7 @@ class TaskDuplicationController extends BaseController list($valid, ) = $this->taskValidator->validateProjectModification($values); if ($valid) { - $task_id = $this->taskDuplicationModel->duplicateToProject( + $task_id = $this->taskProjectDuplicationModel->duplicateToProject( $task['id'], $values['project_id'], $values['swimlane_id'], $values['column_id'], $values['category_id'], $values['owner_id'] ); diff --git a/app/Core/Base.php b/app/Core/Base.php index eacca65d..a8274152 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -90,11 +90,15 @@ use Pimple\Container; * @property \Kanboard\Model\SubtaskModel $subtaskModel * @property \Kanboard\Model\SubtaskTimeTrackingModel $subtaskTimeTrackingModel * @property \Kanboard\Model\SwimlaneModel $swimlaneModel + * @property \Kanboard\Model\TagDuplicationModel $tagDuplicationModel * @property \Kanboard\Model\TagModel $tagModel * @property \Kanboard\Model\TaskModel $taskModel * @property \Kanboard\Model\TaskAnalyticModel $taskAnalyticModel * @property \Kanboard\Model\TaskCreationModel $taskCreationModel * @property \Kanboard\Model\TaskDuplicationModel $taskDuplicationModel + * @property \Kanboard\Model\TaskProjectDuplicationModel $taskProjectDuplicationModel + * @property \Kanboard\Model\TaskProjectMoveModel $taskProjectMoveModel + * @property \Kanboard\Model\TaskRecurrenceModel $taskRecurrenceModel * @property \Kanboard\Model\TaskExternalLinkModel $taskExternalLinkModel * @property \Kanboard\Model\TaskFinderModel $taskFinderModel * @property \Kanboard\Model\TaskLinkModel $taskLinkModel diff --git a/app/Model/TagDuplicationModel.php b/app/Model/TagDuplicationModel.php new file mode 100644 index 00000000..1876391d --- /dev/null +++ b/app/Model/TagDuplicationModel.php @@ -0,0 +1,67 @@ +taskTagModel->getTagsByTask($src_task_id); + + foreach ($tags as $tag) { + $tag_id = $this->tagModel->getIdByName($dst_project_id, $tag['name']); + + if ($tag_id) { + $this->taskTagModel->associateTag($dst_task_id, $tag_id); + } + } + } + + /** + * Duplicate tags to the new task + * + * @access public + * @param integer $src_task_id + * @param integer $dst_task_id + */ + public function duplicateTaskTags($src_task_id, $dst_task_id) + { + $tags = $this->taskTagModel->getTagsByTask($src_task_id); + + foreach ($tags as $tag) { + $this->taskTagModel->associateTag($dst_task_id, $tag['id']); + } + } + + /** + * Remove tags that are not available in destination project + * + * @access public + * @param integer $task_id + * @param integer $dst_project_id + */ + public function syncTaskTagsToAnotherProject($task_id, $dst_project_id) + { + $tag_ids = $this->taskTagModel->getTagIdsByTaskNotAvailableInProject($task_id, $dst_project_id); + + foreach ($tag_ids as $tag_id) { + $this->taskTagModel->dissociateTag($task_id, $tag_id); + } + } +} diff --git a/app/Model/TaskDuplicationModel.php b/app/Model/TaskDuplicationModel.php index 9a4613e2..0dce891f 100644 --- a/app/Model/TaskDuplicationModel.php +++ b/app/Model/TaskDuplicationModel.php @@ -2,10 +2,7 @@ namespace Kanboard\Model; -use DateTime; -use DateInterval; use Kanboard\Core\Base; -use Kanboard\Event\TaskEvent; /** * Task Duplication @@ -18,10 +15,10 @@ class TaskDuplicationModel extends Base /** * Fields to copy when duplicating a task * - * @access private - * @var array + * @access protected + * @var string[] */ - private $fields_to_duplicate = array( + protected $fields_to_duplicate = array( 'title', 'description', 'date_due', @@ -49,106 +46,13 @@ class TaskDuplicationModel extends Base */ public function duplicate($task_id) { - return $this->save($task_id, $this->copyFields($task_id)); - } - - /** - * Duplicate recurring task - * - * @access public - * @param integer $task_id Task id - * @return boolean|integer Recurrence task id - */ - public function duplicateRecurringTask($task_id) - { - $values = $this->copyFields($task_id); - - if ($values['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) { - $values['recurrence_parent'] = $task_id; - $values['column_id'] = $this->columnModel->getFirstColumnId($values['project_id']); - $this->calculateRecurringTaskDueDate($values); - - $recurring_task_id = $this->save($task_id, $values); - - if ($recurring_task_id > 0) { - $parent_update = $this->db - ->table(TaskModel::TABLE) - ->eq('id', $task_id) - ->update(array( - 'recurrence_status' => TaskModel::RECURRING_STATUS_PROCESSED, - 'recurrence_child' => $recurring_task_id, - )); - - if ($parent_update) { - return $recurring_task_id; - } - } - } - - return false; - } - - /** - * Duplicate a task to another project - * - * @access public - * @param integer $task_id - * @param integer $project_id - * @param integer $swimlane_id - * @param integer $column_id - * @param integer $category_id - * @param integer $owner_id - * @return boolean|integer - */ - public function duplicateToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) - { - $values = $this->copyFields($task_id); - $values['project_id'] = $project_id; - $values['column_id'] = $column_id !== null ? $column_id : $values['column_id']; - $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $values['swimlane_id']; - $values['category_id'] = $category_id !== null ? $category_id : $values['category_id']; - $values['owner_id'] = $owner_id !== null ? $owner_id : $values['owner_id']; - - $this->checkDestinationProjectValues($values); - - return $this->save($task_id, $values); - } + $new_task_id = $this->save($task_id, $this->copyFields($task_id)); - /** - * Move a task to another project - * - * @access public - * @param integer $task_id - * @param integer $project_id - * @param integer $swimlane_id - * @param integer $column_id - * @param integer $category_id - * @param integer $owner_id - * @return boolean - */ - public function moveToProject($task_id, $project_id, $swimlane_id = null, $column_id = null, $category_id = null, $owner_id = null) - { - $task = $this->taskFinderModel->getById($task_id); - - $values = array(); - $values['is_active'] = 1; - $values['project_id'] = $project_id; - $values['column_id'] = $column_id !== null ? $column_id : $task['column_id']; - $values['position'] = $this->taskFinderModel->countByColumnId($project_id, $values['column_id']) + 1; - $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $task['swimlane_id']; - $values['category_id'] = $category_id !== null ? $category_id : $task['category_id']; - $values['owner_id'] = $owner_id !== null ? $owner_id : $task['owner_id']; - - $this->checkDestinationProjectValues($values); - - if ($this->db->table(TaskModel::TABLE)->eq('id', $task['id'])->update($values)) { - $this->container['dispatcher']->dispatch( - TaskModel::EVENT_MOVE_PROJECT, - new TaskEvent(array_merge($task, $values, array('task_id' => $task['id']))) - ); + if ($new_task_id !== false) { + $this->tagDuplicationModel->duplicateTaskTags($task_id, $new_task_id); } - return true; + return $new_task_id; } /** @@ -194,50 +98,14 @@ class TaskDuplicationModel extends Base return $values; } - /** - * Calculate new due date for new recurrence task - * - * @access public - * @param array $values Task fields - */ - public function calculateRecurringTaskDueDate(array &$values) - { - if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { - if ($values['recurrence_basedate'] == TaskModel::RECURRING_BASEDATE_TRIGGERDATE) { - $values['date_due'] = time(); - } - - $factor = abs($values['recurrence_factor']); - $subtract = $values['recurrence_factor'] < 0; - - switch ($values['recurrence_timeframe']) { - case TaskModel::RECURRING_TIMEFRAME_MONTHS: - $interval = 'P' . $factor . 'M'; - break; - case TaskModel::RECURRING_TIMEFRAME_YEARS: - $interval = 'P' . $factor . 'Y'; - break; - default: - $interval = 'P' . $factor . 'D'; - } - - $date_due = new DateTime(); - $date_due->setTimestamp($values['date_due']); - - $subtract ? $date_due->sub(new DateInterval($interval)) : $date_due->add(new DateInterval($interval)); - - $values['date_due'] = $date_due->getTimestamp(); - } - } - /** * Duplicate fields for the new task * - * @access private + * @access protected * @param integer $task_id Task id * @return array */ - private function copyFields($task_id) + protected function copyFields($task_id) { $task = $this->taskFinderModel->getById($task_id); $values = array(); @@ -252,16 +120,16 @@ class TaskDuplicationModel extends Base /** * Create the new task and duplicate subtasks * - * @access private + * @access protected * @param integer $task_id Task id * @param array $values Form values * @return boolean|integer */ - private function save($task_id, array $values) + protected function save($task_id, array $values) { $new_task_id = $this->taskCreationModel->create($values); - if ($new_task_id) { + if ($new_task_id !== false) { $this->subtaskModel->duplicate($task_id, $new_task_id); } diff --git a/app/Model/TaskModel.php b/app/Model/TaskModel.php index b0e7772a..b945ee44 100644 --- a/app/Model/TaskModel.php +++ b/app/Model/TaskModel.php @@ -215,7 +215,7 @@ class TaskModel extends Base $task_ids = $this->taskFinderModel->getAllIds($src_project_id, array(TaskModel::STATUS_OPEN, TaskModel::STATUS_CLOSED)); foreach ($task_ids as $task_id) { - if (! $this->taskDuplicationModel->duplicateToProject($task_id, $dst_project_id)) { + if (! $this->taskProjectDuplicationModel->duplicateToProject($task_id, $dst_project_id)) { return false; } } diff --git a/app/Model/TaskProjectDuplicationModel.php b/app/Model/TaskProjectDuplicationModel.php new file mode 100644 index 00000000..8ebed255 --- /dev/null +++ b/app/Model/TaskProjectDuplicationModel.php @@ -0,0 +1,60 @@ +prepare($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id); + $this->checkDestinationProjectValues($values); + $new_task_id = $this->save($task_id, $values); + + if ($new_task_id !== false) { + $this->tagDuplicationModel->duplicateTaskTagsToAnotherProject($task_id, $new_task_id, $project_id); + } + + return $new_task_id; + } + + /** + * Prepare values before duplication + * + * @access protected + * @param integer $task_id + * @param integer $project_id + * @param integer $swimlane_id + * @param integer $column_id + * @param integer $category_id + * @param integer $owner_id + * @return array + */ + protected function prepare($task_id, $project_id, $swimlane_id, $column_id, $category_id, $owner_id) + { + $values = $this->copyFields($task_id); + $values['project_id'] = $project_id; + $values['column_id'] = $column_id !== null ? $column_id : $values['column_id']; + $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $values['swimlane_id']; + $values['category_id'] = $category_id !== null ? $category_id : $values['category_id']; + $values['owner_id'] = $owner_id !== null ? $owner_id : $values['owner_id']; + return $values; + } +} diff --git a/app/Model/TaskProjectMoveModel.php b/app/Model/TaskProjectMoveModel.php new file mode 100644 index 00000000..7e9714d6 --- /dev/null +++ b/app/Model/TaskProjectMoveModel.php @@ -0,0 +1,67 @@ +taskFinderModel->getById($task_id); + $values = $this->prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, $task); + + $this->checkDestinationProjectValues($values); + $this->tagDuplicationModel->syncTaskTagsToAnotherProject($task_id, $project_id); + + if ($this->db->table(TaskModel::TABLE)->eq('id', $task['id'])->update($values)) { + $event = new TaskEvent(array_merge($task, $values, array('task_id' => $task['id']))); + $this->dispatcher->dispatch(TaskModel::EVENT_MOVE_PROJECT, $event); + } + + return true; + } + + /** + * Prepare new task values + * + * @access protected + * @param integer $project_id + * @param integer $swimlane_id + * @param integer $column_id + * @param integer $category_id + * @param integer $owner_id + * @param array $task + * @return array + */ + protected function prepare($project_id, $swimlane_id, $column_id, $category_id, $owner_id, array $task) + { + $values = array(); + $values['is_active'] = 1; + $values['project_id'] = $project_id; + $values['column_id'] = $column_id !== null ? $column_id : $task['column_id']; + $values['position'] = $this->taskFinderModel->countByColumnId($project_id, $values['column_id']) + 1; + $values['swimlane_id'] = $swimlane_id !== null ? $swimlane_id : $task['swimlane_id']; + $values['category_id'] = $category_id !== null ? $category_id : $task['category_id']; + $values['owner_id'] = $owner_id !== null ? $owner_id : $task['owner_id']; + return $values; + } +} diff --git a/app/Model/TaskRecurrenceModel.php b/app/Model/TaskRecurrenceModel.php new file mode 100644 index 00000000..a5f2ab90 --- /dev/null +++ b/app/Model/TaskRecurrenceModel.php @@ -0,0 +1,87 @@ +copyFields($task_id); + + if ($values['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) { + $values['recurrence_parent'] = $task_id; + $values['column_id'] = $this->columnModel->getFirstColumnId($values['project_id']); + $this->calculateRecurringTaskDueDate($values); + + $recurring_task_id = $this->save($task_id, $values); + + if ($recurring_task_id > 0) { + $parent_update = $this->db + ->table(TaskModel::TABLE) + ->eq('id', $task_id) + ->update(array( + 'recurrence_status' => TaskModel::RECURRING_STATUS_PROCESSED, + 'recurrence_child' => $recurring_task_id, + )); + + if ($parent_update) { + return $recurring_task_id; + } + } + } + + return false; + } + + /** + * Calculate new due date for new recurrence task + * + * @access public + * @param array $values Task fields + */ + public function calculateRecurringTaskDueDate(array &$values) + { + if (! empty($values['date_due']) && $values['recurrence_factor'] != 0) { + if ($values['recurrence_basedate'] == TaskModel::RECURRING_BASEDATE_TRIGGERDATE) { + $values['date_due'] = time(); + } + + $factor = abs($values['recurrence_factor']); + $subtract = $values['recurrence_factor'] < 0; + + switch ($values['recurrence_timeframe']) { + case TaskModel::RECURRING_TIMEFRAME_MONTHS: + $interval = 'P' . $factor . 'M'; + break; + case TaskModel::RECURRING_TIMEFRAME_YEARS: + $interval = 'P' . $factor . 'Y'; + break; + default: + $interval = 'P' . $factor . 'D'; + } + + $date_due = new DateTime(); + $date_due->setTimestamp($values['date_due']); + + $subtract ? $date_due->sub(new DateInterval($interval)) : $date_due->add(new DateInterval($interval)); + + $values['date_due'] = $date_due->getTimestamp(); + } + } +} diff --git a/app/Model/TaskTagModel.php b/app/Model/TaskTagModel.php index 2a08e867..0553cc6c 100644 --- a/app/Model/TaskTagModel.php +++ b/app/Model/TaskTagModel.php @@ -19,6 +19,23 @@ class TaskTagModel extends Base */ const TABLE = 'task_has_tags'; + /** + * Get all tags not available in a project + * + * @access public + * @param integer $task_id + * @param integer $project_id + * @return array + */ + public function getTagIdsByTaskNotAvailableInProject($task_id, $project_id) + { + return $this->db->table(TagModel::TABLE) + ->eq(self::TABLE.'.task_id', $task_id) + ->notIn(TagModel::TABLE.'.project_id', array(0, $project_id)) + ->join(self::TABLE, 'tag_id', 'id') + ->findAllByColumn(TagModel::TABLE.'.id'); + } + /** * Get all tags associated to a task * diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index c0fb93bd..1f584fca 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -60,11 +60,15 @@ class ClassProvider implements ServiceProviderInterface 'SubtaskModel', 'SubtaskTimeTrackingModel', 'SwimlaneModel', + 'TagDuplicationModel', 'TagModel', 'TaskModel', 'TaskAnalyticModel', 'TaskCreationModel', 'TaskDuplicationModel', + 'TaskProjectDuplicationModel', + 'TaskProjectMoveModel', + 'TaskRecurrenceModel', 'TaskExternalLinkModel', 'TaskFinderModel', 'TaskFileModel', diff --git a/app/Subscriber/RecurringTaskSubscriber.php b/app/Subscriber/RecurringTaskSubscriber.php index 75b7ff76..21cd3996 100644 --- a/app/Subscriber/RecurringTaskSubscriber.php +++ b/app/Subscriber/RecurringTaskSubscriber.php @@ -22,9 +22,9 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING) { if ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_FIRST_COLUMN && $this->columnModel->getFirstColumnId($event['project_id']) == $event['src_column_id']) { - $this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); + $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']); } elseif ($event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_LAST_COLUMN && $this->columnModel->getLastColumnId($event['project_id']) == $event['dst_column_id']) { - $this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); + $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']); } } } @@ -34,7 +34,7 @@ class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberI $this->logger->debug('Subscriber executed: '.__METHOD__); if ($event['recurrence_status'] == TaskModel::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == TaskModel::RECURRING_TRIGGER_CLOSE) { - $this->taskDuplicationModel->duplicateRecurringTask($event['task_id']); + $this->taskRecurrenceModel->duplicateRecurringTask($event['task_id']); } } } diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php index 79b75e54..7ce851d0 100644 --- a/tests/units/Model/TaskDuplicationTest.php +++ b/tests/units/Model/TaskDuplicationTest.php @@ -2,31 +2,27 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Core\DateParser; use Kanboard\Model\TaskModel; use Kanboard\Model\TaskCreationModel; use Kanboard\Model\TaskDuplicationModel; use Kanboard\Model\TaskFinderModel; use Kanboard\Model\ProjectModel; -use Kanboard\Model\ProjectUserRoleModel; use Kanboard\Model\CategoryModel; -use Kanboard\Model\UserModel; -use Kanboard\Model\SwimlaneModel; -use Kanboard\Core\Security\Role; +use Kanboard\Model\TaskTagModel; class TaskDuplicationTest extends Base { public function testThatDuplicateDefineCreator() { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); + $taskDuplicationModel = new TaskDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1))); - $task = $tf->getById(1); + $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['position']); $this->assertEquals(1, $task['project_id']); @@ -35,37 +31,41 @@ class TaskDuplicationTest extends Base $this->container['sessionStorage']->user = array('id' => 1); // We duplicate our task - $this->assertEquals(2, $td->duplicate(1)); + $this->assertEquals(2, $taskDuplicationModel->duplicate(1)); // Check the values of the duplicated task - $task = $tf->getById(2); + $task = $taskFinderModel->getById(2); $this->assertNotEmpty($task); $this->assertEquals(1, $task['creator_id']); } public function testDuplicateSameProject() { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $c = new CategoryModel($this->container); + $taskDuplicationModel = new TaskDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); // We create a task and a project - $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); // Some categories - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1))); - $this->assertTrue($c->exists(1)); - $this->assertTrue($c->exists(2)); + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 1))); + $this->assertTrue($categoryModel->exists(1)); + $this->assertTrue($categoryModel->exists(2)); - $this->assertEquals( - 1, - $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2, 'time_spent' => 4.4) - )); + $this->assertEquals(1, $taskCreationModel->create(array( + 'title' => 'test', + 'project_id' => 1, + 'column_id' => 3, + 'owner_id' => 1, + 'category_id' => 2, + 'time_spent' => 4.4 + ))); - $task = $tf->getById(1); + $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['position']); $this->assertEquals(1, $task['project_id']); @@ -77,14 +77,14 @@ class TaskDuplicationTest extends Base $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); // We duplicate our task - $this->assertEquals(2, $td->duplicate(1)); + $this->assertEquals(2, $taskDuplicationModel->duplicate(1)); $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); // Check the values of the duplicated task - $task = $tf->getById(2); + $task = $taskFinderModel->getById(2); $this->assertNotEmpty($task); $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); $this->assertEquals(1, $task['project_id']); @@ -97,604 +97,25 @@ class TaskDuplicationTest extends Base $this->assertEquals(0, $task['time_spent']); } - public function testDuplicateAnotherProject() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $c = new CategoryModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertTrue($c->exists(1)); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); - - $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); - $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $td->duplicateToProject(1, 2)); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); - $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals(0, $task['swimlane_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testDuplicateAnotherProjectWithCategory() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $c = new CategoryModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2))); - $this->assertTrue($c->exists(1)); - $this->assertTrue($c->exists(2)); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $td->duplicateToProject(1, 2)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(2, $task['category_id']); - $this->assertEquals(0, $task['swimlane_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testDuplicateAnotherProjectWithPredefinedCategory() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $c = new CategoryModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2))); - $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 2))); - $this->assertTrue($c->exists(1)); - $this->assertTrue($c->exists(2)); - $this->assertTrue($c->exists(3)); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); - - // We duplicate our task to the 2nd project with no category - $this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, 0)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['category_id']); - - // We duplicate our task to the 2nd project with a different category - $this->assertEquals(3, $td->duplicateToProject(1, 2, null, null, 3)); - - // Check the values of the duplicated task - $task = $tf->getById(3); - $this->assertNotEmpty($task); - $this->assertEquals(3, $task['category_id']); - } - - public function testDuplicateAnotherProjectWithSwimlane() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $s = new SwimlaneModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); - $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $td->duplicateToProject(1, 2)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals(2, $task['swimlane_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testDuplicateAnotherProjectWithoutSwimlane() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $s = new SwimlaneModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); - $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $td->duplicateToProject(1, 2)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals(0, $task['swimlane_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testDuplicateAnotherProjectWithPredefinedSwimlane() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $s = new SwimlaneModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); - $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1'))); - $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $td->duplicateToProject(1, 2, 3)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(3, $task['swimlane_id']); - } - - public function testDuplicateAnotherProjectWithPredefinedColumn() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2))); - - // We duplicate our task to the 2nd project with a different column - $this->assertEquals(2, $td->duplicateToProject(1, 2, null, 7)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(7, $task['column_id']); - } - - public function testDuplicateAnotherProjectWithUser() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $pp = new ProjectUserRoleModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $td->duplicateToProject(1, 2)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - - // We create a new user for our project - $user = new UserModel($this->container); - $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); - $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); - - // We duplicate our task to the 2nd project - $this->assertEquals(3, $td->duplicateToProject(1, 2)); - - // Check the values of the duplicated task - $task = $tf->getById(3); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['position']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(2, $task['owner_id']); - $this->assertEquals(2, $task['project_id']); - - // We duplicate a task with a not allowed user - $this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3))); - $this->assertEquals(5, $td->duplicateToProject(4, 2)); - - $task = $tf->getById(5); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['position']); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals(5, $task['column_id']); - } - - public function testDuplicateAnotherProjectWithPredefinedUser() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $pr = new ProjectUserRoleModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); - $this->assertTrue($pr->addUser(2, 1, Role::PROJECT_MEMBER)); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, null, 1)); - - // Check the values of the duplicated task - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['owner_id']); - } - - public function onMoveProject($event) - { - $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event); - - $event_data = $event->getAll(); - $this->assertNotEmpty($event_data); - $this->assertEquals(1, $event_data['task_id']); - $this->assertEquals('test', $event_data['title']); - } - - public function testMoveAnotherProject() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $user = new UserModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333))); - - $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject')); - - // We duplicate our task to the 2nd project - $this->assertTrue($td->moveToProject(1, 2)); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called); - - // Check the values of the moved task - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals(0, $task['swimlane_id']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals(5, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals('test', $task['title']); - } - - public function testMoveAnotherProjectWithCategory() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $c = new CategoryModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1))); - $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2))); - $this->assertTrue($c->exists(1)); - $this->assertTrue($c->exists(2)); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); - - // We move our task to the 2nd project - $this->assertTrue($td->moveToProject(1, 2)); - - // Check the values of the duplicated task - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(2, $task['category_id']); - $this->assertEquals(0, $task['swimlane_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testMoveAnotherProjectWithUser() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $pp = new ProjectUserRoleModel($this->container); - $user = new UserModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - // We create a new user for our project - $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); - $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); - - // We move our task to the 2nd project - $this->assertTrue($td->moveToProject(1, 2)); - - // Check the values of the moved task - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['owner_id']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals(6, $task['column_id']); - } - - public function testMoveAnotherProjectWithForbiddenUser() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $pp = new ProjectUserRoleModel($this->container); - $user = new UserModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - // We create a new user for our project - $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); - $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3))); - - // We move our task to the 2nd project - $this->assertTrue($td->moveToProject(1, 2)); - - // Check the values of the moved task - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['position']); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals(6, $task['column_id']); - } - - public function testMoveAnotherProjectWithSwimlane() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $s = new SwimlaneModel($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); - $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); - - // We move our task to the 2nd project - $this->assertTrue($td->moveToProject(1, 2)); - - // Check the values of the moved task - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals(2, $task['swimlane_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testMoveAnotherProjectWithoutSwimlane() + public function testDuplicateSameProjectWitTags() { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $s = new SwimlaneModel($this->container); + $taskDuplicationModel = new TaskDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $projectModel = new ProjectModel($this->container); + $taskTagModel = new TaskTagModel($this->container); - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertNotFalse($s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); - $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #2'))); - - // We create a task - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); - - // We move our task to the 2nd project - $this->assertTrue($td->moveToProject(1, 2)); - - // Check the values of the moved task - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals(0, $task['swimlane_id']); - $this->assertEquals(6, $task['column_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testCalculateRecurringTaskDueDate() - { - $td = new TaskDuplicationModel($this->container); - - $values = array('date_due' => 0); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(0, $values['date_due']); - - $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(0, $values['date_due']); - - $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(time() + 86400, $values['date_due'], '', 1); - - $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1); - - $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1); - - $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1); - - $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(1436561776, $values['date_due'], '', 1); - - $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS); - $td->calculateRecurringTaskDueDate($values); - $this->assertEquals(1494449776, $values['date_due'], '', 1); - } - - public function testDuplicateRecurringTask() - { - $td = new TaskDuplicationModel($this->container); - $tc = new TaskCreationModel($this->container); - $tf = new TaskFinderModel($this->container); - $p = new ProjectModel($this->container); - $dp = new DateParser($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - - $this->assertEquals(1, $tc->create(array( + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array( 'title' => 'test', 'project_id' => 1, - 'date_due' => 1436561776, - 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING, - 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE, - 'recurrence_factor' => 2, - 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS, - 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, + 'tags' => array('T1', 'T2') ))); - $this->assertEquals(2, $td->duplicateRecurringTask(1)); + $this->assertEquals(2, $taskDuplicationModel->duplicate(1)); - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); - $this->assertEquals(2, $task['recurrence_child']); - $this->assertEquals(1436486400, $task['date_due'], '', 2); - - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']); - $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); - $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); - $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); - $this->assertEquals(1, $task['recurrence_parent']); - $this->assertEquals(2, $task['recurrence_factor']); - $this->assertEquals($dp->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2); + $tags = $taskTagModel->getList(2); + $this->assertCount(2, $tags); + $this->assertArrayHasKey(1, $tags); + $this->assertArrayHasKey(2, $tags); } } diff --git a/tests/units/Model/TaskProjectDuplicationModelTest.php b/tests/units/Model/TaskProjectDuplicationModelTest.php new file mode 100644 index 00000000..798257ba --- /dev/null +++ b/tests/units/Model/TaskProjectDuplicationModelTest.php @@ -0,0 +1,369 @@ +container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertTrue($categoryModel->exists(1)); + + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1))); + + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {}); + $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {}); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called); + $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testDuplicateAnotherProjectWithCategory() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2))); + $this->assertTrue($categoryModel->exists(1)); + $this->assertTrue($categoryModel->exists(2)); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(2, $task['category_id']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testDuplicateAnotherProjectWithPredefinedCategory() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2))); + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 2))); + $this->assertTrue($categoryModel->exists(1)); + $this->assertTrue($categoryModel->exists(2)); + $this->assertTrue($categoryModel->exists(3)); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); + + // We duplicate our task to the 2nd project with no category + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 0)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['category_id']); + + // We duplicate our task to the 2nd project with a different category + $this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 3)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(3); + $this->assertNotEmpty($task); + $this->assertEquals(3, $task['category_id']); + } + + public function testDuplicateAnotherProjectWithSwimlane() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(2, $task['swimlane_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testDuplicateAnotherProjectWithoutSwimlane() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testDuplicateAnotherProjectWithPredefinedSwimlane() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1'))); + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, 3)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(3, $task['swimlane_id']); + } + + public function testDuplicateAnotherProjectWithPredefinedColumn() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2))); + + // We duplicate our task to the 2nd project with a different column + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, 7)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(7, $task['column_id']); + } + + public function testDuplicateAnotherProjectWithUser() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + + // We create a new user for our project + $user = new UserModel($this->container); + $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + + // We duplicate our task to the 2nd project + $this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(3); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['position']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(2, $task['owner_id']); + $this->assertEquals(2, $task['project_id']); + + // We duplicate a task with a not allowed user + $this->assertEquals(4, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3))); + $this->assertEquals(5, $taskProjectDuplicationModel->duplicateToProject(4, 2)); + + $task = $taskFinderModel->getById(5); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['position']); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals(5, $task['column_id']); + } + + public function testDuplicateAnotherProjectWithPredefinedUser() + { + $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); + $this->assertTrue($projectUserRoleModel->addUser(2, 1, Role::PROJECT_MEMBER)); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, null, 1)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['owner_id']); + } + + public function testDuplicateAnotherProjectWithDifferentTags() + { + $taskProjectMoveModel = new TaskProjectDuplicationModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $tagModel = new TagModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create our tags for each projects + $this->assertEquals(1, $tagModel->create(1, 'T1')); + $this->assertEquals(2, $tagModel->create(1, 'T2')); + $this->assertEquals(3, $tagModel->create(2, 'T2')); + $this->assertEquals(4, $tagModel->create(2, 'T3')); + $this->assertEquals(5, $tagModel->create(0, 'T4')); + $this->assertEquals(6, $tagModel->create(0, 'T5')); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T2', 'T5')))); + + // We move our task to the 2nd project + $this->assertEquals(2, $taskProjectMoveModel->duplicateToProject(1, 2)); + + // Check the values of the moved task + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['id']); + $this->assertEquals(2, $task['project_id']); + + // Check tags + $tags = $taskTagModel->getList(2); + $this->assertCount(2, $tags); + $this->assertArrayHasKey(3, $tags); + $this->assertArrayHasKey(6, $tags); + } +} diff --git a/tests/units/Model/TaskProjectMoveModelTest.php b/tests/units/Model/TaskProjectMoveModelTest.php new file mode 100644 index 00000000..ed6c0c3c --- /dev/null +++ b/tests/units/Model/TaskProjectMoveModelTest.php @@ -0,0 +1,269 @@ +assertInstanceOf('Kanboard\Event\TaskEvent', $event); + + $event_data = $event->getAll(); + $this->assertNotEmpty($event_data); + $this->assertEquals(1, $event_data['task_id']); + $this->assertEquals('test', $event_data['title']); + } + + public function testMoveAnotherProject() + { + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333))); + + $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject')); + + // We duplicate our task to the 2nd project + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2)); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskProjectMoveModelTest::onMoveProject', $called); + + // Check the values of the moved task + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals(5, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals('test', $task['title']); + } + + public function testMoveAnotherProjectWithCategory() + { + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new CategoryModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1))); + $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2))); + $this->assertTrue($categoryModel->exists(1)); + $this->assertTrue($categoryModel->exists(2)); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1))); + + // We move our task to the 2nd project + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2)); + + // Check the values of the duplicated task + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(2, $task['category_id']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testMoveAnotherProjectWithUser() + { + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create a new user for our project + $this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); + + // We move our task to the 2nd project + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2)); + + // Check the values of the moved task + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['owner_id']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals(6, $task['column_id']); + } + + public function testMoveAnotherProjectWithForbiddenUser() + { + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $projectUserRoleModel = new ProjectUserRoleModel($this->container); + $userModel = new UserModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create a new user for our project + $this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3))); + + // We move our task to the 2nd project + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2)); + + // Check the values of the moved task + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['position']); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals(6, $task['column_id']); + } + + public function testMoveAnotherProjectWithSwimlane() + { + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); + + // We move our task to the 2nd project + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2)); + + // Check the values of the moved task + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(2, $task['swimlane_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testMoveAnotherProjectWithoutSwimlane() + { + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); + $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2'))); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1))); + + // We move our task to the 2nd project + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2)); + + // Check the values of the moved task + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(6, $task['column_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testMoveAnotherProjectWithDifferentTags() + { + $taskProjectMoveModel = new TaskProjectMoveModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $tagModel = new TagModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + + // We create 2 projects + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + // We create our tags for each projects + $this->assertEquals(1, $tagModel->create(1, 'T1')); + $this->assertEquals(2, $tagModel->create(1, 'T2')); + $this->assertEquals(3, $tagModel->create(2, 'T3')); + $this->assertEquals(4, $tagModel->create(2, 'T4')); + $this->assertEquals(5, $tagModel->create(0, 'T5')); + $this->assertEquals(6, $tagModel->create(0, 'T6')); + + // We create a task + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T5', 'T6')))); + + // We move our task to the 2nd project + $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2)); + + // Check the values of the moved task + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + + // Check tags + $tags = $taskTagModel->getList(1); + $this->assertCount(2, $tags); + $this->assertArrayHasKey(5, $tags); + $this->assertArrayHasKey(6, $tags); + } +} diff --git a/tests/units/Model/TaskRecurrenceModelTest.php b/tests/units/Model/TaskRecurrenceModelTest.php new file mode 100644 index 00000000..6970e30f --- /dev/null +++ b/tests/units/Model/TaskRecurrenceModelTest.php @@ -0,0 +1,90 @@ +container); + + $values = array('date_due' => 0); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(0, $values['date_due']); + + $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(0, $values['date_due']); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(time() + 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1436561776, $values['date_due'], '', 1); + + $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS); + $taskRecurrenceModel->calculateRecurringTaskDueDate($values); + $this->assertEquals(1494449776, $values['date_due'], '', 1); + } + + public function testDuplicateRecurringTask() + { + $taskRecurrenceModel = new TaskRecurrenceModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $dateParser = new DateParser($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + $this->assertEquals(1, $taskCreationModel->create(array( + 'title' => 'test', + 'project_id' => 1, + 'date_due' => 1436561776, + 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING, + 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE, + 'recurrence_factor' => 2, + 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS, + 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, + ))); + + $this->assertEquals(2, $taskRecurrenceModel->duplicateRecurringTask(1)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); + $this->assertEquals(2, $task['recurrence_child']); + $this->assertEquals(1436486400, $task['date_due'], '', 2); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']); + $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']); + $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); + $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); + $this->assertEquals(1, $task['recurrence_parent']); + $this->assertEquals(2, $task['recurrence_factor']); + $this->assertEquals($dateParser->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2); + } +} diff --git a/tests/units/Model/TaskTagModelTest.php b/tests/units/Model/TaskTagModelTest.php index 88055d5f..3485368e 100644 --- a/tests/units/Model/TaskTagModelTest.php +++ b/tests/units/Model/TaskTagModelTest.php @@ -124,4 +124,25 @@ class TaskTagModelTest extends Base $tags = $taskTagModel->getTagsByTasks(array()); $this->assertEquals(array(), $tags); } + + public function testGetTagIdNotAvailableInDestinationProject() + { + $projectModel = new ProjectModel($this->container); + $taskCreationModel = new TaskCreationModel($this->container); + $taskTagModel = new TaskTagModel($this->container); + $tagModel = new TagModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1'))); + + $this->assertEquals(1, $tagModel->create(0, 'T0')); + $this->assertEquals(2, $tagModel->create(2, 'T1')); + $this->assertEquals(3, $tagModel->create(2, 'T3')); + $this->assertEquals(4, $tagModel->create(1, 'T2')); + $this->assertEquals(5, $tagModel->create(1, 'T3')); + $this->assertTrue($taskTagModel->save(1, 1, array('T0', 'T2', 'T3'))); + + $this->assertEquals(array(4, 5), $taskTagModel->getTagIdsByTaskNotAvailableInProject(1, 2)); + } } -- cgit v1.2.3