From 4a230d331ec220fc32a48525afb308af0d9787fa Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 10:25:13 -0400 Subject: Added application and project roles validation for API procedure calls --- tests/integration/BaseProcedureTest.php | 122 ++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 tests/integration/BaseProcedureTest.php (limited to 'tests/integration/BaseProcedureTest.php') diff --git a/tests/integration/BaseProcedureTest.php b/tests/integration/BaseProcedureTest.php new file mode 100644 index 00000000..e3382e82 --- /dev/null +++ b/tests/integration/BaseProcedureTest.php @@ -0,0 +1,122 @@ +setUpAppClient(); + $this->setUpAdminUser(); + $this->setUpManagerUser(); + $this->setUpStandardUser(); + } + + public function setUpAppClient() + { + $this->app = new JsonRPC\Client(API_URL); + $this->app->authentication('jsonrpc', API_KEY); + $this->app->getHttpClient()->withDebug()->withTimeout(10); + } + + public function setUpAdminUser() + { + $this->adminUserId = $this->getUserId('superuser'); + + if (! $this->adminUserId) { + $this->adminUserId = $this->app->createUser('superuser', 'password', 'Admin User', 'user@localhost', 'app-admin'); + $this->assertNotFalse($this->adminUserId); + } + + $this->admin = new JsonRPC\Client(API_URL); + $this->admin->authentication('superuser', 'password'); + $this->admin->getHttpClient()->withDebug(); + } + + public function setUpManagerUser() + { + $this->managerUserId = $this->getUserId('manager'); + + if (! $this->managerUserId) { + $this->managerUserId = $this->app->createUser('manager', 'password', 'Manager User', 'user@localhost', 'app-manager'); + $this->assertNotFalse($this->managerUserId); + } + + $this->manager = new JsonRPC\Client(API_URL); + $this->manager->authentication('manager', 'password'); + $this->manager->getHttpClient()->withDebug(); + } + + public function setUpStandardUser() + { + $this->userUserId = $this->getUserId('user'); + + if (! $this->userUserId) { + $this->userUserId = $this->app->createUser('user', 'password', 'Standard User', 'user@localhost', 'app-user'); + $this->assertNotFalse($this->userUserId); + } + + $this->user = new JsonRPC\Client(API_URL); + $this->user->authentication('user', 'password'); + $this->user->getHttpClient()->withDebug(); + } + + public function getUserId($username) + { + $user = $this->app->getUserByName($username); + + if (! empty($user)) { + return $user['id']; + } + + return 0; + } + + public function assertCreateTeamProject() + { + $this->projectId = $this->app->createProject($this->projectName, 'Description'); + $this->assertNotFalse($this->projectId); + } + + public function assertCreateUser() + { + $this->userId = $this->app->createUser($this->username, 'password'); + $this->assertNotFalse($this->userId); + } + + public function assertCreateGroups() + { + $this->groupId1 = $this->app->createGroup($this->groupName1); + $this->groupId2 = $this->app->createGroup($this->groupName2, 'External ID'); + $this->assertNotFalse($this->groupId1); + $this->assertNotFalse($this->groupId2); + } + + public function assertCreateTask() + { + $this->taskId = $this->app->createTask(array('title' => $this->taskTitle, 'project_id' => $this->projectId)); + $this->assertNotFalse($this->taskId); + } +} -- cgit v1.2.3 From 82623f1a212a3a79507ede69586c561efa675224 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 26 Jun 2016 15:47:02 -0400 Subject: Added API calls for subtask time tracking --- ChangeLog | 2 +- app/Api/Procedure/SubtaskTimeTrackingProcedure.php | 8 +- doc/api-json-rpc.markdown | 1 + doc/api-subtask-time-tracking-procedures.markdown | 102 +++++++++++++++++++++ tests/integration/BaseProcedureTest.php | 11 +++ tests/integration/SubtaskProcedureTest.php | 11 --- .../SubtaskTimeTrackingProcedureTest.php | 46 ++++++++++ 7 files changed, 165 insertions(+), 16 deletions(-) create mode 100644 doc/api-subtask-time-tracking-procedures.markdown create mode 100644 tests/integration/SubtaskTimeTrackingProcedureTest.php (limited to 'tests/integration/BaseProcedureTest.php') diff --git a/ChangeLog b/ChangeLog index 7a56139c..eccff6a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,7 +5,7 @@ New features: * Added application and project roles validation for API procedure calls * Added new API call: "getProjectByIdentifier" -* Added new API calls for external task links, project attachments +* Added new API calls for external task links, project attachments and subtask time tracking Improvements: diff --git a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php index b6d1102a..5ceaa08d 100644 --- a/app/Api/Procedure/SubtaskTimeTrackingProcedure.php +++ b/app/Api/Procedure/SubtaskTimeTrackingProcedure.php @@ -19,15 +19,15 @@ class SubtaskTimeTrackingProcedure extends BaseProcedure return $this->subtaskTimeTrackingModel->hasTimer($subtask_id, $user_id); } - public function logSubtaskStartTime($subtask_id, $user_id) + public function setSubtaskStartTime($subtask_id, $user_id) { - SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskStartTime', $subtask_id); + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'setSubtaskStartTime', $subtask_id); return $this->subtaskTimeTrackingModel->logStartTime($subtask_id, $user_id); } - public function logSubtaskEndTime($subtask_id, $user_id) + public function setSubtaskEndTime($subtask_id, $user_id) { - SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'logSubtaskEndTime', $subtask_id); + SubtaskAuthorization::getInstance($this->container)->check($this->getClassName(), 'setSubtaskEndTime', $subtask_id); return $this->subtaskTimeTrackingModel->logEndTime($subtask_id, $user_id); } diff --git a/doc/api-json-rpc.markdown b/doc/api-json-rpc.markdown index 6498b0cc..ab1056f0 100644 --- a/doc/api-json-rpc.markdown +++ b/doc/api-json-rpc.markdown @@ -58,6 +58,7 @@ Usage - [Automatic Actions](api-action-procedures.markdown) - [Tasks](api-task-procedures.markdown) - [Subtasks](api-subtask-procedures.markdown) +- [Subtask Time Tracking](api-subtask-time-tracking-procedures.markdown) - [Task Files](api-task-file-procedures.markdown) - [Project Files](api-project-file-procedures.markdown) - [Links](api-link-procedures.markdown) diff --git a/doc/api-subtask-time-tracking-procedures.markdown b/doc/api-subtask-time-tracking-procedures.markdown new file mode 100644 index 00000000..67447623 --- /dev/null +++ b/doc/api-subtask-time-tracking-procedures.markdown @@ -0,0 +1,102 @@ +Subtask Time Tracking API procedures +==================================== + +## hasSubtaskTimer + +- Purpose: **Check if a timer is started for the given subtask and user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"hasSubtaskTimer","id":1786995697,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 1786995697 +} +``` + +## setSubtaskStartTime + +- Purpose: **Start subtask timer for a user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"setSubtaskStartTime","id":1168991769,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 1168991769 +} +``` + +## setSubtaskEndTime + +- Purpose: **Stop subtask timer for a user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **true** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"setSubtaskEndTime","id":1026607603,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": true, + "id": 1026607603 +} +``` + +## getSubtaskTimeSpent + +- Purpose: **Get time spent on a subtask for a user** +- Parameters: + - **subtask_id** (integer, required) + - **user_id** (integer, optional) +- Result on success: **number of hours** +- Result on failure: **false** + +Request example: + +```json +{"jsonrpc":"2.0","method":"getSubtaskTimeSpent","id":738527378,"params":[2,4]} +``` + +Response example: + +```json +{ + "jsonrpc": "2.0", + "result": 1.5, + "id": 738527378 +} +``` diff --git a/tests/integration/BaseProcedureTest.php b/tests/integration/BaseProcedureTest.php index e3382e82..beb13ff7 100644 --- a/tests/integration/BaseProcedureTest.php +++ b/tests/integration/BaseProcedureTest.php @@ -17,6 +17,7 @@ abstract class BaseProcedureTest extends PHPUnit_Framework_TestCase protected $projectId = 0; protected $taskTitle = 'My task'; protected $taskId = 0; + protected $subtaskId = 0; protected $groupName1 = 'My Group A'; protected $groupName2 = 'My Group B'; @@ -119,4 +120,14 @@ abstract class BaseProcedureTest extends PHPUnit_Framework_TestCase $this->taskId = $this->app->createTask(array('title' => $this->taskTitle, 'project_id' => $this->projectId)); $this->assertNotFalse($this->taskId); } + + public function assertCreateSubtask() + { + $this->subtaskId = $this->app->createSubtask(array( + 'task_id' => $this->taskId, + 'title' => 'subtask #1', + )); + + $this->assertNotFalse($this->subtaskId); + } } diff --git a/tests/integration/SubtaskProcedureTest.php b/tests/integration/SubtaskProcedureTest.php index 7ab4ef0b..b9868e6f 100644 --- a/tests/integration/SubtaskProcedureTest.php +++ b/tests/integration/SubtaskProcedureTest.php @@ -5,7 +5,6 @@ require_once __DIR__.'/BaseProcedureTest.php'; class SubtaskProcedureTest extends BaseProcedureTest { protected $projectName = 'My project to test subtasks'; - private $subtaskId = 0; public function testAll() { @@ -18,16 +17,6 @@ class SubtaskProcedureTest extends BaseProcedureTest $this->assertRemoveSubtask(); } - public function assertCreateSubtask() - { - $this->subtaskId = $this->app->createSubtask(array( - 'task_id' => $this->taskId, - 'title' => 'subtask #1', - )); - - $this->assertNotFalse($this->subtaskId); - } - public function assertGetSubtask() { $subtask = $this->app->getSubtask($this->subtaskId); diff --git a/tests/integration/SubtaskTimeTrackingProcedureTest.php b/tests/integration/SubtaskTimeTrackingProcedureTest.php new file mode 100644 index 00000000..6c45c983 --- /dev/null +++ b/tests/integration/SubtaskTimeTrackingProcedureTest.php @@ -0,0 +1,46 @@ +assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertCreateSubtask(); + $this->assertHasNoTimer(); + $this->assertStartTimer(); + $this->assertHasTimer(); + $this->assertStopTimer(); + $this->assertHasNoTimer(); + $this->assertGetSubtaskTimeSpent(); + } + + public function assertHasNoTimer() + { + $this->assertFalse($this->app->hasSubtaskTimer($this->subtaskId, $this->userUserId)); + } + + public function assertHasTimer() + { + $this->assertTrue($this->app->hasSubtaskTimer($this->subtaskId, $this->userUserId)); + } + + public function assertStartTimer() + { + $this->assertTrue($this->app->setSubtaskStartTime($this->subtaskId, $this->userUserId)); + } + + public function assertStopTimer() + { + $this->assertTrue($this->app->setSubtaskEndTime($this->subtaskId, $this->userUserId)); + } + + public function assertGetSubtaskTimeSpent() + { + $this->assertEquals(0, $this->app->getSubtaskTimeSpent($this->subtaskId, $this->userUserId)); + } +} -- cgit v1.2.3