action to duplicate timesheet record (#1478)
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -45,7 +45,7 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
public const CATEGORY_WORK = 'work';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* @var int|null
|
||||
*
|
||||
* @ORM\Column(name="id", type="integer")
|
||||
* @ORM\Id
|
||||
@@ -537,4 +537,12 @@ class Timesheet implements EntityWithMetaFields, ExportItemInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->id) {
|
||||
$this->id = null;
|
||||
$this->exported = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class TimesheetVoter extends AbstractVoter
|
||||
self::VIEW_RATE,
|
||||
self::EDIT_RATE,
|
||||
self::EDIT_EXPORT,
|
||||
'duplicate'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -99,6 +100,10 @@ class TimesheetVoter extends AbstractVoter
|
||||
$permission .= $attribute;
|
||||
break;
|
||||
|
||||
case 'duplicate':
|
||||
$permission = self::EDIT;
|
||||
break;
|
||||
|
||||
case self::VIEW_RATE:
|
||||
case self::EDIT_RATE:
|
||||
case self::STOP:
|
||||
|
||||
Reference in New Issue
Block a user