diff options
Diffstat (limited to 'app/Api')
-rw-r--r-- | app/Api/Action.php | 98 | ||||
-rw-r--r-- | app/Api/App.php | 22 | ||||
-rw-r--r-- | app/Api/Base.php | 81 | ||||
-rw-r--r-- | app/Api/Board.php | 52 | ||||
-rw-r--r-- | app/Api/Category.php | 49 | ||||
-rw-r--r-- | app/Api/Comment.php | 51 | ||||
-rw-r--r-- | app/Api/Link.php | 111 | ||||
-rw-r--r-- | app/Api/Project.php | 85 | ||||
-rw-r--r-- | app/Api/ProjectPermission.php | 27 | ||||
-rw-r--r-- | app/Api/Subtask.php | 64 | ||||
-rw-r--r-- | app/Api/Swimlane.php | 77 | ||||
-rw-r--r-- | app/Api/Task.php | 113 | ||||
-rw-r--r-- | app/Api/TaskLink.php | 77 | ||||
-rw-r--r-- | app/Api/User.php | 88 |
14 files changed, 995 insertions, 0 deletions
diff --git a/app/Api/Action.php b/app/Api/Action.php new file mode 100644 index 00000000..6187b776 --- /dev/null +++ b/app/Api/Action.php @@ -0,0 +1,98 @@ +<?php + +namespace Api; + +/** + * Action API controller + * + * @package api + * @author Frederic Guillot + */ +class Action extends Base +{ + public function getAvailableActions() + { + return $this->action->getAvailableActions(); + } + + public function getAvailableActionEvents() + { + return $this->action->getAvailableEvents(); + } + + public function getCompatibleActionEvents($action_name) + { + return $this->action->getCompatibleEvents($action_name); + } + + public function removeAction($action_id) + { + return $this->action->remove($action_id); + } + + public function getActions($project_id) + { + $actions = $this->action->getAllByProject($project_id); + + foreach ($actions as $index => $action) { + + $params = array(); + + foreach($action['params'] as $param) { + $params[$param['name']] = $param['value']; + } + + $actions[$index]['params'] = $params; + } + + return $actions; + } + + public function createAction($project_id, $event_name, $action_name, $params) + { + $values = array( + 'project_id' => $project_id, + 'event_name' => $event_name, + 'action_name' => $action_name, + 'params' => $params, + ); + + list($valid,) = $this->action->validateCreation($values); + + if (! $valid) { + return false; + } + + // Check if the action exists + $actions = $this->action->getAvailableActions(); + + if (! isset($actions[$action_name])) { + return false; + } + + // Check the event + $action = $this->action->load($action_name, $project_id, $event_name); + + if (! in_array($event_name, $action->getCompatibleEvents())) { + 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 new file mode 100644 index 00000000..2fc32e91 --- /dev/null +++ b/app/Api/App.php @@ -0,0 +1,22 @@ +<?php + +namespace Api; + +/** + * App API controller + * + * @package api + * @author Frederic Guillot + */ +class App extends Base +{ + public function getTimezone() + { + return $this->config->get('application_timezone'); + } + + public function getVersion() + { + return APP_VERSION; + } +} diff --git a/app/Api/Base.php b/app/Api/Base.php new file mode 100644 index 00000000..e9494b58 --- /dev/null +++ b/app/Api/Base.php @@ -0,0 +1,81 @@ +<?php + +namespace Api; + +use Pimple\Container; +use JsonRPC\AuthenticationFailure; +use Symfony\Component\EventDispatcher\Event; + +/** + * Base class + * + * @package api + * @author Frederic Guillot + * + * @property \Model\Board $board + * @property \Model\Config $config + * @property \Model\Comment $comment + * @property \Model\LastLogin $lastLogin + * @property \Model\Notification $notification + * @property \Model\Project $project + * @property \Model\ProjectPermission $projectPermission + * @property \Model\ProjectActivity $projectActivity + * @property \Model\ProjectAnalytic $projectAnalytic + * @property \Model\ProjectDailySummary $projectDailySummary + * @property \Model\Subtask $subtask + * @property \Model\Task $task + * @property \Model\TaskDuplication $taskDuplication + * @property \Model\TaskExport $taskExport + * @property \Model\TaskFinder $taskFinder + */ +abstract class Base +{ + /** + * Container instance + * + * @access protected + * @var \Pimple\Container + */ + protected $container; + + /** + * Constructor + * + * @access public + * @param \Pimple\Container $container + */ + public function __construct(Container $container) + { + $this->container = $container; + } + + /** + * Load automatically models + * + * @access public + * @param string $name Model name + * @return mixed + */ + public function __get($name) + { + return $this->container[$name]; + } + + /** + * Check api credentials + * + * @access public + * @param string $username + * @param string $password + * @param string $class + * @param string $method + */ + public function authentication($username, $password, $class, $method) + { + $this->container['dispatcher']->dispatch('api.bootstrap', new Event); + + if (! ($username === 'jsonrpc' && $password === $this->config->get('api_token'))) { + throw new AuthenticationFailure('Wrond credentials'); + } + } +} diff --git a/app/Api/Board.php b/app/Api/Board.php new file mode 100644 index 00000000..163131b6 --- /dev/null +++ b/app/Api/Board.php @@ -0,0 +1,52 @@ +<?php + +namespace Api; + +/** + * Board API controller + * + * @package api + * @author Frederic Guillot + */ +class Board extends Base +{ + public function getBoard($project_id) + { + return $this->board->getBoard($project_id); + } + + public function getColumns($project_id) + { + return $this->board->getColumns($project_id); + } + + public function getColumn($column_id) + { + return $this->board->getColumn($column_id); + } + + public function moveColumnUp($project_id, $column_id) + { + return $this->board->moveUp($project_id, $column_id); + } + + public function moveColumnDown($project_id, $column_id) + { + return $this->board->moveDown($project_id, $column_id); + } + + public function updateColumn($column_id, $title, $task_limit = 0, $description = '') + { + return $this->board->updateColumn($column_id, $title, $task_limit, $description); + } + + public function addColumn($project_id, $title, $task_limit = 0, $description = '') + { + return $this->board->addColumn($project_id, $title, $task_limit, $description); + } + + public function removeColumn($column_id) + { + return $this->board->removeColumn($column_id); + } +} diff --git a/app/Api/Category.php b/app/Api/Category.php new file mode 100644 index 00000000..f457ddf1 --- /dev/null +++ b/app/Api/Category.php @@ -0,0 +1,49 @@ +<?php + +namespace Api; + +/** + * Category API controller + * + * @package api + * @author Frederic Guillot + */ +class Category extends Base +{ + public function getCategory($category_id) + { + return $this->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->category->validateCreation($values); + return $valid ? $this->category->create($values) : false; + } + + public function updateCategory($id, $name) + { + $values = array( + 'id' => $id, + 'name' => $name, + ); + + list($valid,) = $this->category->validateModification($values); + return $valid && $this->category->update($values); + } +} diff --git a/app/Api/Comment.php b/app/Api/Comment.php new file mode 100644 index 00000000..19b84383 --- /dev/null +++ b/app/Api/Comment.php @@ -0,0 +1,51 @@ +<?php + +namespace Api; + +/** + * Comment API controller + * + * @package api + * @author Frederic Guillot + */ +class Comment extends Base +{ + public function getComment($comment_id) + { + return $this->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) + { + $values = array( + 'task_id' => $task_id, + 'user_id' => $user_id, + 'comment' => $content, + ); + + list($valid,) = $this->comment->validateCreation($values); + + return $valid ? $this->comment->create($values) : false; + } + + public function updateComment($id, $content) + { + $values = array( + 'id' => $id, + 'comment' => $content, + ); + + list($valid,) = $this->comment->validateModification($values); + return $valid && $this->comment->update($values); + } +} diff --git a/app/Api/Link.php b/app/Api/Link.php new file mode 100644 index 00000000..b9084784 --- /dev/null +++ b/app/Api/Link.php @@ -0,0 +1,111 @@ +<?php + +namespace Api; + +/** + * Link API controller + * + * @package api + * @author Frederic Guillot + */ +class Link extends Base +{ + /** + * Get a link by id + * + * @access public + * @param integer $link_id Link id + * @return array + */ + public function getLinkById($link_id) + { + return $this->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->link->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->link->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/Project.php b/app/Api/Project.php new file mode 100644 index 00000000..2451cd9c --- /dev/null +++ b/app/Api/Project.php @@ -0,0 +1,85 @@ +<?php + +namespace Api; + +/** + * Project API controller + * + * @package api + * @author Frederic Guillot + */ +class Project extends Base +{ + public function getProjectById($project_id) + { + return $this->project->getById($project_id); + } + + public function getProjectByName($name) + { + return $this->project->getByName($name); + } + + public function getAllProjects() + { + return $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->projectActivity->getProjects($project_ids); + } + + public function getProjectActivity($project_id) + { + return $this->projectActivity->getProject($project_id); + } + + public function createProject($name, $description = null) + { + $values = array( + 'name' => $name, + 'description' => $description + ); + + list($valid,) = $this->project->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->project->validateModification($values); + return $valid && $this->project->update($values); + } +} diff --git a/app/Api/ProjectPermission.php b/app/Api/ProjectPermission.php new file mode 100644 index 00000000..a31faf3d --- /dev/null +++ b/app/Api/ProjectPermission.php @@ -0,0 +1,27 @@ +<?php + +namespace Api; + +/** + * ProjectPermission API controller + * + * @package api + * @author Frederic Guillot + */ +class ProjectPermission extends Base +{ + public function getMembers($project_id) + { + return $this->projectPermission->getMembers($project_id); + } + + public function revokeUser($project_id, $user_id) + { + return $this->projectPermission->revokeMember($project_id, $user_id); + } + + public function allowUser($project_id, $user_id) + { + return $this->projectPermission->addMember($project_id, $user_id); + } +} diff --git a/app/Api/Subtask.php b/app/Api/Subtask.php new file mode 100644 index 00000000..2e6c30f2 --- /dev/null +++ b/app/Api/Subtask.php @@ -0,0 +1,64 @@ +<?php + +namespace Api; + +/** + * Subtask API controller + * + * @package api + * @author Frederic Guillot + */ +class Subtask extends Base +{ + public function getSubtask($subtask_id) + { + return $this->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->subtask->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->subtask->validateApiModification($values); + return $valid && $this->subtask->update($values); + } +} diff --git a/app/Api/Swimlane.php b/app/Api/Swimlane.php new file mode 100644 index 00000000..322b0805 --- /dev/null +++ b/app/Api/Swimlane.php @@ -0,0 +1,77 @@ +<?php + +namespace Api; + +/** + * Swimlane API controller + * + * @package api + * @author Frederic Guillot + */ +class Swimlane extends Base +{ + public function getActiveSwimlanes($project_id) + { + return $this->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) + { + return $this->swimlane->create($project_id, $name); + } + + public function updateSwimlane($swimlane_id, $name) + { + return $this->swimlane->rename($swimlane_id, $name); + } + + 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 moveSwimlaneUp($project_id, $swimlane_id) + { + return $this->swimlane->moveUp($project_id, $swimlane_id); + } + + public function moveSwimlaneDown($project_id, $swimlane_id) + { + return $this->swimlane->moveDown($project_id, $swimlane_id); + } +} diff --git a/app/Api/Task.php b/app/Api/Task.php new file mode 100644 index 00000000..c98b24a6 --- /dev/null +++ b/app/Api/Task.php @@ -0,0 +1,113 @@ +<?php + +namespace Api; + +use Model\Task as TaskModel; + +/** + * Task API controller + * + * @package api + * @author Frederic Guillot + */ +class Task extends Base +{ + public function getTask($task_id) + { + return $this->taskFinder->getById($task_id); + } + + public function getAllTasks($project_id, $status_id = TaskModel::STATUS_OPEN) + { + return $this->taskFinder->getAll($project_id, $status_id); + } + + public function getOverdueTasks() + { + return $this->taskFinder->getOverdueTasks(); + } + + public function openTask($task_id) + { + return $this->taskStatus->open($task_id); + } + + public function closeTask($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) + { + return $this->taskPosition->movePosition($project_id, $task_id, $column_id, $position, $swimlane_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, + $recurrence_status = 0, $recurrence_trigger = 0, $recurrence_factor = 0, $recurrence_timeframe = 0, + $recurrence_basedate = 0) + { + $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, + ); + + list($valid,) = $this->taskValidator->validateCreation($values); + + return $valid ? $this->taskCreation->create($values) : false; + } + + public function updateTask($id, $title = null, $project_id = null, $color_id = null, $column_id = null, $owner_id = null, + $creator_id = null, $date_due = null, $description = null, $category_id = null, $score = null, + $swimlane_id = null, $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null, + $recurrence_timeframe = null, $recurrence_basedate = null) + { + $values = array( + 'id' => $id, + '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, + ); + + 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 new file mode 100644 index 00000000..c3e1a83c --- /dev/null +++ b/app/Api/TaskLink.php @@ -0,0 +1,77 @@ +<?php + +namespace Api; + +/** + * TaskLink API controller + * + * @package api + * @author Frederic Guillot + */ +class TaskLink extends Base +{ + /** + * Get a task link + * + * @access public + * @param integer $task_link_id Task link id + * @return array + */ + public function getTaskLinkById($task_link_id) + { + return $this->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 new file mode 100644 index 00000000..166ef2c1 --- /dev/null +++ b/app/Api/User.php @@ -0,0 +1,88 @@ +<?php + +namespace Api; + +use Auth\Ldap; + +/** + * User API controller + * + * @package api + * @author Frederic Guillot + */ +class User extends Base +{ + public function getUser($user_id) + { + return $this->user->getById($user_id); + } + + public function getAllUsers() + { + return $this->user->getAll(); + } + + public function removeUser($user_id) + { + return $this->user->remove($user_id); + } + + public function createUser($username, $password, $name = '', $email = '', $is_admin = 0, $default_project_id = 0) + { + $values = array( + 'username' => $username, + 'password' => $password, + 'confirmation' => $password, + 'name' => $name, + 'email' => $email, + 'is_admin' => $is_admin, + 'default_project_id' => $default_project_id, + ); + + list($valid,) = $this->user->validateCreation($values); + + return $valid ? $this->user->create($values) : false; + } + + public function createLdapUser($username = '', $email = '', $is_admin = 0, $default_project_id = 0) + { + $ldap = new Ldap($this->container); + $user = $ldap->lookup($username, $email); + + if (! $user) { + return false; + } + + $values = array( + 'username' => $user['username'], + 'name' => $user['name'], + 'email' => $user['email'], + 'is_ldap_user' => 1, + 'is_admin' => $is_admin, + 'default_project_id' => $default_project_id, + ); + + return $this->user->create($values); + } + + public function updateUser($id, $username = null, $name = null, $email = null, $is_admin = null, $default_project_id = null) + { + $values = array( + 'id' => $id, + 'username' => $username, + 'name' => $name, + 'email' => $email, + 'is_admin' => $is_admin, + 'default_project_id' => $default_project_id, + ); + + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + list($valid,) = $this->user->validateApiModification($values); + return $valid && $this->user->update($values); + } +} |