feat: publish assignment via context menu
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\Assignment;
|
||||
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Entity\Assignment;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class PublishController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/assignment/publish/{uuid}', name: 'app_administrative_assignment_publish')]
|
||||
public function index(Assignment $assignment, Request $request): Response
|
||||
{
|
||||
$returnUrl = $this->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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -181,6 +181,15 @@
|
||||
bearbeiten
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if is_granted('PUBLISH', assignment) %}
|
||||
<button type="button"
|
||||
class="block px-4 py-2 text-sm w-full text-left"
|
||||
role="menuitem"
|
||||
tabindex="-1"
|
||||
hx-post="{{ path('app_administrative_assignment_publish', { 'uuid': assignment.uuid }) }}">
|
||||
veröffentlichen
|
||||
</button>
|
||||
{% endif %}
|
||||
</twig:DropDown>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user