diff options
author | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
---|---|---|
committer | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
commit | e4de6b3898b64b26d29aff31f21df5fda8055686 (patch) | |
tree | 575f8a65440f291d70a070d168eafca8c82a6459 /app/Api | |
parent | d9ffbea174ea6524d0a22f8375ca8b3aa04a3c96 (diff) | |
parent | a6540bc604c837d92c9368540c145606723e97f7 (diff) |
Merge pull request #1 from fguillot/master
Update from upstream
Diffstat (limited to 'app/Api')
-rw-r--r-- | app/Api/Action.php | 30 | ||||
-rw-r--r-- | app/Api/App.php | 10 | ||||
-rw-r--r-- | app/Api/Auth.php | 52 | ||||
-rw-r--r-- | app/Api/Board.php | 35 | ||||
-rw-r--r-- | app/Api/Category.php | 4 | ||||
-rw-r--r-- | app/Api/Column.php | 42 | ||||
-rw-r--r-- | app/Api/Comment.php | 7 | ||||
-rw-r--r-- | app/Api/File.php | 58 | ||||
-rw-r--r-- | app/Api/Group.php | 49 | ||||
-rw-r--r-- | app/Api/GroupMember.php | 32 | ||||
-rw-r--r-- | app/Api/Link.php | 4 | ||||
-rw-r--r-- | app/Api/Me.php | 16 | ||||
-rw-r--r-- | app/Api/Project.php | 4 | ||||
-rw-r--r-- | app/Api/ProjectPermission.php | 53 | ||||
-rw-r--r-- | app/Api/Subtask.php | 4 | ||||
-rw-r--r-- | app/Api/Swimlane.php | 11 | ||||
-rw-r--r-- | app/Api/Task.php | 44 | ||||
-rw-r--r-- | app/Api/User.php | 81 |
18 files changed, 403 insertions, 133 deletions
diff --git a/app/Api/Action.php b/app/Api/Action.php index 0ae91f10..9e3b86f6 100644 --- a/app/Api/Action.php +++ b/app/Api/Action.php @@ -12,17 +12,17 @@ class Action extends \Kanboard\Core\Base { public function getAvailableActions() { - return $this->action->getAvailableActions(); + return $this->actionManager->getAvailableActions(); } public function getAvailableActionEvents() { - return $this->action->getAvailableEvents(); + return $this->eventManager->getAll(); } public function getCompatibleActionEvents($action_name) { - return $this->action->getCompatibleEvents($action_name); + return $this->actionManager->getCompatibleEvents($action_name); } public function removeAction($action_id) @@ -32,22 +32,10 @@ class Action extends \Kanboard\Core\Base 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; + return $this->action->getAllByProject($project_id); } - public function createAction($project_id, $event_name, $action_name, $params) + public function createAction($project_id, $event_name, $action_name, array $params) { $values = array( 'project_id' => $project_id, @@ -56,23 +44,23 @@ class Action extends \Kanboard\Core\Base 'params' => $params, ); - list($valid, ) = $this->action->validateCreation($values); + list($valid, ) = $this->actionValidator->validateCreation($values); if (! $valid) { return false; } // Check if the action exists - $actions = $this->action->getAvailableActions(); + $actions = $this->actionManager->getAvailableActions(); if (! isset($actions[$action_name])) { return false; } // Check the event - $action = $this->action->load($action_name, $project_id, $event_name); + $action = $this->actionManager->getAction($action_name); - if (! in_array($event_name, $action->getCompatibleEvents())) { + if (! in_array($event_name, $action->getEvents())) { return false; } diff --git a/app/Api/App.php b/app/Api/App.php index d082bcfb..635f1ce2 100644 --- a/app/Api/App.php +++ b/app/Api/App.php @@ -34,4 +34,14 @@ class App extends \Kanboard\Core\Base { 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 index b3627e4b..c7c5298c 100644 --- a/app/Api/Auth.php +++ b/app/Api/Auth.php @@ -3,7 +3,6 @@ namespace Kanboard\Api; use JsonRPC\AuthenticationFailure; -use Symfony\Component\EventDispatcher\Event; /** * Base class @@ -24,15 +23,58 @@ class Auth extends Base */ public function checkCredentials($username, $password, $class, $method) { - $this->container['dispatcher']->dispatch('api.bootstrap', new Event); + $this->dispatcher->dispatch('app.bootstrap'); - if ($username !== 'jsonrpc' && ! $this->authentication->hasCaptcha($username) && $this->authentication->authenticate($username, $password)) { + if ($this->isUserAuthenticated($username, $password)) { $this->checkProcedurePermission(true, $method); - $this->userSession->refresh($this->user->getByUsername($username)); - } elseif ($username === 'jsonrpc' && $password === $this->config->get('api_token')) { + $this->userSession->initialize($this->user->getByUsername($username)); + } elseif ($this->isAppAuthenticated($username, $password)) { $this->checkProcedurePermission(false, $method); } else { throw new AuthenticationFailure('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/Board.php b/app/Api/Board.php index d615b1dc..185ac51a 100644 --- a/app/Api/Board.php +++ b/app/Api/Board.php @@ -15,39 +15,4 @@ class Board extends Base $this->checkProjectPermission($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 index 458eaef6..fbd61c56 100644 --- a/app/Api/Category.php +++ b/app/Api/Category.php @@ -32,7 +32,7 @@ class Category extends \Kanboard\Core\Base 'name' => $name, ); - list($valid, ) = $this->category->validateCreation($values); + list($valid, ) = $this->categoryValidator->validateCreation($values); return $valid ? $this->category->create($values) : false; } @@ -43,7 +43,7 @@ class Category extends \Kanboard\Core\Base 'name' => $name, ); - list($valid, ) = $this->category->validateModification($values); + list($valid, ) = $this->categoryValidator->validateModification($values); return $valid && $this->category->update($values); } } diff --git a/app/Api/Column.php b/app/Api/Column.php new file mode 100644 index 00000000..ddc3a5d0 --- /dev/null +++ b/app/Api/Column.php @@ -0,0 +1,42 @@ +<?php + +namespace Kanboard\Api; + +/** + * Column API controller + * + * @package api + * @author Frederic Guillot + */ +class Column extends Base +{ + public function getColumns($project_id) + { + return $this->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 index 26b632e9..1fc1c708 100644 --- a/app/Api/Comment.php +++ b/app/Api/Comment.php @@ -25,15 +25,16 @@ class Comment extends \Kanboard\Core\Base return $this->comment->remove($comment_id); } - public function createComment($task_id, $user_id, $content) + 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->comment->validateCreation($values); + list($valid, ) = $this->commentValidator->validateCreation($values); return $valid ? $this->comment->create($values) : false; } @@ -45,7 +46,7 @@ class Comment extends \Kanboard\Core\Base 'comment' => $content, ); - list($valid, ) = $this->comment->validateModification($values); + list($valid, ) = $this->commentValidator->validateModification($values); return $valid && $this->comment->update($values); } } diff --git a/app/Api/File.php b/app/Api/File.php index be415ecb..71c31c76 100644 --- a/app/Api/File.php +++ b/app/Api/File.php @@ -10,45 +10,81 @@ use Kanboard\Core\ObjectStorage\ObjectStorageException; * @package api * @author Frederic Guillot */ -class File extends \Kanboard\Core\Base +class File extends Base { - public function getFile($file_id) + public function getTaskFile($file_id) { - return $this->file->getById($file_id); + return $this->taskFile->getById($file_id); } - public function getAllFiles($task_id) + public function getAllTaskFiles($task_id) { - return $this->file->getAll($task_id); + return $this->taskFile->getAll($task_id); } - public function downloadFile($file_id) + public function downloadTaskFile($file_id) { try { - $file = $this->file->getById($file_id); + $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); + } - return ''; + 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->file->uploadContent($project_id, $task_id, $filename, $blob); + return $this->createTaskFile($project_id, $task_id, $filename, $blob); } public function removeFile($file_id) { - return $this->file->remove($file_id); + return $this->removeTaskFile($file_id); } public function removeAllFiles($task_id) { - return $this->file->removeAll($task_id); + return $this->removeAllTaskFiles($task_id); } } diff --git a/app/Api/Group.php b/app/Api/Group.php new file mode 100644 index 00000000..a1e0a73d --- /dev/null +++ b/app/Api/Group.php @@ -0,0 +1,49 @@ +<?php + +namespace Kanboard\Api; + +/** + * Group API controller + * + * @package api + * @author Frederic Guillot + */ +class Group extends \Kanboard\Core\Base +{ + public function createGroup($name, $external_id = '') + { + return $this->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 new file mode 100644 index 00000000..de62f0c6 --- /dev/null +++ b/app/Api/GroupMember.php @@ -0,0 +1,32 @@ +<?php + +namespace Kanboard\Api; + +/** + * Group Member API controller + * + * @package api + * @author Frederic Guillot + */ +class GroupMember extends \Kanboard\Core\Base +{ + 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 index d4df18fe..23a9916d 100644 --- a/app/Api/Link.php +++ b/app/Api/Link.php @@ -72,7 +72,7 @@ class Link extends \Kanboard\Core\Base 'opposite_label' => $opposite_label, ); - list($valid, ) = $this->link->validateCreation($values); + list($valid, ) = $this->linkValidator->validateCreation($values); return $valid ? $this->link->create($label, $opposite_label) : false; } @@ -93,7 +93,7 @@ class Link extends \Kanboard\Core\Base 'label' => $label, ); - list($valid, ) = $this->link->validateModification($values); + list($valid, ) = $this->linkValidator->validateModification($values); return $valid && $this->link->update($values); } diff --git a/app/Api/Me.php b/app/Api/Me.php index 2c332a8c..ccc809ed 100644 --- a/app/Api/Me.php +++ b/app/Api/Me.php @@ -14,13 +14,13 @@ class Me extends Base { public function getMe() { - return $this->session['user']; + return $this->sessionStorage->user; } public function getMyDashboard() { $user_id = $this->userSession->getId(); - $projects = $this->project->getQueryColumnStats($this->projectPermission->getActiveMemberProjectIds($user_id))->findAll(); + $projects = $this->project->getQueryColumnStats($this->projectPermission->getActiveProjectIds($user_id))->findAll(); $tasks = $this->taskFinder->getUserQuery($user_id)->findAll(); return array( @@ -32,25 +32,29 @@ class Me extends Base public function getMyActivityStream() { - $project_ids = $this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()); + $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); return $this->projectActivity->getProjects($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->project->validateCreation($values); + list($valid, ) = $this->projectValidator->validateCreation($values); return $valid ? $this->project->create($values, $this->userSession->getId(), true) : false; } public function getMyProjectsList() { - return $this->projectPermission->getMemberProjects($this->userSession->getId()); + return $this->projectUserRole->getProjectsByUser($this->userSession->getId()); } public function getMyOverdueTasks() @@ -60,7 +64,7 @@ class Me extends Base public function getMyProjects() { - $project_ids = $this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()); + $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 index f934432d..8e311f7f 100644 --- a/app/Api/Project.php +++ b/app/Api/Project.php @@ -69,7 +69,7 @@ class Project extends Base 'description' => $description ); - list($valid, ) = $this->project->validateCreation($values); + list($valid, ) = $this->projectValidator->validateCreation($values); return $valid ? $this->project->create($values) : false; } @@ -81,7 +81,7 @@ class Project extends Base 'description' => $description ); - list($valid, ) = $this->project->validateModification($values); + list($valid, ) = $this->projectValidator->validateModification($values); return $valid && $this->project->update($values); } } diff --git a/app/Api/ProjectPermission.php b/app/Api/ProjectPermission.php index 80323395..11e92af0 100644 --- a/app/Api/ProjectPermission.php +++ b/app/Api/ProjectPermission.php @@ -2,26 +2,71 @@ namespace Kanboard\Api; +use Kanboard\Core\Security\Role; + /** - * ProjectPermission API controller + * Project Permission API controller * * @package api * @author Frederic Guillot */ class ProjectPermission extends \Kanboard\Core\Base { + public function getProjectUsers($project_id) + { + return $this->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->projectPermission->getMembers($project_id); + return $this->getProjectUsers($project_id); } + // Deprecated public function revokeUser($project_id, $user_id) { - return $this->projectPermission->revokeMember($project_id, $user_id); + return $this->removeProjectUser($project_id, $user_id); } + // Deprecated public function allowUser($project_id, $user_id) { - return $this->projectPermission->addMember($project_id, $user_id); + return $this->addProjectUser($project_id, $user_id); } } diff --git a/app/Api/Subtask.php b/app/Api/Subtask.php index 7baee3d3..782fdb02 100644 --- a/app/Api/Subtask.php +++ b/app/Api/Subtask.php @@ -36,7 +36,7 @@ class Subtask extends \Kanboard\Core\Base 'status' => $status, ); - list($valid, ) = $this->subtask->validateCreation($values); + list($valid, ) = $this->subtaskValidator->validateCreation($values); return $valid ? $this->subtask->create($values) : false; } @@ -58,7 +58,7 @@ class Subtask extends \Kanboard\Core\Base } } - list($valid, ) = $this->subtask->validateApiModification($values); + list($valid, ) = $this->subtaskValidator->validateApiModification($values); return $valid && $this->subtask->update($values); } } diff --git a/app/Api/Swimlane.php b/app/Api/Swimlane.php index 84c699ab..03a2819f 100644 --- a/app/Api/Swimlane.php +++ b/app/Api/Swimlane.php @@ -48,9 +48,11 @@ class Swimlane extends \Kanboard\Core\Base 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); } @@ -69,13 +71,8 @@ class Swimlane extends \Kanboard\Core\Base 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) + public function changeSwimlanePosition($project_id, $swimlane_id, $position) { - return $this->swimlane->moveDown($project_id, $swimlane_id); + return $this->swimlane->changePosition($project_id, $swimlane_id, $position); } } diff --git a/app/Api/Task.php b/app/Api/Task.php index 0dceb209..177a09c6 100644 --- a/app/Api/Task.php +++ b/app/Api/Task.php @@ -64,13 +64,31 @@ class Task extends Base 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, - $recurrence_status = 0, $recurrence_trigger = 0, $recurrence_factor = 0, $recurrence_timeframe = 0, - $recurrence_basedate = 0, $reference = '') + $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, $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, @@ -96,20 +114,28 @@ class Task extends Base return $valid ? $this->taskCreation->create($values) : false; } - public function updateTask($id, $title = null, $project_id = null, $color_id = null, $owner_id = null, - $creator_id = null, $date_due = null, $description = null, $category_id = null, $score = null, - $recurrence_status = null, $recurrence_trigger = null, $recurrence_factor = null, - $recurrence_timeframe = null, $recurrence_basedate = null, $reference = null) + public function updateTask($id, $title = null, $color_id = null, $owner_id = null, + $date_due = null, $description = null, $category_id = null, $score = 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, - 'project_id' => $project_id, 'color_id' => $color_id, 'owner_id' => $owner_id, - 'creator_id' => $creator_id, 'date_due' => $date_due, 'description' => $description, 'category_id' => $category_id, diff --git a/app/Api/User.php b/app/Api/User.php index 105723d3..48337ac6 100644 --- a/app/Api/User.php +++ b/app/Api/User.php @@ -2,7 +2,11 @@ namespace Kanboard\Api; -use Kanboard\Auth\Ldap; +use LogicException; +use Kanboard\Core\Security\Role; +use Kanboard\Core\Ldap\Client as LdapClient; +use Kanboard\Core\Ldap\ClientException as LdapException; +use Kanboard\Core\Ldap\User as LdapUser; /** * User API controller @@ -17,6 +21,11 @@ class User extends \Kanboard\Core\Base return $this->user->getById($user_id); } + public function getUserByName($username) + { + return $this->user->getByUsername($username); + } + public function getAllUsers() { return $this->user->getAll(); @@ -27,7 +36,22 @@ class User extends \Kanboard\Core\Base return $this->user->remove($user_id); } - public function createUser($username, $password, $name = '', $email = '', $is_admin = 0, $is_project_admin = 0) + 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, @@ -35,44 +59,53 @@ class User extends \Kanboard\Core\Base 'confirmation' => $password, 'name' => $name, 'email' => $email, - 'is_admin' => $is_admin, - 'is_project_admin' => $is_project_admin, + 'role' => $role, ); - list($valid, ) = $this->user->validateCreation($values); + list($valid, ) = $this->userValidator->validateCreation($values); return $valid ? $this->user->create($values) : false; } - public function createLdapUser($username = '', $email = '', $is_admin = 0, $is_project_admin = 0) + public function createLdapUser($username) { - $ldap = new Ldap($this->container); - $user = $ldap->lookup($username, $email); + try { - if (! $user) { - return false; - } + $ldap = LdapClient::connect(); + $user = LdapUser::getUser($ldap, sprintf(LDAP_USER_FILTER, $username)); - $values = array( - 'username' => $user['username'], - 'name' => $user['name'], - 'email' => $user['email'], - 'is_ldap_user' => 1, - 'is_admin' => $is_admin, - 'is_project_admin' => $is_project_admin, - ); + if ($user === null) { + $this->logger->info('User not found in LDAP server'); + return false; + } - return $this->user->create($values); + 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, $is_admin = null, $is_project_admin = null) + public function updateUser($id, $username = null, $name = null, $email = null, $role = null) { $values = array( 'id' => $id, 'username' => $username, 'name' => $name, 'email' => $email, - 'is_admin' => $is_admin, - 'is_project_admin' => $is_project_admin, + 'role' => $role, ); foreach ($values as $key => $value) { @@ -81,7 +114,7 @@ class User extends \Kanboard\Core\Base } } - list($valid, ) = $this->user->validateApiModification($values); + list($valid, ) = $this->userValidator->validateApiModification($values); return $valid && $this->user->update($values); } } |