API endpoint to delete timespent record
This commit is contained in:
parent
b7b322e661
commit
a9775a4413
@ -584,15 +584,7 @@ class Tasks extends DolibarrApi
|
|||||||
if (!DolibarrApiAccess::$user->rights->projet->creer) {
|
if (!DolibarrApiAccess::$user->rights->projet->creer) {
|
||||||
throw new RestException(401);
|
throw new RestException(401);
|
||||||
}
|
}
|
||||||
if ($this->task->fetch($id) <= 0) {
|
$this->_timespentRecordChecks($id, $timespent_id);
|
||||||
throw new RestException(404, 'Task not found');
|
|
||||||
}
|
|
||||||
if ($this->task->fetchTimeSpent($timespent_id) <= 0) {
|
|
||||||
throw new RestException(404, 'Timespent not found');
|
|
||||||
}
|
|
||||||
elseif ($this->task->id != $id) {
|
|
||||||
throw new RestException(404, 'Timespent not found in selected task');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
|
if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
@ -622,6 +614,51 @@ class Tasks extends DolibarrApi
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete time spent for a task of a project.
|
||||||
|
*
|
||||||
|
* @param int $id Task ID
|
||||||
|
* @param int $timespent_id Time spent ID (llx_projet_task_time.rowid)
|
||||||
|
*
|
||||||
|
* @url DELETE {id}/timespent/{timespent_id}
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function deleteTimeSpent($id, $timespent_id, $user_id)
|
||||||
|
{
|
||||||
|
if (!DolibarrApiAccess::$user->rights->projet->supprimer) {
|
||||||
|
throw new RestException(401);
|
||||||
|
}
|
||||||
|
$this->_timespentRecordChecks($id, $timespent_id);
|
||||||
|
|
||||||
|
if (!DolibarrApi::_checkAccessToResource('task', $this->task->id)) {
|
||||||
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->task->delTimeSpent(DolibarrApiAccess::$user, 0) < 0) {
|
||||||
|
throw new RestException(500, 'Error when deleting time spent: '.$this->task->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'success' => array(
|
||||||
|
'code' => 200,
|
||||||
|
'message' => 'Time spent deleted'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _timespentRecordChecks($id, $timespent_id) {
|
||||||
|
if ($this->task->fetch($id) <= 0) {
|
||||||
|
throw new RestException(404, 'Task not found');
|
||||||
|
}
|
||||||
|
if ($this->task->fetchTimeSpent($timespent_id) <= 0) {
|
||||||
|
throw new RestException(404, 'Timespent not found');
|
||||||
|
}
|
||||||
|
elseif ($this->task->id != $id) {
|
||||||
|
throw new RestException(404, 'Timespent not found in selected task');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
|
||||||
/**
|
/**
|
||||||
* Clean sensible object datas
|
* Clean sensible object datas
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user