Fix: Add dedicated process for withdrawal of applications by teamer

This commit is contained in:
Björn Fromme
2023-10-21 10:20:24 +02:00
parent e3dc2b22fd
commit 0fce77fbb7
3 changed files with 22 additions and 15 deletions
@@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Security\Http\Attribute\IsGranted;
class DeleteController extends AbstractController class WithdrawController extends AbstractController
{ {
use ReturnUrlTrait; use ReturnUrlTrait;
@@ -23,8 +23,8 @@ class DeleteController extends AbstractController
) { ) {
} }
#[Route('/teamer/application/delete/{uuid}', name: 'app_teamer_application_delete')] #[Route('/teamer/application/withdraw/{uuid}', name: 'app_teamer_application_withdraw')]
#[IsGranted('DELETE', subject: 'application')] #[IsGranted('WITHDRAW', subject: 'application')]
public function index(Application $application, Request $request): Response public function index(Application $application, Request $request): Response
{ {
/** @var User $user */ /** @var User $user */
@@ -35,7 +35,7 @@ class DeleteController extends AbstractController
$this->entityManager->remove($application); $this->entityManager->remove($application);
$this->entityManager->flush(); $this->entityManager->flush();
$this->logger->info('Delete application', [ $this->logger->info('Withdraw application', [
'teamer_id' => $teamer->getId(), 'teamer_id' => $teamer->getId(),
'teamer_name' => (string) $teamer, 'teamer_name' => (string) $teamer,
'application_id' => $application->getId(), 'application_id' => $application->getId(),
+17 -10
View File
@@ -11,6 +11,7 @@ class ApplicationVoter extends Voter
{ {
public const VIEW = 'VIEW'; public const VIEW = 'VIEW';
public const DELETE = 'DELETE'; public const DELETE = 'DELETE';
public const WITHDRAW = 'WITHDRAW';
public const DISPOSE = 'DISPOSE'; public const DISPOSE = 'DISPOSE';
public const STATUS = 'STATUS'; public const STATUS = 'STATUS';
@@ -20,7 +21,7 @@ class ApplicationVoter extends Voter
return false; return false;
} }
return in_array($attribute, [static::VIEW, static::DELETE, static::DISPOSE, static::STATUS]); return in_array($attribute, [static::VIEW, static::WITHDRAW, static::DELETE, static::DISPOSE, static::STATUS]);
} }
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
@@ -30,24 +31,30 @@ class ApplicationVoter extends Voter
/** @var Application $application */ /** @var Application $application */
$application = $subject; $application = $subject;
$status = $application->getStatus();
if ($user->hasRole('ROLE_ADMINISTRATIVE')) { $adminAttributes = [static::VIEW, static::DELETE, static::DISPOSE, static::STATUS];
$teamerAttributes = [static::VIEW, static::WITHDRAW, static::DELETE, static::STATUS];
if ($user->hasRole('ROLE_ADMINISTRATIVE') && in_array($attribute, $adminAttributes)) {
$assignment = $application->getAssignment(); $assignment = $application->getAssignment();
return match ($attribute) { return match ($attribute) {
static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $application->getStatus(), static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $status,
static::DELETE => Application::STATUS_REJECTED === $application->getStatus(), static::DELETE => Application::STATUS_REJECTED === $status,
static::DISPOSE => Application::STATUS_REJECTED !== $application->getStatus() static::DISPOSE => Application::STATUS_REJECTED !== $status
&& $assignment->getAvailableDispositions() > $assignment->getDispositions()->count(), && $assignment->getAvailableDispositions() > $assignment->getDispositions()->count(),
default => false, default => false,
}; };
} }
if ($user->hasRole('ROLE_TEAMER')) { if ($user->hasRole('ROLE_TEAMER') && in_array($attribute, $teamerAttributes)) {
$teamer = $user->getTeamer();
return match ($attribute) { return match ($attribute) {
static::DELETE => $user->getTeamer() === $application->getTeamer() static::WITHDRAW => $teamer === $application->getTeamer(),
&& Application::STATUS_REJECTED === $application->getStatus(), static::DELETE => $teamer === $application->getTeamer()
static::VIEW => $user->getTeamer() === $application->getTeamer() && Application::STATUS_REJECTED === $status,
&& Application::STATUS_REJECTED !== $application->getStatus(), static::VIEW => $teamer === $application->getTeamer()
&& Application::STATUS_REJECTED !== $status,
default => false, default => false,
}; };
} }
+1 -1
View File
@@ -31,7 +31,7 @@
{{ stimulus_action('modal-button', 'confirmation', null, { {{ stimulus_action('modal-button', 'confirmation', null, {
'title': 'Bist du sicher?', 'title': 'Bist du sicher?',
'content': 'Möchtest du die Bewerbing wirklich zurückziehen?', 'content': 'Möchtest du die Bewerbing wirklich zurückziehen?',
'target-url': path('app_teamer_application_delete', { 'uuid': application.uuid }) 'target-url': path('app_teamer_application_withdraw', { 'uuid': application.uuid })
}) }}> }) }}>
Bewerbung zurückziehen Bewerbung zurückziehen
</button> </button>