diff --git a/src/Controller/Administrative/Assignment/PublishController.php b/src/Controller/Administrative/Assignment/PublishController.php new file mode 100644 index 0000000..5ce8a44 --- /dev/null +++ b/src/Controller/Administrative/Assignment/PublishController.php @@ -0,0 +1,43 @@ +getReturnUrl($request, 'app_administrative_assignment_index'); + + $assignment->setStatus(Assignment::STATUS_PUBLISHED); + $this->entityManager->flush(); + + $this->addFlash('success', 'Der Einsatz wurde veröffentlicht'); + + $this->logger->info('Publish assignment', [ + 'assignment_id' => $assignment->getId(), + 'destination' => (string) $assignment->getDestination(), + 'job_profile' => $assignment->getJobProfile()->getName(), + ]); + + return new HxRedirectResponse($returnUrl); + } +} diff --git a/src/Security/Voter/AssignmentVoter.php b/src/Security/Voter/AssignmentVoter.php index 0737ca0..95188cd 100644 --- a/src/Security/Voter/AssignmentVoter.php +++ b/src/Security/Voter/AssignmentVoter.php @@ -16,6 +16,7 @@ class AssignmentVoter extends Voter public const VIEW = 'VIEW'; public const EDIT = 'EDIT'; public const APPLY = 'APPLY'; + public const PUBLISH = 'PUBLISH'; public function __construct( private readonly Security $security, @@ -29,7 +30,7 @@ class AssignmentVoter extends Voter return false; } - return in_array($attribute, [static::VIEW, static::EDIT, static::APPLY]); + return in_array($attribute, [static::VIEW, static::EDIT, static::APPLY, static::PUBLISH]); } protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool @@ -47,6 +48,12 @@ class AssignmentVoter extends Voter return $this->security->isGranted('ROLE_ADMINISTRATIVE'); } + // Only users with administrative role may publish assignments currently in draft + if (static::PUBLISH === $attribute) { + return Assignment::STATUS_DRAFT === $assignment->getStatus() + && $this->security->isGranted('ROLE_ADMINISTRATIVE'); + } + // Only allow applications to published assignments if (Assignment::STATUS_DRAFT === $assignment->getStatus()) { return false; diff --git a/templates/administrative/assignment/index.html.twig b/templates/administrative/assignment/index.html.twig index f6a354c..fb3001c 100644 --- a/templates/administrative/assignment/index.html.twig +++ b/templates/administrative/assignment/index.html.twig @@ -181,6 +181,15 @@ bearbeiten {% endif %} + {% if is_granted('PUBLISH', assignment) %} + + {% endif %}