copy timesheet meta fields on restart record (#1030)

This commit is contained in:
Kevin Papst
2019-08-13 18:41:20 +02:00
committed by GitHub
parent 5affa0de82
commit 455861ec69
2 changed files with 27 additions and 19 deletions

View File

@@ -409,8 +409,6 @@ class TimesheetController extends BaseApiController
* required=true,
* )
*
* @Security("is_granted('delete_own_timesheet') or is_granted('delete_other_timesheet')")
*
* @param int $id
* @return Response
*/
@@ -523,8 +521,6 @@ class TimesheetController extends BaseApiController
* required=true,
* )
*
* @Security("is_granted('stop_own_timesheet') or is_granted('stop_other_timesheet')")
*
* @param int $id
* @return Response
* @throws \App\Repository\RepositoryException
@@ -568,9 +564,7 @@ class TimesheetController extends BaseApiController
* required=true,
* )
*
* @Rest\RequestParam(name="copy", requirements="all|tags|description", strict=true, nullable=true, description="Whether description and tags are copied to the new entry. Allowed values: all, tags, description (default: nothing is copied)")
*
* @Security("is_granted('start_own_timesheet') or is_granted('start_other_timesheet')")
* @Rest\RequestParam(name="copy", requirements="all|tags|description", strict=true, nullable=true, description="Whether description and tags are copied to the new entry. Allowed values: all, tags, description, meta (default: nothing is copied)")
*
* @param int $id
* @return Response
@@ -582,8 +576,6 @@ class TimesheetController extends BaseApiController
{
/** @var Timesheet $timesheet */
$timesheet = $this->repository->find($id);
/** @var User $user */
$user = $this->getUser();
if (null === $timesheet) {
throw new NotFoundException();
@@ -593,6 +585,9 @@ class TimesheetController extends BaseApiController
throw new AccessDeniedHttpException('You are not allowed to re-start this timesheet');
}
/** @var User $user */
$user = $this->getUser();
$entry = new Timesheet();
$entry
->setBegin($this->dateTime->createDateTime())
@@ -611,6 +606,13 @@ class TimesheetController extends BaseApiController
$entry->addTag($tag);
}
}
if (in_array($copy, ['meta', 'all'])) {
foreach ($timesheet->getMetaFields() as $metaField) {
$metaNew = clone $metaField;
$entry->setMetaField($metaNew);
}
}
}
$errors = $validator->validate($entry);
@@ -650,8 +652,6 @@ class TimesheetController extends BaseApiController
* required=true,
* )
*
* @Security("is_granted('edit_export_own_timesheet') or is_granted('edit_export_other_timesheet')")
*
* @param int $id
* @return Response
*/