Feat: Make dispositions deletable by admins
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20231021084644 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE disposition DROP deleted_at');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE disposition ADD deleted_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\Disposition;
|
||||||
|
|
||||||
|
use App\Entity\Disposition;
|
||||||
|
use App\Event\DispositionDeletedEvent;
|
||||||
|
use App\Model\AjaxModalResponseDto;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
|
class DeleteController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly EventDispatcherInterface $eventDispatcher,
|
||||||
|
private readonly LoggerInterface $logger
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/disposition/delete/{uuid}', name: 'app_admin_disposition_delete')]
|
||||||
|
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||||
|
#[IsGranted('DELETE', subject: 'disposition')]
|
||||||
|
public function index(Disposition $disposition, Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
$response = new AjaxModalResponseDto();
|
||||||
|
$formAction = $this->generateUrl('app_admin_disposition_delete', ['uuid' => $disposition->getUuid()]);
|
||||||
|
$form = $this
|
||||||
|
->createFormBuilder($disposition, ['action' => $formAction, 'ajax_submit' => true])
|
||||||
|
->add('remarks', TextareaType::class, [
|
||||||
|
'label' => 'Kommentar/Begründung',
|
||||||
|
'required' => false,
|
||||||
|
'attr' => [
|
||||||
|
'rows' => 3,
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->getForm()
|
||||||
|
;
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
$this->eventDispatcher->dispatch(new DispositionDeletedEvent($disposition), DispositionDeletedEvent::NAME);
|
||||||
|
|
||||||
|
$this->entityManager->remove($disposition);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$this->addFlash('success', 'Die Einteilung wurde gelöscht');
|
||||||
|
$this->logger->info('Delete disposition', [
|
||||||
|
'disposition_id' => $disposition->getId(),
|
||||||
|
'teamer' => (string) $disposition->getTeamer(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->setCloseAndRedirect($this->generateUrl('app_admin_assignment_detail', [
|
||||||
|
'uuid' => $disposition->getAssignment()->getUuid(),
|
||||||
|
]));
|
||||||
|
} else {
|
||||||
|
$response->setContent($this->renderView('admin/disposition/delete.html.twig', [
|
||||||
|
'form' => $form,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->json($response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,11 +13,10 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
use Symfony\Component\Uid\Uuid;
|
use Symfony\Component\Uid\Uuid;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: DispositionRepository::class)]
|
#[ORM\Entity(repositoryClass: DispositionRepository::class)]
|
||||||
class Disposition implements BlameableEntityInterface, TimestampableEntityInterface, SoftDeletableEntityInterface
|
class Disposition implements BlameableEntityInterface, TimestampableEntityInterface
|
||||||
{
|
{
|
||||||
use BlameableEntity;
|
use BlameableEntity;
|
||||||
use TimestampableEntity;
|
use TimestampableEntity;
|
||||||
use SoftDeletableEntity;
|
|
||||||
|
|
||||||
public const STATUS_NEW = 'new';
|
public const STATUS_NEW = 'new';
|
||||||
public const STATUS_CHECKING_CONTRACT = 'checking_contract';
|
public const STATUS_CHECKING_CONTRACT = 'checking_contract';
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Event;
|
||||||
|
|
||||||
|
use App\Entity\Disposition;
|
||||||
|
use Symfony\Contracts\EventDispatcher\Event;
|
||||||
|
|
||||||
|
class DispositionDeletedEvent extends Event
|
||||||
|
{
|
||||||
|
public const NAME = 'disposition.deleted';
|
||||||
|
|
||||||
|
public function __construct(private readonly Disposition $disposition)
|
||||||
|
{}
|
||||||
|
|
||||||
|
public function getDisposition(): Disposition
|
||||||
|
{
|
||||||
|
return $this->disposition;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">
|
<td colspan="4">
|
||||||
Es liegen keine Bewerbungen vor...
|
Es liegen keine Bewerbungen vor...
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -143,12 +143,23 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="flex items-center justify-end space-x-2">
|
<div class="flex items-center justify-end space-x-2">
|
||||||
|
{% if is_granted('DELETE', disposition) %}
|
||||||
|
<button type="button"
|
||||||
|
class="text-red-500"
|
||||||
|
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
|
||||||
|
{{ stimulus_action('modal-button', 'ajax', null, {
|
||||||
|
'title': 'Einteilung löschen',
|
||||||
|
'url': path('app_admin_disposition_delete', { 'uuid': disposition.uuid })
|
||||||
|
}) }}>
|
||||||
|
{{ icon('delete') }}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3">
|
<td colspan="4">
|
||||||
Es gibt noch keine Einteilungen...
|
Es gibt noch keine Einteilungen...
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{{ form_start(form) }}
|
||||||
|
<div class="flex flex-col space-y-4 pb-4">
|
||||||
|
{{ form_row(form.remarks) }}
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn">
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
{{ form_rest(form) }}
|
||||||
|
{{ form_end(form) }}
|
||||||
Reference in New Issue
Block a user