From 922e0fb6de06a98774418612e0b0f75af72b6dbb Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 25 Jun 2016 14:34:46 -0400 Subject: Rewrite integration tests to run with Docker containers --- app/Api/BaseApi.php | 11 +++++ app/Api/FileApi.php | 91 ------------------------------------- app/Api/ProjectApi.php | 8 ++-- app/Api/ProjectPermissionApi.php | 18 -------- app/Api/TaskApi.php | 10 +--- app/Api/TaskFileApi.php | 59 ++++++++++++++++++++++++ app/Api/UserApi.php | 13 ++---- app/ServiceProvider/ApiProvider.php | 4 +- 8 files changed, 81 insertions(+), 133 deletions(-) delete mode 100644 app/Api/FileApi.php create mode 100644 app/Api/TaskFileApi.php (limited to 'app') diff --git a/app/Api/BaseApi.php b/app/Api/BaseApi.php index 9f69aa65..8f18802c 100644 --- a/app/Api/BaseApi.php +++ b/app/Api/BaseApi.php @@ -71,4 +71,15 @@ abstract class BaseApi extends Base return $projects; } + + protected function filterValues(array $values) + { + foreach ($values as $key => $value) { + if (is_null($value)) { + unset($values[$key]); + } + } + + return $values; + } } diff --git a/app/Api/FileApi.php b/app/Api/FileApi.php deleted file mode 100644 index 1ed3aeb9..00000000 --- a/app/Api/FileApi.php +++ /dev/null @@ -1,91 +0,0 @@ -taskFileModel->getById($file_id); - } - - public function getAllTaskFiles($task_id) - { - return $this->taskFileModel->getAll($task_id); - } - - public function downloadTaskFile($file_id) - { - try { - $file = $this->taskFileModel->getById($file_id); - - if (! empty($file)) { - return base64_encode($this->objectStorage->get($file['path'])); - } - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - } - - return ''; - } - - public function createTaskFile($project_id, $task_id, $filename, $blob) - { - try { - return $this->taskFileModel->uploadContent($task_id, $filename, $blob); - } catch (ObjectStorageException $e) { - $this->logger->error($e->getMessage()); - return false; - } - } - - public function removeTaskFile($file_id) - { - return $this->taskFileModel->remove($file_id); - } - - public function removeAllTaskFiles($task_id) - { - return $this->taskFileModel->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/ProjectApi.php b/app/Api/ProjectApi.php index 29a9cd79..a726d4eb 100644 --- a/app/Api/ProjectApi.php +++ b/app/Api/ProjectApi.php @@ -73,13 +73,13 @@ class ProjectApi extends BaseApi return $valid ? $this->projectModel->create($values) : false; } - public function updateProject($id, $name, $description = null) + public function updateProject($project_id, $name, $description = null) { - $values = array( - 'id' => $id, + $values = $this->filterValues(array( + 'id' => $project_id, 'name' => $name, 'description' => $description - ); + )); list($valid, ) = $this->projectValidator->validateModification($values); return $valid && $this->projectModel->update($values); diff --git a/app/Api/ProjectPermissionApi.php b/app/Api/ProjectPermissionApi.php index 703cd0f3..37c5e13c 100644 --- a/app/Api/ProjectPermissionApi.php +++ b/app/Api/ProjectPermissionApi.php @@ -52,22 +52,4 @@ class ProjectPermissionApi extends Base { return $this->projectGroupRoleModel->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/TaskApi.php b/app/Api/TaskApi.php index ddb3ac54..523bfaa0 100644 --- a/app/Api/TaskApi.php +++ b/app/Api/TaskApi.php @@ -139,7 +139,7 @@ class TaskApi extends BaseApi return false; } - $values = array( + $values = $this->filterValues(array( 'id' => $id, 'title' => $title, 'color_id' => $color_id, @@ -155,13 +155,7 @@ class TaskApi extends BaseApi '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->taskModificationModel->update($values); diff --git a/app/Api/TaskFileApi.php b/app/Api/TaskFileApi.php new file mode 100644 index 00000000..7b27477c --- /dev/null +++ b/app/Api/TaskFileApi.php @@ -0,0 +1,59 @@ +taskFileModel->getById($file_id); + } + + public function getAllTaskFiles($task_id) + { + return $this->taskFileModel->getAll($task_id); + } + + public function downloadTaskFile($file_id) + { + try { + $file = $this->taskFileModel->getById($file_id); + + if (! empty($file)) { + return base64_encode($this->objectStorage->get($file['path'])); + } + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + } + + return ''; + } + + public function createTaskFile($project_id, $task_id, $filename, $blob) + { + try { + return $this->taskFileModel->uploadContent($task_id, $filename, $blob); + } catch (ObjectStorageException $e) { + $this->logger->error($e->getMessage()); + return false; + } + } + + public function removeTaskFile($file_id) + { + return $this->taskFileModel->remove($file_id); + } + + public function removeAllTaskFiles($task_id) + { + return $this->taskFileModel->removeAll($task_id); + } +} diff --git a/app/Api/UserApi.php b/app/Api/UserApi.php index 88d75527..6cb9df1c 100644 --- a/app/Api/UserApi.php +++ b/app/Api/UserApi.php @@ -2,7 +2,6 @@ namespace Kanboard\Api; -use Kanboard\Core\Base; use LogicException; use Kanboard\Core\Security\Role; use Kanboard\Core\Ldap\Client as LdapClient; @@ -15,7 +14,7 @@ use Kanboard\Core\Ldap\User as LdapUser; * @package Kanboard\Api * @author Frederic Guillot */ -class UserApi extends Base +class UserApi extends BaseApi { public function getUser($user_id) { @@ -118,19 +117,13 @@ class UserApi extends Base public function updateUser($id, $username = null, $name = null, $email = null, $role = null) { - $values = array( + $values = $this->filterValues(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->userModel->update($values); diff --git a/app/ServiceProvider/ApiProvider.php b/app/ServiceProvider/ApiProvider.php index 93b3c7f5..e0312056 100644 --- a/app/ServiceProvider/ApiProvider.php +++ b/app/ServiceProvider/ApiProvider.php @@ -9,7 +9,7 @@ use Kanboard\Api\BoardApi; use Kanboard\Api\CategoryApi; use Kanboard\Api\ColumnApi; use Kanboard\Api\CommentApi; -use Kanboard\Api\FileApi; +use Kanboard\Api\TaskFileApi; use Kanboard\Api\GroupApi; use Kanboard\Api\GroupMemberApi; use Kanboard\Api\LinkApi; @@ -56,7 +56,7 @@ class ApiProvider implements ServiceProviderInterface ->withObject(new ColumnApi($container)) ->withObject(new CategoryApi($container)) ->withObject(new CommentApi($container)) - ->withObject(new FileApi($container)) + ->withObject(new TaskFileApi($container)) ->withObject(new LinkApi($container)) ->withObject(new ProjectApi($container)) ->withObject(new ProjectPermissionApi($container)) -- cgit v1.2.3