diff --git a/src/API/TimesheetController.php b/src/API/TimesheetController.php index 7ca7ddea..e2ce8124 100644 --- a/src/API/TimesheetController.php +++ b/src/API/TimesheetController.php @@ -36,6 +36,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; use Swagger\Annotations as SWG; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\Validator\Constraints; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -704,6 +705,11 @@ class TimesheetController extends BaseApiController public function exportAction(Timesheet $id): Response { $timesheet = $id; + + if ($timesheet->isExported() && !$this->isGranted('edit_exported_timesheet')) { + throw new AccessDeniedHttpException('User cannot edit an exported timesheet'); + } + $timesheet->setExported(!$timesheet->isExported()); $this->service->updateTimesheet($timesheet); diff --git a/src/Validator/Constraints/TimesheetExportedValidator.php b/src/Validator/Constraints/TimesheetExportedValidator.php index f550faa0..4e90f911 100644 --- a/src/Validator/Constraints/TimesheetExportedValidator.php +++ b/src/Validator/Constraints/TimesheetExportedValidator.php @@ -42,7 +42,11 @@ final class TimesheetExportedValidator extends ConstraintValidator return; } - if (null !== $this->security->getUser() && $this->security->isGranted('edit_exported_timesheet')) { + // this was "edit_exported_timesheet" before, but that was wrong, because the first time this + // can trigger is the moment when the "export" flag ist set from the "edit form". + // most teamleads should not have "edit_exported_timesheet" but only "edit_export_other_timesheet" + + if (null !== $this->security->getUser() && $this->security->isGranted('edit_export', $timesheet)) { return; } diff --git a/templates/export/index.html.twig b/templates/export/index.html.twig index 968063e5..729b720d 100644 --- a/templates/export/index.html.twig +++ b/templates/export/index.html.twig @@ -17,6 +17,7 @@ } %} {% set tableName = 'export' %} +{% set editExported = is_granted('edit_exported_timesheet') %} {% block page_title %}{{ 'export.title'|trans }}{% endblock %} {% block page_actions %} @@ -185,10 +186,14 @@ {% if is_granted('edit_export', entry) %} {% if entry.exported %} + {% if editExported %} + {% else %} + {{ 'entryState.exported'|trans }} + {% endif %} {% else %}