action to duplicate timesheet record (#1478)

This commit is contained in:
Kevin Papst
2020-02-18 15:32:33 +01:00
committed by GitHub
parent 7b218c33f9
commit 886fc8d74e
5 changed files with 97 additions and 1 deletions

View File

@@ -656,6 +656,47 @@ class TimesheetController extends BaseApiController
return $this->viewHandler->handle($view);
}
/**
* Duplicates an existing timesheet record
*
* @SWG\Response(
* response=200,
* description="Duplicates a timesheet record, resetting the export state only.",
* @SWG\Schema(ref="#/definitions/TimesheetEntity")
* )
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="Timesheet record ID to duplicate",
* required=true,
* )
*
* @ApiSecurity(name="apiUser")
* @ApiSecurity(name="apiToken")
*/
public function duplicateAction(int $id): Response
{
$timesheet = $this->repository->find($id);
if (null === $timesheet) {
throw new NotFoundException();
}
if (!$this->isGranted('duplicate', $timesheet)) {
throw new AccessDeniedHttpException('You are not allowed to duplicate this timesheet');
}
$copyTimesheet = clone $timesheet;
$this->service->saveNewTimesheet($copyTimesheet);
$view = new View($copyTimesheet, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Timesheet']);
return $this->viewHandler->handle($view);
}
/**
* Switch the export state of a timesheet record to (un-)lock it
*