From b1e2ca00ce7375ffcbe5e927135c8892036e6bd6 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 16 May 2016 21:07:29 -0400 Subject: Rename Api classes --- app/Api/Action.php | 85 -------------------- app/Api/ActionApi.php | 87 ++++++++++++++++++++ app/Api/App.php | 47 ----------- app/Api/AppApi.php | 49 ++++++++++++ app/Api/Auth.php | 81 ------------------- app/Api/AuthApi.php | 82 +++++++++++++++++++ app/Api/Base.php | 118 --------------------------- app/Api/BaseApi.php | 119 +++++++++++++++++++++++++++ app/Api/Board.php | 18 ----- app/Api/BoardApi.php | 18 +++++ app/Api/Category.php | 49 ------------ app/Api/CategoryApi.php | 51 ++++++++++++ app/Api/Column.php | 42 ---------- app/Api/ColumnApi.php | 42 ++++++++++ app/Api/Comment.php | 52 ------------ app/Api/CommentApi.php | 54 +++++++++++++ app/Api/File.php | 90 --------------------- app/Api/FileApi.php | 91 +++++++++++++++++++++ app/Api/Group.php | 49 ------------ app/Api/GroupApi.php | 51 ++++++++++++ app/Api/GroupMember.php | 37 --------- app/Api/GroupMemberApi.php | 39 +++++++++ app/Api/Link.php | 111 ------------------------- app/Api/LinkApi.php | 113 ++++++++++++++++++++++++++ app/Api/Me.php | 72 ----------------- app/Api/MeApi.php | 72 +++++++++++++++++ app/Api/Project.php | 87 -------------------- app/Api/ProjectApi.php | 87 ++++++++++++++++++++ app/Api/ProjectPermission.php | 72 ----------------- app/Api/ProjectPermissionApi.php | 73 +++++++++++++++++ app/Api/Subtask.php | 64 --------------- app/Api/SubtaskApi.php | 66 +++++++++++++++ app/Api/Swimlane.php | 78 ------------------ app/Api/SwimlaneApi.php | 80 ++++++++++++++++++ app/Api/Task.php | 169 --------------------------------------- app/Api/TaskApi.php | 169 +++++++++++++++++++++++++++++++++++++++ app/Api/TaskLink.php | 77 ------------------ app/Api/TaskLinkApi.php | 79 ++++++++++++++++++ app/Api/User.php | 137 ------------------------------- app/Api/UserApi.php | 138 ++++++++++++++++++++++++++++++++ 40 files changed, 1560 insertions(+), 1535 deletions(-) delete mode 100644 app/Api/Action.php create mode 100644 app/Api/ActionApi.php delete mode 100644 app/Api/App.php create mode 100644 app/Api/AppApi.php delete mode 100644 app/Api/Auth.php create mode 100644 app/Api/AuthApi.php delete mode 100644 app/Api/Base.php create mode 100644 app/Api/BaseApi.php delete mode 100644 app/Api/Board.php create mode 100644 app/Api/BoardApi.php delete mode 100644 app/Api/Category.php create mode 100644 app/Api/CategoryApi.php delete mode 100644 app/Api/Column.php create mode 100644 app/Api/ColumnApi.php delete mode 100644 app/Api/Comment.php create mode 100644 app/Api/CommentApi.php delete mode 100644 app/Api/File.php create mode 100644 app/Api/FileApi.php delete mode 100644 app/Api/Group.php create mode 100644 app/Api/GroupApi.php delete mode 100644 app/Api/GroupMember.php create mode 100644 app/Api/GroupMemberApi.php delete mode 100644 app/Api/Link.php create mode 100644 app/Api/LinkApi.php delete mode 100644 app/Api/Me.php create mode 100644 app/Api/MeApi.php delete mode 100644 app/Api/Project.php create mode 100644 app/Api/ProjectApi.php delete mode 100644 app/Api/ProjectPermission.php create mode 100644 app/Api/ProjectPermissionApi.php delete mode 100644 app/Api/Subtask.php create mode 100644 app/Api/SubtaskApi.php delete mode 100644 app/Api/Swimlane.php create mode 100644 app/Api/SwimlaneApi.php delete mode 100644 app/Api/Task.php create mode 100644 app/Api/TaskApi.php delete mode 100644 app/Api/TaskLink.php create mode 100644 app/Api/TaskLinkApi.php delete mode 100644 app/Api/User.php create mode 100644 app/Api/UserApi.php (limited to 'app/Api') diff --git a/app/Api/Action.php b/app/Api/Action.php deleted file mode 100644 index 9e3b86f6..00000000 --- a/app/Api/Action.php +++ /dev/null @@ -1,85 +0,0 @@ -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) - { - return $this->action->remove($action_id); - } - - public function getActions($project_id) - { - return $this->action->getAllByProject($project_id); - } - - public function createAction($project_id, $event_name, $action_name, array $params) - { - $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->action->create($values); - } -} diff --git a/app/Api/ActionApi.php b/app/Api/ActionApi.php new file mode 100644 index 00000000..0647f9e8 --- /dev/null +++ b/app/Api/ActionApi.php @@ -0,0 +1,87 @@ +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) + { + return $this->action->remove($action_id); + } + + public function getActions($project_id) + { + return $this->action->getAllByProject($project_id); + } + + public function createAction($project_id, $event_name, $action_name, array $params) + { + $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->action->create($values); + } +} diff --git a/app/Api/App.php b/app/Api/App.php deleted file mode 100644 index 1c4737c0..00000000 --- a/app/Api/App.php +++ /dev/null @@ -1,47 +0,0 @@ -timezone->getCurrentTimezone(); - } - - public function getVersion() - { - return APP_VERSION; - } - - public function getDefaultTaskColor() - { - return $this->color->getDefaultColor(); - } - - public function getDefaultTaskColors() - { - return $this->color->getDefaultColors(); - } - - public function getColorList() - { - return $this->color->getList(); - } - - public function getApplicationRoles() - { - return $this->role->getApplicationRoles(); - } - - public function getProjectRoles() - { - return $this->role->getProjectRoles(); - } -} diff --git a/app/Api/AppApi.php b/app/Api/AppApi.php new file mode 100644 index 00000000..865ba21a --- /dev/null +++ b/app/Api/AppApi.php @@ -0,0 +1,49 @@ +timezone->getCurrentTimezone(); + } + + public function getVersion() + { + return APP_VERSION; + } + + public function getDefaultTaskColor() + { + return $this->color->getDefaultColor(); + } + + public function getDefaultTaskColors() + { + return $this->color->getDefaultColors(); + } + + public function getColorList() + { + return $this->color->getList(); + } + + public function getApplicationRoles() + { + return $this->role->getApplicationRoles(); + } + + public function getProjectRoles() + { + return $this->role->getProjectRoles(); + } +} diff --git a/app/Api/Auth.php b/app/Api/Auth.php deleted file mode 100644 index 1cc6627f..00000000 --- a/app/Api/Auth.php +++ /dev/null @@ -1,81 +0,0 @@ -dispatcher->dispatch('app.bootstrap'); - - if ($this->isUserAuthenticated($username, $password)) { - $this->checkProcedurePermission(true, $method); - $this->userSession->initialize($this->user->getByUsername($username)); - } elseif ($this->isAppAuthenticated($username, $password)) { - $this->checkProcedurePermission(false, $method); - } else { - $this->logger->error('API authentication failure for '.$username); - throw new AuthenticationFailureException('Wrong credentials'); - } - } - - /** - * Check user credentials - * - * @access public - * @param string $username - * @param string $password - * @return boolean - */ - private function isUserAuthenticated($username, $password) - { - return $username !== 'jsonrpc' && - ! $this->userLocking->isLocked($username) && - $this->authenticationManager->passwordAuthentication($username, $password); - } - - /** - * Check administrative credentials - * - * @access public - * @param string $username - * @param string $password - * @return boolean - */ - private function isAppAuthenticated($username, $password) - { - return $username === 'jsonrpc' && $password === $this->getApiToken(); - } - - /** - * Get API Token - * - * @access private - * @return string - */ - private function getApiToken() - { - if (defined('API_AUTHENTICATION_TOKEN')) { - return API_AUTHENTICATION_TOKEN; - } - - return $this->config->get('api_token'); - } -} diff --git a/app/Api/AuthApi.php b/app/Api/AuthApi.php new file mode 100644 index 00000000..a9ad5baf --- /dev/null +++ b/app/Api/AuthApi.php @@ -0,0 +1,82 @@ +dispatcher->dispatch('app.bootstrap'); + + if ($this->isUserAuthenticated($username, $password)) { + $this->checkProcedurePermission(true, $method); + $this->userSession->initialize($this->user->getByUsername($username)); + } elseif ($this->isAppAuthenticated($username, $password)) { + $this->checkProcedurePermission(false, $method); + } else { + $this->logger->error('API authentication failure for '.$username); + throw new AuthenticationFailureException('Wrong credentials'); + } + } + + /** + * Check user credentials + * + * @access public + * @param string $username + * @param string $password + * @return boolean + */ + private function isUserAuthenticated($username, $password) + { + return $username !== 'jsonrpc' && + ! $this->userLocking->isLocked($username) && + $this->authenticationManager->passwordAuthentication($username, $password); + } + + /** + * Check administrative credentials + * + * @access public + * @param string $username + * @param string $password + * @return boolean + */ + private function isAppAuthenticated($username, $password) + { + return $username === 'jsonrpc' && $password === $this->getApiToken(); + } + + /** + * Get API Token + * + * @access private + * @return string + */ + private function getApiToken() + { + if (defined('API_AUTHENTICATION_TOKEN')) { + return API_AUTHENTICATION_TOKEN; + } + + return $this->config->get('api_token'); + } +} diff --git a/app/Api/Base.php b/app/Api/Base.php deleted file mode 100644 index ea817f7d..00000000 --- a/app/Api/Base.php +++ /dev/null @@ -1,118 +0,0 @@ -both_allowed_procedures); - $is_user_procedure = in_array($procedure, $this->user_allowed_procedures); - - if ($is_user && ! $is_both_procedure && ! $is_user_procedure) { - throw new AccessDeniedException('Permission denied'); - } elseif (! $is_user && ! $is_both_procedure && $is_user_procedure) { - throw new AccessDeniedException('Permission denied'); - } - - $this->logger->debug('API call: '.$procedure); - } - - public function checkProjectPermission($project_id) - { - if ($this->userSession->isLogged() && ! $this->projectPermission->isUserAllowed($project_id, $this->userSession->getId())) { - throw new AccessDeniedException('Permission denied'); - } - } - - public function checkTaskPermission($task_id) - { - if ($this->userSession->isLogged()) { - $this->checkProjectPermission($this->taskFinder->getProjectId($task_id)); - } - } - - protected function formatTask($task) - { - if (! empty($task)) { - $task['url'] = $this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true); - $task['color'] = $this->color->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('board', 'show', array('project_id' => $project['id']), '', true), - 'calendar' => $this->helper->url->to('calendar', 'show', array('project_id' => $project['id']), '', true), - 'list' => $this->helper->url->to('listing', '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; - } -} diff --git a/app/Api/BaseApi.php b/app/Api/BaseApi.php new file mode 100644 index 00000000..37e11030 --- /dev/null +++ b/app/Api/BaseApi.php @@ -0,0 +1,119 @@ +both_allowed_procedures); + $is_user_procedure = in_array($procedure, $this->user_allowed_procedures); + + if ($is_user && ! $is_both_procedure && ! $is_user_procedure) { + throw new AccessDeniedException('Permission denied'); + } elseif (! $is_user && ! $is_both_procedure && $is_user_procedure) { + throw new AccessDeniedException('Permission denied'); + } + + $this->logger->debug('API call: '.$procedure); + } + + public function checkProjectPermission($project_id) + { + if ($this->userSession->isLogged() && ! $this->projectPermission->isUserAllowed($project_id, $this->userSession->getId())) { + throw new AccessDeniedException('Permission denied'); + } + } + + public function checkTaskPermission($task_id) + { + if ($this->userSession->isLogged()) { + $this->checkProjectPermission($this->taskFinder->getProjectId($task_id)); + } + } + + protected function formatTask($task) + { + if (! empty($task)) { + $task['url'] = $this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), '', true); + $task['color'] = $this->color->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('board', 'show', array('project_id' => $project['id']), '', true), + 'calendar' => $this->helper->url->to('calendar', 'show', array('project_id' => $project['id']), '', true), + 'list' => $this->helper->url->to('listing', '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; + } +} diff --git a/app/Api/Board.php b/app/Api/Board.php deleted file mode 100644 index 185ac51a..00000000 --- a/app/Api/Board.php +++ /dev/null @@ -1,18 +0,0 @@ -checkProjectPermission($project_id); - return $this->board->getBoard($project_id); - } -} diff --git a/app/Api/BoardApi.php b/app/Api/BoardApi.php new file mode 100644 index 00000000..c7d93aa0 --- /dev/null +++ b/app/Api/BoardApi.php @@ -0,0 +1,18 @@ +checkProjectPermission($project_id); + return $this->board->getBoard($project_id); + } +} diff --git a/app/Api/Category.php b/app/Api/Category.php deleted file mode 100644 index fbd61c56..00000000 --- a/app/Api/Category.php +++ /dev/null @@ -1,49 +0,0 @@ -category->getById($category_id); - } - - public function getAllCategories($project_id) - { - return $this->category->getAll($project_id); - } - - public function removeCategory($category_id) - { - return $this->category->remove($category_id); - } - - public function createCategory($project_id, $name) - { - $values = array( - 'project_id' => $project_id, - 'name' => $name, - ); - - list($valid, ) = $this->categoryValidator->validateCreation($values); - return $valid ? $this->category->create($values) : false; - } - - public function updateCategory($id, $name) - { - $values = array( - 'id' => $id, - 'name' => $name, - ); - - list($valid, ) = $this->categoryValidator->validateModification($values); - return $valid && $this->category->update($values); - } -} diff --git a/app/Api/CategoryApi.php b/app/Api/CategoryApi.php new file mode 100644 index 00000000..7c5d3bfb --- /dev/null +++ b/app/Api/CategoryApi.php @@ -0,0 +1,51 @@ +category->getById($category_id); + } + + public function getAllCategories($project_id) + { + return $this->category->getAll($project_id); + } + + public function removeCategory($category_id) + { + return $this->category->remove($category_id); + } + + public function createCategory($project_id, $name) + { + $values = array( + 'project_id' => $project_id, + 'name' => $name, + ); + + list($valid, ) = $this->categoryValidator->validateCreation($values); + return $valid ? $this->category->create($values) : false; + } + + public function updateCategory($id, $name) + { + $values = array( + 'id' => $id, + 'name' => $name, + ); + + list($valid, ) = $this->categoryValidator->validateModification($values); + return $valid && $this->category->update($values); + } +} diff --git a/app/Api/Column.php b/app/Api/Column.php deleted file mode 100644 index ddc3a5d0..00000000 --- a/app/Api/Column.php +++ /dev/null @@ -1,42 +0,0 @@ -column->getAll($project_id); - } - - public function getColumn($column_id) - { - return $this->column->getById($column_id); - } - - public function updateColumn($column_id, $title, $task_limit = 0, $description = '') - { - return $this->column->update($column_id, $title, $task_limit, $description); - } - - public function addColumn($project_id, $title, $task_limit = 0, $description = '') - { - return $this->column->create($project_id, $title, $task_limit, $description); - } - - public function removeColumn($column_id) - { - return $this->column->remove($column_id); - } - - public function changeColumnPosition($project_id, $column_id, $position) - { - return $this->column->changePosition($project_id, $column_id, $position); - } -} diff --git a/app/Api/ColumnApi.php b/app/Api/ColumnApi.php new file mode 100644 index 00000000..45ce521d --- /dev/null +++ b/app/Api/ColumnApi.php @@ -0,0 +1,42 @@ +column->getAll($project_id); + } + + public function getColumn($column_id) + { + return $this->column->getById($column_id); + } + + public function updateColumn($column_id, $title, $task_limit = 0, $description = '') + { + return $this->column->update($column_id, $title, $task_limit, $description); + } + + public function addColumn($project_id, $title, $task_limit = 0, $description = '') + { + return $this->column->create($project_id, $title, $task_limit, $description); + } + + public function removeColumn($column_id) + { + return $this->column->remove($column_id); + } + + public function changeColumnPosition($project_id, $column_id, $position) + { + return $this->column->changePosition($project_id, $column_id, $position); + } +} diff --git a/app/Api/Comment.php b/app/Api/Comment.php deleted file mode 100644 index 1fc1c708..00000000 --- a/app/Api/Comment.php +++ /dev/null @@ -1,52 +0,0 @@ -comment->getById($comment_id); - } - - public function getAllComments($task_id) - { - return $this->comment->getAll($task_id); - } - - public function removeComment($comment_id) - { - return $this->comment->remove($comment_id); - } - - public function createComment($task_id, $user_id, $content, $reference = '') - { - $values = array( - 'task_id' => $task_id, - 'user_id' => $user_id, - 'comment' => $content, - 'reference' => $reference, - ); - - list($valid, ) = $this->commentValidator->validateCreation($values); - - return $valid ? $this->comment->create($values) : false; - } - - public function updateComment($id, $content) - { - $values = array( - 'id' => $id, - 'comment' => $content, - ); - - list($valid, ) = $this->commentValidator->validateModification($values); - return $valid && $this->comment->update($values); - } -} diff --git a/app/Api/CommentApi.php b/app/Api/CommentApi.php new file mode 100644 index 00000000..f16b0f7f --- /dev/null +++ b/app/Api/CommentApi.php @@ -0,0 +1,54 @@ +comment->getById($comment_id); + } + + public function getAllComments($task_id) + { + return $this->comment->getAll($task_id); + } + + public function removeComment($comment_id) + { + return $this->comment->remove($comment_id); + } + + public function createComment($task_id, $user_id, $content, $reference = '') + { + $values = array( + 'task_id' => $task_id, + 'user_id' => $user_id, + 'comment' => $content, + 'reference' => $reference, + ); + + list($valid, ) = $this->commentValidator->validateCreation($values); + + return $valid ? $this->comment->create($values) : false; + } + + public function updateComment($id, $content) + { + $values = array( + 'id' => $id, + 'comment' => $content, + ); + + list($valid, ) = $this->commentValidator->validateModification($values); + return $valid && $this->comment->update($values); + } +} diff --git a/app/Api/File.php b/app/Api/File.php deleted file mode 100644 index 71c31c76..00000000 --- a/app/Api/File.php +++ /dev/null @@ -1,90 +0,0 @@ -taskFile->getById($file_id); - } - - public function getAllTaskFiles($task_id) - { - return $this->taskFile->getAll($task_id); - } - - public function downloadTaskFile($file_id) - { - try { - $file = $this->taskFile->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) - { - try { - return $this->taskFile->uploadContent($task_id, $filename, $blob); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - return false; - } - } - - public function removeTaskFile($file_id) - { - return $this->taskFile->remove($file_id); - } - - public function removeAllTaskFiles($task_id) - { - return $this->taskFile->removeAll($task_id); - } - - // Deprecated procedures - - public function getFile($file_id) - { - return $this->getTaskFile($file_id); - } - - public function getAllFiles($task_id) - { - return $this->getAllTaskFiles($task_id); - } - - public function downloadFile($file_id) - { - return $this->downloadTaskFile($file_id); - } - - public function createFile($project_id, $task_id, $filename, $blob) - { - return $this->createTaskFile($project_id, $task_id, $filename, $blob); - } - - public function removeFile($file_id) - { - return $this->removeTaskFile($file_id); - } - - public function removeAllFiles($task_id) - { - return $this->removeAllTaskFiles($task_id); - } -} diff --git a/app/Api/FileApi.php b/app/Api/FileApi.php new file mode 100644 index 00000000..cc2e3986 --- /dev/null +++ b/app/Api/FileApi.php @@ -0,0 +1,91 @@ +taskFile->getById($file_id); + } + + public function getAllTaskFiles($task_id) + { + return $this->taskFile->getAll($task_id); + } + + public function downloadTaskFile($file_id) + { + try { + $file = $this->taskFile->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) + { + try { + return $this->taskFile->uploadContent($task_id, $filename, $blob); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + public function removeTaskFile($file_id) + { + return $this->taskFile->remove($file_id); + } + + public function removeAllTaskFiles($task_id) + { + return $this->taskFile->removeAll($task_id); + } + + // Deprecated procedures + + public function getFile($file_id) + { + return $this->getTaskFile($file_id); + } + + public function getAllFiles($task_id) + { + return $this->getAllTaskFiles($task_id); + } + + public function downloadFile($file_id) + { + return $this->downloadTaskFile($file_id); + } + + public function createFile($project_id, $task_id, $filename, $blob) + { + return $this->createTaskFile($project_id, $task_id, $filename, $blob); + } + + public function removeFile($file_id) + { + return $this->removeTaskFile($file_id); + } + + public function removeAllFiles($task_id) + { + return $this->removeAllTaskFiles($task_id); + } +} diff --git a/app/Api/Group.php b/app/Api/Group.php deleted file mode 100644 index a1e0a73d..00000000 --- a/app/Api/Group.php +++ /dev/null @@ -1,49 +0,0 @@ -group->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->group->update($values); - } - - public function removeGroup($group_id) - { - return $this->group->remove($group_id); - } - - public function getGroup($group_id) - { - return $this->group->getById($group_id); - } - - public function getAllGroups() - { - return $this->group->getAll(); - } -} diff --git a/app/Api/GroupApi.php b/app/Api/GroupApi.php new file mode 100644 index 00000000..f1841fa3 --- /dev/null +++ b/app/Api/GroupApi.php @@ -0,0 +1,51 @@ +group->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->group->update($values); + } + + public function removeGroup($group_id) + { + return $this->group->remove($group_id); + } + + public function getGroup($group_id) + { + return $this->group->getById($group_id); + } + + public function getAllGroups() + { + return $this->group->getAll(); + } +} diff --git a/app/Api/GroupMember.php b/app/Api/GroupMember.php deleted file mode 100644 index 9d2a4796..00000000 --- a/app/Api/GroupMember.php +++ /dev/null @@ -1,37 +0,0 @@ -groupMember->getGroups($user_id); - } - - public function getGroupMembers($group_id) - { - return $this->groupMember->getMembers($group_id); - } - - public function addGroupMember($group_id, $user_id) - { - return $this->groupMember->addUser($group_id, $user_id); - } - - public function removeGroupMember($group_id, $user_id) - { - return $this->groupMember->removeUser($group_id, $user_id); - } - - public function isGroupMember($group_id, $user_id) - { - return $this->groupMember->isMember($group_id, $user_id); - } -} diff --git a/app/Api/GroupMemberApi.php b/app/Api/GroupMemberApi.php new file mode 100644 index 00000000..f5171e23 --- /dev/null +++ b/app/Api/GroupMemberApi.php @@ -0,0 +1,39 @@ +groupMember->getGroups($user_id); + } + + public function getGroupMembers($group_id) + { + return $this->groupMember->getMembers($group_id); + } + + public function addGroupMember($group_id, $user_id) + { + return $this->groupMember->addUser($group_id, $user_id); + } + + public function removeGroupMember($group_id, $user_id) + { + return $this->groupMember->removeUser($group_id, $user_id); + } + + public function isGroupMember($group_id, $user_id) + { + return $this->groupMember->isMember($group_id, $user_id); + } +} diff --git a/app/Api/Link.php b/app/Api/Link.php deleted file mode 100644 index 23a9916d..00000000 --- a/app/Api/Link.php +++ /dev/null @@ -1,111 +0,0 @@ -link->getById($link_id); - } - - /** - * Get a link by name - * - * @access public - * @param string $label - * @return array - */ - public function getLinkByLabel($label) - { - return $this->link->getByLabel($label); - } - - /** - * Get the opposite link id - * - * @access public - * @param integer $link_id Link id - * @return integer - */ - public function getOppositeLinkId($link_id) - { - return $this->link->getOppositeLinkId($link_id); - } - - /** - * Get all links - * - * @access public - * @return array - */ - public function getAllLinks() - { - return $this->link->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->link->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->link->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->link->remove($link_id); - } -} diff --git a/app/Api/LinkApi.php b/app/Api/LinkApi.php new file mode 100644 index 00000000..a76cb802 --- /dev/null +++ b/app/Api/LinkApi.php @@ -0,0 +1,113 @@ +link->getById($link_id); + } + + /** + * Get a link by name + * + * @access public + * @param string $label + * @return array + */ + public function getLinkByLabel($label) + { + return $this->link->getByLabel($label); + } + + /** + * Get the opposite link id + * + * @access public + * @param integer $link_id Link id + * @return integer + */ + public function getOppositeLinkId($link_id) + { + return $this->link->getOppositeLinkId($link_id); + } + + /** + * Get all links + * + * @access public + * @return array + */ + public function getAllLinks() + { + return $this->link->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->link->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->link->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->link->remove($link_id); + } +} diff --git a/app/Api/Me.php b/app/Api/Me.php deleted file mode 100644 index 3d08626a..00000000 --- a/app/Api/Me.php +++ /dev/null @@ -1,72 +0,0 @@ -sessionStorage->user; - } - - public function getMyDashboard() - { - $user_id = $this->userSession->getId(); - $projects = $this->project->getQueryColumnStats($this->projectPermission->getActiveProjectIds($user_id))->findAll(); - $tasks = $this->taskFinder->getUserQuery($user_id)->findAll(); - - return array( - 'projects' => $this->formatProjects($projects), - 'tasks' => $this->formatTasks($tasks), - 'subtasks' => $this->subtask->getUserQuery($user_id, array(SubTaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))->findAll(), - ); - } - - public function getMyActivityStream() - { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); - return $this->helper->projectActivity->getProjectsEvents($project_ids, 100); - } - - public function createMyPrivateProject($name, $description = null) - { - if ($this->config->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->project->create($values, $this->userSession->getId(), true) : false; - } - - public function getMyProjectsList() - { - return $this->projectUserRole->getProjectsByUser($this->userSession->getId()); - } - - public function getMyOverdueTasks() - { - return $this->taskFinder->getOverdueTasksByUser($this->userSession->getId()); - } - - public function getMyProjects() - { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); - $projects = $this->project->getAllByIds($project_ids); - - return $this->formatProjects($projects); - } -} diff --git a/app/Api/MeApi.php b/app/Api/MeApi.php new file mode 100644 index 00000000..7d46a962 --- /dev/null +++ b/app/Api/MeApi.php @@ -0,0 +1,72 @@ +sessionStorage->user; + } + + public function getMyDashboard() + { + $user_id = $this->userSession->getId(); + $projects = $this->project->getQueryColumnStats($this->projectPermission->getActiveProjectIds($user_id))->findAll(); + $tasks = $this->taskFinder->getUserQuery($user_id)->findAll(); + + return array( + 'projects' => $this->formatProjects($projects), + 'tasks' => $this->formatTasks($tasks), + 'subtasks' => $this->subtask->getUserQuery($user_id, array(SubTaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS))->findAll(), + ); + } + + public function getMyActivityStream() + { + $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + return $this->helper->projectActivity->getProjectsEvents($project_ids, 100); + } + + public function createMyPrivateProject($name, $description = null) + { + if ($this->config->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->project->create($values, $this->userSession->getId(), true) : false; + } + + public function getMyProjectsList() + { + return $this->projectUserRole->getProjectsByUser($this->userSession->getId()); + } + + public function getMyOverdueTasks() + { + return $this->taskFinder->getOverdueTasksByUser($this->userSession->getId()); + } + + public function getMyProjects() + { + $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + $projects = $this->project->getAllByIds($project_ids); + + return $this->formatProjects($projects); + } +} diff --git a/app/Api/Project.php b/app/Api/Project.php deleted file mode 100644 index 846d7046..00000000 --- a/app/Api/Project.php +++ /dev/null @@ -1,87 +0,0 @@ -checkProjectPermission($project_id); - return $this->formatProject($this->project->getById($project_id)); - } - - public function getProjectByName($name) - { - return $this->formatProject($this->project->getByName($name)); - } - - public function getAllProjects() - { - return $this->formatProjects($this->project->getAll()); - } - - public function removeProject($project_id) - { - return $this->project->remove($project_id); - } - - public function enableProject($project_id) - { - return $this->project->enable($project_id); - } - - public function disableProject($project_id) - { - return $this->project->disable($project_id); - } - - public function enableProjectPublicAccess($project_id) - { - return $this->project->enablePublicAccess($project_id); - } - - public function disableProjectPublicAccess($project_id) - { - return $this->project->disablePublicAccess($project_id); - } - - public function getProjectActivities(array $project_ids) - { - return $this->helper->projectActivity->getProjectsEvents($project_ids); - } - - public function getProjectActivity($project_id) - { - $this->checkProjectPermission($project_id); - return $this->helper->projectActivity->getProjectEvents($project_id); - } - - public function createProject($name, $description = null) - { - $values = array( - 'name' => $name, - 'description' => $description - ); - - list($valid, ) = $this->projectValidator->validateCreation($values); - return $valid ? $this->project->create($values) : false; - } - - public function updateProject($id, $name, $description = null) - { - $values = array( - 'id' => $id, - 'name' => $name, - 'description' => $description - ); - - list($valid, ) = $this->projectValidator->validateModification($values); - return $valid && $this->project->update($values); - } -} diff --git a/app/Api/ProjectApi.php b/app/Api/ProjectApi.php new file mode 100644 index 00000000..70cd8d16 --- /dev/null +++ b/app/Api/ProjectApi.php @@ -0,0 +1,87 @@ +checkProjectPermission($project_id); + return $this->formatProject($this->project->getById($project_id)); + } + + public function getProjectByName($name) + { + return $this->formatProject($this->project->getByName($name)); + } + + public function getAllProjects() + { + return $this->formatProjects($this->project->getAll()); + } + + public function removeProject($project_id) + { + return $this->project->remove($project_id); + } + + public function enableProject($project_id) + { + return $this->project->enable($project_id); + } + + public function disableProject($project_id) + { + return $this->project->disable($project_id); + } + + public function enableProjectPublicAccess($project_id) + { + return $this->project->enablePublicAccess($project_id); + } + + public function disableProjectPublicAccess($project_id) + { + return $this->project->disablePublicAccess($project_id); + } + + public function getProjectActivities(array $project_ids) + { + return $this->helper->projectActivity->getProjectsEvents($project_ids); + } + + public function getProjectActivity($project_id) + { + $this->checkProjectPermission($project_id); + return $this->helper->projectActivity->getProjectEvents($project_id); + } + + public function createProject($name, $description = null) + { + $values = array( + 'name' => $name, + 'description' => $description + ); + + list($valid, ) = $this->projectValidator->validateCreation($values); + return $valid ? $this->project->create($values) : false; + } + + public function updateProject($id, $name, $description = null) + { + $values = array( + 'id' => $id, + 'name' => $name, + 'description' => $description + ); + + list($valid, ) = $this->projectValidator->validateModification($values); + return $valid && $this->project->update($values); + } +} diff --git a/app/Api/ProjectPermission.php b/app/Api/ProjectPermission.php deleted file mode 100644 index 11e92af0..00000000 --- a/app/Api/ProjectPermission.php +++ /dev/null @@ -1,72 +0,0 @@ -projectUserRole->getAllUsers($project_id); - } - - public function getAssignableUsers($project_id, $prepend_unassigned = false) - { - return $this->projectUserRole->getAssignableUsersList($project_id, $prepend_unassigned); - } - - public function addProjectUser($project_id, $user_id, $role = Role::PROJECT_MEMBER) - { - return $this->projectUserRole->addUser($project_id, $user_id, $role); - } - - public function addProjectGroup($project_id, $group_id, $role = Role::PROJECT_MEMBER) - { - return $this->projectGroupRole->addGroup($project_id, $group_id, $role); - } - - public function removeProjectUser($project_id, $user_id) - { - return $this->projectUserRole->removeUser($project_id, $user_id); - } - - public function removeProjectGroup($project_id, $group_id) - { - return $this->projectGroupRole->removeGroup($project_id, $group_id); - } - - public function changeProjectUserRole($project_id, $user_id, $role) - { - return $this->projectUserRole->changeUserRole($project_id, $user_id, $role); - } - - public function changeProjectGroupRole($project_id, $group_id, $role) - { - return $this->projectGroupRole->changeGroupRole($project_id, $group_id, $role); - } - - // Deprecated - public function getMembers($project_id) - { - return $this->getProjectUsers($project_id); - } - - // Deprecated - public function revokeUser($project_id, $user_id) - { - return $this->removeProjectUser($project_id, $user_id); - } - - // Deprecated - public function allowUser($project_id, $user_id) - { - return $this->addProjectUser($project_id, $user_id); - } -} diff --git a/app/Api/ProjectPermissionApi.php b/app/Api/ProjectPermissionApi.php new file mode 100644 index 00000000..10ee3852 --- /dev/null +++ b/app/Api/ProjectPermissionApi.php @@ -0,0 +1,73 @@ +projectUserRole->getAllUsers($project_id); + } + + public function getAssignableUsers($project_id, $prepend_unassigned = false) + { + return $this->projectUserRole->getAssignableUsersList($project_id, $prepend_unassigned); + } + + public function addProjectUser($project_id, $user_id, $role = Role::PROJECT_MEMBER) + { + return $this->projectUserRole->addUser($project_id, $user_id, $role); + } + + public function addProjectGroup($project_id, $group_id, $role = Role::PROJECT_MEMBER) + { + return $this->projectGroupRole->addGroup($project_id, $group_id, $role); + } + + public function removeProjectUser($project_id, $user_id) + { + return $this->projectUserRole->removeUser($project_id, $user_id); + } + + public function removeProjectGroup($project_id, $group_id) + { + return $this->projectGroupRole->removeGroup($project_id, $group_id); + } + + public function changeProjectUserRole($project_id, $user_id, $role) + { + return $this->projectUserRole->changeUserRole($project_id, $user_id, $role); + } + + public function changeProjectGroupRole($project_id, $group_id, $role) + { + return $this->projectGroupRole->changeGroupRole($project_id, $group_id, $role); + } + + // Deprecated + public function getMembers($project_id) + { + return $this->getProjectUsers($project_id); + } + + // Deprecated + public function revokeUser($project_id, $user_id) + { + return $this->removeProjectUser($project_id, $user_id); + } + + // Deprecated + public function allowUser($project_id, $user_id) + { + return $this->addProjectUser($project_id, $user_id); + } +} diff --git a/app/Api/Subtask.php b/app/Api/Subtask.php deleted file mode 100644 index 782fdb02..00000000 --- a/app/Api/Subtask.php +++ /dev/null @@ -1,64 +0,0 @@ -subtask->getById($subtask_id); - } - - public function getAllSubtasks($task_id) - { - return $this->subtask->getAll($task_id); - } - - public function removeSubtask($subtask_id) - { - return $this->subtask->remove($subtask_id); - } - - public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) - { - $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->subtask->create($values) : false; - } - - public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) - { - $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->subtask->update($values); - } -} diff --git a/app/Api/SubtaskApi.php b/app/Api/SubtaskApi.php new file mode 100644 index 00000000..305f9ae7 --- /dev/null +++ b/app/Api/SubtaskApi.php @@ -0,0 +1,66 @@ +subtask->getById($subtask_id); + } + + public function getAllSubtasks($task_id) + { + return $this->subtask->getAll($task_id); + } + + public function removeSubtask($subtask_id) + { + return $this->subtask->remove($subtask_id); + } + + public function createSubtask($task_id, $title, $user_id = 0, $time_estimated = 0, $time_spent = 0, $status = 0) + { + $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->subtask->create($values) : false; + } + + public function updateSubtask($id, $task_id, $title = null, $user_id = null, $time_estimated = null, $time_spent = null, $status = null) + { + $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->subtask->update($values); + } +} diff --git a/app/Api/Swimlane.php b/app/Api/Swimlane.php deleted file mode 100644 index 03a2819f..00000000 --- a/app/Api/Swimlane.php +++ /dev/null @@ -1,78 +0,0 @@ -swimlane->getSwimlanes($project_id); - } - - public function getAllSwimlanes($project_id) - { - return $this->swimlane->getAll($project_id); - } - - public function getSwimlaneById($swimlane_id) - { - return $this->swimlane->getById($swimlane_id); - } - - public function getSwimlaneByName($project_id, $name) - { - return $this->swimlane->getByName($project_id, $name); - } - - public function getSwimlane($swimlane_id) - { - return $this->swimlane->getById($swimlane_id); - } - - public function getDefaultSwimlane($project_id) - { - return $this->swimlane->getDefault($project_id); - } - - public function addSwimlane($project_id, $name, $description = '') - { - return $this->swimlane->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->swimlane->update($values); - } - - public function removeSwimlane($project_id, $swimlane_id) - { - return $this->swimlane->remove($project_id, $swimlane_id); - } - - public function disableSwimlane($project_id, $swimlane_id) - { - return $this->swimlane->disable($project_id, $swimlane_id); - } - - public function enableSwimlane($project_id, $swimlane_id) - { - return $this->swimlane->enable($project_id, $swimlane_id); - } - - public function changeSwimlanePosition($project_id, $swimlane_id, $position) - { - return $this->swimlane->changePosition($project_id, $swimlane_id, $position); - } -} diff --git a/app/Api/SwimlaneApi.php b/app/Api/SwimlaneApi.php new file mode 100644 index 00000000..f179e11b --- /dev/null +++ b/app/Api/SwimlaneApi.php @@ -0,0 +1,80 @@ +swimlane->getSwimlanes($project_id); + } + + public function getAllSwimlanes($project_id) + { + return $this->swimlane->getAll($project_id); + } + + public function getSwimlaneById($swimlane_id) + { + return $this->swimlane->getById($swimlane_id); + } + + public function getSwimlaneByName($project_id, $name) + { + return $this->swimlane->getByName($project_id, $name); + } + + public function getSwimlane($swimlane_id) + { + return $this->swimlane->getById($swimlane_id); + } + + public function getDefaultSwimlane($project_id) + { + return $this->swimlane->getDefault($project_id); + } + + public function addSwimlane($project_id, $name, $description = '') + { + return $this->swimlane->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->swimlane->update($values); + } + + public function removeSwimlane($project_id, $swimlane_id) + { + return $this->swimlane->remove($project_id, $swimlane_id); + } + + public function disableSwimlane($project_id, $swimlane_id) + { + return $this->swimlane->disable($project_id, $swimlane_id); + } + + public function enableSwimlane($project_id, $swimlane_id) + { + return $this->swimlane->enable($project_id, $swimlane_id); + } + + public function changeSwimlanePosition($project_id, $swimlane_id, $position) + { + return $this->swimlane->changePosition($project_id, $swimlane_id, $position); + } +} diff --git a/app/Api/Task.php b/app/Api/Task.php deleted file mode 100644 index 1d1211f2..00000000 --- a/app/Api/Task.php +++ /dev/null @@ -1,169 +0,0 @@ -checkProjectPermission($project_id); - return $this->taskLexer->build($query)->withFilter(new TaskProjectFilter($project_id))->toArray(); - } - - public function getTask($task_id) - { - $this->checkTaskPermission($task_id); - return $this->formatTask($this->taskFinder->getById($task_id)); - } - - public function getTaskByReference($project_id, $reference) - { - $this->checkProjectPermission($project_id); - return $this->formatTask($this->taskFinder->getByReference($project_id, $reference)); - } - - public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) - { - $this->checkProjectPermission($project_id); - return $this->formatTasks($this->taskFinder->getAll($project_id, $status_id)); - } - - public function getOverdueTasks() - { - return $this->taskFinder->getOverdueTasks(); - } - - public function getOverdueTasksByProject($project_id) - { - $this->checkProjectPermission($project_id); - return $this->taskFinder->getOverdueTasksByProject($project_id); - } - - public function openTask($task_id) - { - $this->checkTaskPermission($task_id); - return $this->taskStatus->open($task_id); - } - - public function closeTask($task_id) - { - $this->checkTaskPermission($task_id); - return $this->taskStatus->close($task_id); - } - - public function removeTask($task_id) - { - return $this->task->remove($task_id); - } - - public function moveTaskPosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0) - { - $this->checkProjectPermission($project_id); - return $this->taskPosition->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) - { - return $this->taskDuplication->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) - { - return $this->taskDuplication->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 = '') - { - $this->checkProjectPermission($project_id); - - if ($owner_id !== 0 && ! $this->projectPermission->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->taskCreation->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) - { - $this->checkTaskPermission($id); - - $project_id = $this->taskFinder->getProjectId($id); - - if ($project_id === 0) { - return false; - } - - if ($owner_id !== null && $owner_id != 0 && ! $this->projectPermission->isAssignable($project_id, $owner_id)) { - return false; - } - - $values = 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, - ); - - foreach ($values as $key => $value) { - if (is_null($value)) { - unset($values[$key]); - } - } - - list($valid) = $this->taskValidator->validateApiModification($values); - return $valid && $this->taskModification->update($values); - } -} diff --git a/app/Api/TaskApi.php b/app/Api/TaskApi.php new file mode 100644 index 00000000..4d745fa6 --- /dev/null +++ b/app/Api/TaskApi.php @@ -0,0 +1,169 @@ +checkProjectPermission($project_id); + return $this->taskLexer->build($query)->withFilter(new TaskProjectFilter($project_id))->toArray(); + } + + public function getTask($task_id) + { + $this->checkTaskPermission($task_id); + return $this->formatTask($this->taskFinder->getById($task_id)); + } + + public function getTaskByReference($project_id, $reference) + { + $this->checkProjectPermission($project_id); + return $this->formatTask($this->taskFinder->getByReference($project_id, $reference)); + } + + public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) + { + $this->checkProjectPermission($project_id); + return $this->formatTasks($this->taskFinder->getAll($project_id, $status_id)); + } + + public function getOverdueTasks() + { + return $this->taskFinder->getOverdueTasks(); + } + + public function getOverdueTasksByProject($project_id) + { + $this->checkProjectPermission($project_id); + return $this->taskFinder->getOverdueTasksByProject($project_id); + } + + public function openTask($task_id) + { + $this->checkTaskPermission($task_id); + return $this->taskStatus->open($task_id); + } + + public function closeTask($task_id) + { + $this->checkTaskPermission($task_id); + return $this->taskStatus->close($task_id); + } + + public function removeTask($task_id) + { + return $this->task->remove($task_id); + } + + public function moveTaskPosition($project_id, $task_id, $column_id, $position, $swimlane_id = 0) + { + $this->checkProjectPermission($project_id); + return $this->taskPosition->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) + { + return $this->taskDuplication->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) + { + return $this->taskDuplication->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 = '') + { + $this->checkProjectPermission($project_id); + + if ($owner_id !== 0 && ! $this->projectPermission->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->taskCreation->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) + { + $this->checkTaskPermission($id); + + $project_id = $this->taskFinder->getProjectId($id); + + if ($project_id === 0) { + return false; + } + + if ($owner_id !== null && $owner_id != 0 && ! $this->projectPermission->isAssignable($project_id, $owner_id)) { + return false; + } + + $values = 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, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + list($valid) = $this->taskValidator->validateApiModification($values); + return $valid && $this->taskModification->update($values); + } +} diff --git a/app/Api/TaskLink.php b/app/Api/TaskLink.php deleted file mode 100644 index 47d70d1e..00000000 --- a/app/Api/TaskLink.php +++ /dev/null @@ -1,77 +0,0 @@ -taskLink->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) - { - return $this->taskLink->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) - { - return $this->taskLink->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) - { - return $this->taskLink->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) - { - return $this->taskLink->remove($task_link_id); - } -} diff --git a/app/Api/TaskLinkApi.php b/app/Api/TaskLinkApi.php new file mode 100644 index 00000000..8c02c524 --- /dev/null +++ b/app/Api/TaskLinkApi.php @@ -0,0 +1,79 @@ +taskLink->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) + { + return $this->taskLink->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) + { + return $this->taskLink->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) + { + return $this->taskLink->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) + { + return $this->taskLink->remove($task_link_id); + } +} diff --git a/app/Api/User.php b/app/Api/User.php deleted file mode 100644 index 6ee935a3..00000000 --- a/app/Api/User.php +++ /dev/null @@ -1,137 +0,0 @@ -user->getById($user_id); - } - - public function getUserByName($username) - { - return $this->user->getByUsername($username); - } - - public function getAllUsers() - { - return $this->user->getAll(); - } - - public function removeUser($user_id) - { - return $this->user->remove($user_id); - } - - public function disableUser($user_id) - { - return $this->user->disable($user_id); - } - - public function enableUser($user_id) - { - return $this->user->enable($user_id); - } - - public function isActiveUser($user_id) - { - return $this->user->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->user->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->user->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 = array( - 'id' => $id, - 'username' => $username, - 'name' => $name, - 'email' => $email, - 'role' => $role, - ); - - foreach ($values as $key => $value) { - if (is_null($value)) { - unset($values[$key]); - } - } - - list($valid, ) = $this->userValidator->validateApiModification($values); - return $valid && $this->user->update($values); - } -} diff --git a/app/Api/UserApi.php b/app/Api/UserApi.php new file mode 100644 index 00000000..9786e6cf --- /dev/null +++ b/app/Api/UserApi.php @@ -0,0 +1,138 @@ +user->getById($user_id); + } + + public function getUserByName($username) + { + return $this->user->getByUsername($username); + } + + public function getAllUsers() + { + return $this->user->getAll(); + } + + public function removeUser($user_id) + { + return $this->user->remove($user_id); + } + + public function disableUser($user_id) + { + return $this->user->disable($user_id); + } + + public function enableUser($user_id) + { + return $this->user->enable($user_id); + } + + public function isActiveUser($user_id) + { + return $this->user->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->user->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->user->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 = array( + 'id' => $id, + 'username' => $username, + 'name' => $name, + 'email' => $email, + 'role' => $role, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + list($valid, ) = $this->userValidator->validateApiModification($values); + return $valid && $this->user->update($values); + } +} -- cgit v1.2.3