Added API calls for subtask time tracking

This commit is contained in:
Frederic Guillot 2016-06-26 15:47:02 -04:00
parent f621129836
commit 82623f1a21
No known key found for this signature in database
GPG Key ID: 92D77191BA7FBC99
7 changed files with 165 additions and 16 deletions

View File

@ -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:

View File

@ -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);
}

View File

@ -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)

View File

@ -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
}
```

View File

@ -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);
}
}

View File

@ -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);

View File

@ -0,0 +1,46 @@
<?php
require_once __DIR__.'/BaseProcedureTest.php';
class SubtaskTimeTrackingProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test subtask time tracking';
public function testAll()
{
$this->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));
}
}