feat: let managers edit the staffing matrix

This commit is contained in:
fromme committed 2026-11-05 17:18:26 +01:00
1 parent f9d2ff084d
commit 4ff963d1e2
15 files changed
+84 -52

No files matched your search

@@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller\Admin\System\StaffingRule; namespace App\Controller\Administrative\System\StaffingRule;
use App\Entity\StaffingRule; use App\Entity\StaffingRule;
use App\Form\StaffingRuleType; use App\Form\StaffingRuleType;
@@ -21,8 +21,8 @@ class CreateController extends AbstractController
) { ) {
} }
#[Route('/admin/system/staffing-rule/create', name: 'app_admin_system_staffing_rule_create')] #[Route('/administrative/system/staffing-rule/create', name: 'app_administrative_system_staffing_rule_create')]
#[IsGranted('ROLE_TEAM_ADMIN')] #[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response public function index(Request $request): Response
{ {
$rule = new StaffingRule(); $rule = new StaffingRule();
@@ -39,10 +39,10 @@ class CreateController extends AbstractController
'product_code' => $rule->getProductCode(), 'product_code' => $rule->getProductCode(),
]); ]);
return new HxRedirectResponse($this->generateUrl('app_admin_system_staffing_rule_index')); return new HxRedirectResponse($this->generateUrl('app_administrative_system_staffing_rule_index'));
} }
return $this->render('admin/system/staffing_rule/modal_create.html.twig', [ return $this->render('administrative/system/staffing_rule/modal_create.html.twig', [
'form' => $form->createView(), 'form' => $form->createView(),
]); ]);
} }
@@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller\Admin\System\StaffingRule; namespace App\Controller\Administrative\System\StaffingRule;
use App\Entity\StaffingRule; use App\Entity\StaffingRule;
use App\Htmx\HxRedirectResponse; use App\Htmx\HxRedirectResponse;
@@ -20,8 +20,8 @@ class DeleteController extends AbstractController
) { ) {
} }
#[Route('/admin/system/staffing-rule/delete/{uuid}', name: 'app_admin_system_staffing_rule_delete')] #[Route('/administrative/system/staffing-rule/delete/{uuid}', name: 'app_administrative_system_staffing_rule_delete')]
#[IsGranted('ROLE_TEAM_ADMIN')] #[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(StaffingRule $rule, Request $request): Response public function index(StaffingRule $rule, Request $request): Response
{ {
if (true === $request->isMethod('POST')) { if (true === $request->isMethod('POST')) {
@@ -34,10 +34,10 @@ class DeleteController extends AbstractController
'product_code' => $rule->getProductCode(), 'product_code' => $rule->getProductCode(),
]); ]);
return new HxRedirectResponse($this->generateUrl('app_admin_system_staffing_rule_index')); return new HxRedirectResponse($this->generateUrl('app_administrative_system_staffing_rule_index'));
} }
return $this->render('admin/system/staffing_rule/modal_delete.html.twig', [ return $this->render('administrative/system/staffing_rule/modal_delete.html.twig', [
'rule' => $rule, 'rule' => $rule,
]); ]);
} }
@@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller\Admin\System\StaffingRule; namespace App\Controller\Administrative\System\StaffingRule;
use App\Entity\StaffingRule; use App\Entity\StaffingRule;
use App\Form\StaffingRuleType; use App\Form\StaffingRuleType;
@@ -21,8 +21,8 @@ class EditController extends AbstractController
) { ) {
} }
#[Route('/admin/system/staffing-rule/edit/{uuid}', name: 'app_admin_system_staffing_rule_edit')] #[Route('/administrative/system/staffing-rule/edit/{uuid}', name: 'app_administrative_system_staffing_rule_edit')]
#[IsGranted('ROLE_TEAM_ADMIN')] #[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(StaffingRule $rule, Request $request): Response public function index(StaffingRule $rule, Request $request): Response
{ {
$form = $this->createForm(StaffingRuleType::class, $rule); $form = $this->createForm(StaffingRuleType::class, $rule);
@@ -37,10 +37,10 @@ class EditController extends AbstractController
'product_code' => $rule->getProductCode(), 'product_code' => $rule->getProductCode(),
]); ]);
return new HxRedirectResponse($this->generateUrl('app_admin_system_staffing_rule_index')); return new HxRedirectResponse($this->generateUrl('app_administrative_system_staffing_rule_index'));
} }
return $this->render('admin/system/staffing_rule/modal_edit.html.twig', [ return $this->render('administrative/system/staffing_rule/modal_edit.html.twig', [
'form' => $form->createView(), 'form' => $form->createView(),
]); ]);
} }
@@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller\Admin\System\StaffingRule; namespace App\Controller\Administrative\System\StaffingRule;
use App\Service\Assignment\StaffingConfigurationException; use App\Service\Assignment\StaffingConfigurationException;
use App\Service\Export\StaffingPreviewExporter; use App\Service\Export\StaffingPreviewExporter;
@@ -21,8 +21,8 @@ class ExportController extends AbstractController
) { ) {
} }
#[Route('/admin/system/staffing-rule/export', name: 'app_admin_system_staffing_rule_export')] #[Route('/administrative/system/staffing-rule/export', name: 'app_administrative_system_staffing_rule_export')]
#[IsGranted('ROLE_TEAM_ADMIN')] #[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(): Response public function index(): Response
{ {
try { try {
@@ -30,13 +30,13 @@ class ExportController extends AbstractController
} catch (StaffingConfigurationException $e) { } catch (StaffingConfigurationException $e) {
$this->addFlash('error', 'Ein Jobprofil oder Honorar der Besetzungsmatrix ist nicht (mehr) vorhanden: '.$e->getMessage()); $this->addFlash('error', 'Ein Jobprofil oder Honorar der Besetzungsmatrix ist nicht (mehr) vorhanden: '.$e->getMessage());
return $this->redirectToRoute('app_admin_system_staffing_rule_index'); return $this->redirectToRoute('app_administrative_system_staffing_rule_index');
} }
if ([] === $rows) { if ([] === $rows) {
$this->addFlash('error', 'Keine Daten für den Export vorhanden'); $this->addFlash('error', 'Keine Daten für den Export vorhanden');
return $this->redirectToRoute('app_admin_system_staffing_rule_preview'); return $this->redirectToRoute('app_administrative_system_staffing_rule_preview');
} }
$spreadsheet = $this->previewExporter->export($rows); $spreadsheet = $this->previewExporter->export($rows);
@@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller\Admin\System\StaffingRule; namespace App\Controller\Administrative\System\StaffingRule;
use App\Repository\StaffingRuleRepository; use App\Repository\StaffingRuleRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -14,11 +14,11 @@ class IndexController extends AbstractController
{ {
} }
#[Route('/admin/system/staffing-rule', name: 'app_admin_system_staffing_rule_index')] #[Route('/administrative/system/staffing-rule', name: 'app_administrative_system_staffing_rule_index')]
#[IsGranted('ROLE_TEAM_ADMIN')] #[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(): Response public function index(): Response
{ {
return $this->render('admin/system/staffing_rule/index.html.twig', [ return $this->render('administrative/system/staffing_rule/index.html.twig', [
'rules' => $this->staffingRuleRepository->getList(), 'rules' => $this->staffingRuleRepository->getList(),
]); ]);
} }
@@ -1,6 +1,6 @@
<?php <?php
namespace App\Controller\Admin\System\StaffingRule; namespace App\Controller\Administrative\System\StaffingRule;
use App\Service\Assignment\StaffingConfigurationException; use App\Service\Assignment\StaffingConfigurationException;
use App\Service\Export\StaffingPreviewExporter; use App\Service\Export\StaffingPreviewExporter;
@@ -19,8 +19,8 @@ class PreviewController extends AbstractController
) { ) {
} }
#[Route('/admin/system/staffing-rule/preview', name: 'app_admin_system_staffing_rule_preview')] #[Route('/administrative/system/staffing-rule/preview', name: 'app_administrative_system_staffing_rule_preview')]
#[IsGranted('ROLE_TEAM_ADMIN')] #[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(Request $request): Response public function index(Request $request): Response
{ {
try { try {
@@ -28,7 +28,7 @@ class PreviewController extends AbstractController
} catch (StaffingConfigurationException $e) { } catch (StaffingConfigurationException $e) {
$this->addFlash('error', 'Ein Jobprofil oder Honorar der Besetzungsmatrix ist nicht (mehr) vorhanden: '.$e->getMessage()); $this->addFlash('error', 'Ein Jobprofil oder Honorar der Besetzungsmatrix ist nicht (mehr) vorhanden: '.$e->getMessage());
return $this->redirectToRoute('app_admin_system_staffing_rule_index'); return $this->redirectToRoute('app_administrative_system_staffing_rule_index');
} }
// The candidates are a computed list, not a query: page the finished rows. The Excel // The candidates are a computed list, not a query: page the finished rows. The Excel
@@ -39,7 +39,7 @@ class PreviewController extends AbstractController
$request->query->getInt('limit', 50), $request->query->getInt('limit', 50),
); );
return $this->render('admin/system/staffing_rule/preview.html.twig', [ return $this->render('administrative/system/staffing_rule/preview.html.twig', [
'pagination' => $pagination, 'pagination' => $pagination,
]); ]);
} }
+2 -2
View File
@@ -279,13 +279,13 @@ class AdminMenuBuilder extends AbstractMenuBuilder
], ],
]); ]);
$settingsMenu->addChild('Besetzungsmatrix', [ $settingsMenu->addChild('Besetzungsmatrix', [
'route' => 'app_admin_system_staffing_rule_index', 'route' => 'app_administrative_system_staffing_rule_index',
'linkAttributes' => [ 'linkAttributes' => [
'title' => 'Besetzungsmatrix', 'title' => 'Besetzungsmatrix',
], ],
'extras' => [ 'extras' => [
'routes' => [ 'routes' => [
['pattern' => '/^app_admin_system_staffing_rule_/'], ['pattern' => '/^app_administrative_system_staffing_rule_/'],
], ],
], ],
]); ]);
+11
View File
@@ -167,6 +167,17 @@ class ManagerMenuBuilder extends AbstractMenuBuilder
'icon' => 'settings', 'icon' => 'settings',
], ],
]); ]);
$settingsMenu->addChild('Besetzungsmatrix', [
'route' => 'app_administrative_system_staffing_rule_index',
'linkAttributes' => [
'title' => 'Besetzungsmatrix',
],
'extras' => [
'routes' => [
['pattern' => '/^app_administrative_system_staffing_rule_/'],
],
],
]);
$settingsMenu->addChild('Reisen', [ $settingsMenu->addChild('Reisen', [
'route' => 'app_administrative_system_destination_index', 'route' => 'app_administrative_system_destination_index',
'linkAttributes' => [ 'linkAttributes' => [
@@ -1,4 +1,4 @@
{% extends 'admin/layout.html.twig' %} {% extends 'administrative/layout.html.twig' %}
{% block title %}Einstellungen - Besetzungsmatrix{% endblock %} {% block title %}Einstellungen - Besetzungsmatrix{% endblock %}
@@ -9,7 +9,7 @@
<h1 class="text-2xl font-bold"> <h1 class="text-2xl font-bold">
Besetzungsmatrix Besetzungsmatrix
</h1> </h1>
<a href="{{ path('app_admin_system_staffing_rule_preview') }}" class="btn"> <a href="{{ path('app_administrative_system_staffing_rule_preview') }}" class="btn">
Vorschau Vorschau
</a> </a>
</div> </div>
@@ -53,14 +53,14 @@
<button type="button" <button type="button"
class="text-red-500" class="text-red-500"
title="Zeile löschen" title="Zeile löschen"
hx-get="{{ path('app_admin_system_staffing_rule_delete', { 'uuid': rule.uuid }) }}" hx-get="{{ path('app_administrative_system_staffing_rule_delete', { 'uuid': rule.uuid }) }}"
hx-target="body" hx-target="body"
hx-swap="beforeend"> hx-swap="beforeend">
{{ icon('delete') }} {{ icon('delete') }}
</button> </button>
<button type="button" <button type="button"
title="Zeile bearbeiten" title="Zeile bearbeiten"
hx-get="{{ path('app_admin_system_staffing_rule_edit', { 'uuid': rule.uuid }) }}" hx-get="{{ path('app_administrative_system_staffing_rule_edit', { 'uuid': rule.uuid }) }}"
hx-target="body" hx-target="body"
hx-swap="beforeend"> hx-swap="beforeend">
{{ icon('edit') }} {{ icon('edit') }}
@@ -82,7 +82,7 @@
<button type="button" <button type="button"
class="btn" class="btn"
title="Zeile hinzufügen" title="Zeile hinzufügen"
hx-get="{{ path('app_admin_system_staffing_rule_create') }}" hx-get="{{ path('app_administrative_system_staffing_rule_create') }}"
hx-target="body" hx-target="body"
hx-swap="beforeend"> hx-swap="beforeend">
Zeile hinzufügen Zeile hinzufügen
@@ -3,5 +3,5 @@
{% block title %}Zeile hinzufügen{% endblock %} {% block title %}Zeile hinzufügen{% endblock %}
{% block content %} {% block content %}
{% include 'admin/system/staffing_rule/_form.html.twig' %} {% include 'administrative/system/staffing_rule/_form.html.twig' %}
{% endblock %} {% endblock %}
@@ -3,5 +3,5 @@
{% block title %}Zeile bearbeiten{% endblock %} {% block title %}Zeile bearbeiten{% endblock %}
{% block content %} {% block content %}
{% include 'admin/system/staffing_rule/_form.html.twig' %} {% include 'administrative/system/staffing_rule/_form.html.twig' %}
{% endblock %} {% endblock %}
@@ -1,4 +1,4 @@
{% extends 'admin/layout.html.twig' %} {% extends 'administrative/layout.html.twig' %}
{% block title %}Einstellungen - Besetzungsmatrix - Vorschau{% endblock %} {% block title %}Einstellungen - Besetzungsmatrix - Vorschau{% endblock %}
@@ -8,10 +8,10 @@
Besetzungsmatrix – Vorschau Besetzungsmatrix – Vorschau
</h1> </h1>
<div class="flex items-center space-x-2"> <div class="flex items-center space-x-2">
<a href="{{ path('app_admin_system_staffing_rule_index') }}" class="btn"> <a href="{{ path('app_administrative_system_staffing_rule_index') }}" class="btn">
Zurück zur Matrix Zurück zur Matrix
</a> </a>
<a href="{{ path('app_admin_system_staffing_rule_export') }}" class="btn"> <a href="{{ path('app_administrative_system_staffing_rule_export') }}" class="btn">
Excel-Export Excel-Export
</a> </a>
</div> </div>
@@ -2,7 +2,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Controller\Admin\System\StaffingRule; namespace App\Tests\Controller\Administrative\System\StaffingRule;
use App\Entity\User; use App\Entity\User;
use App\Repository\StaffingRuleRepository; use App\Repository\StaffingRuleRepository;
@@ -29,7 +29,7 @@ class StaffingRuleControllerTest extends WebTestCase
$this->resetStaffingTables(self::getContainer()->get(Connection::class)); $this->resetStaffingTables(self::getContainer()->get(Connection::class));
$this->entityManager->createQuery(sprintf('DELETE FROM %s', User::class))->execute(); $this->entityManager->createQuery(sprintf('DELETE FROM %s', User::class))->execute();
$this->client->loginUser($this->admin()); $this->client->loginUser($this->user('ROLE_TEAM_ADMIN'));
} }
public function testARuleIsCreatedWithItsCodeNormalized(): void public function testARuleIsCreatedWithItsCodeNormalized(): void
@@ -44,12 +44,33 @@ class StaffingRuleControllerTest extends WebTestCase
$this->assertTrue($rules[0]->isSkiBeginner()); $this->assertTrue($rules[0]->isSkiBeginner());
$this->assertFalse($rules[0]->isEnabled()); $this->assertFalse($rules[0]->isEnabled());
$this->client->request('GET', '/admin/system/staffing-rule'); $this->client->request('GET', '/administrative/system/staffing-rule');
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
$this->assertStringContainsString('DKIMP', (string) $this->client->getResponse()->getContent()); $this->assertStringContainsString('DKIMP', (string) $this->client->getResponse()->getContent());
} }
public function testAManagerEditsTheMatrixToo(): void
{
$this->client->loginUser($this->user('ROLE_MANAGER'));
$this->submitCreate('DKIMP');
$this->assertCount(1, $this->repository()->getList());
$this->client->request('GET', '/administrative/system/staffing-rule/preview');
$this->assertResponseIsSuccessful();
}
public function testATeamerIsRefused(): void
{
$this->client->loginUser($this->user('ROLE_TEAMER'));
$this->client->request('GET', '/administrative/system/staffing-rule');
// the access-denied handler sends a teamer home instead of answering 403
$this->assertResponseRedirects('/teamer');
}
public function testASecondRowForTheSameProductIsRefused(): void public function testASecondRowForTheSameProductIsRefused(): void
{ {
$this->submitCreate('DKIMP'); $this->submitCreate('DKIMP');
@@ -74,7 +95,7 @@ class StaffingRuleControllerTest extends WebTestCase
{ {
$this->submitCreate('DKIMP'); $this->submitCreate('DKIMP');
$this->client->request('GET', '/admin/system/staffing-rule/preview'); $this->client->request('GET', '/administrative/system/staffing-rule/preview');
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
$this->assertStringContainsString('Keine Termine', (string) $this->client->getResponse()->getContent()); $this->assertStringContainsString('Keine Termine', (string) $this->client->getResponse()->getContent());
@@ -86,7 +107,7 @@ class StaffingRuleControllerTest extends WebTestCase
$this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP'); $this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP');
$this->entityManager->flush(); $this->entityManager->flush();
$this->client->request('GET', '/admin/system/staffing-rule/preview'); $this->client->request('GET', '/administrative/system/staffing-rule/preview');
$content = (string) $this->client->getResponse()->getContent(); $content = (string) $this->client->getResponse()->getContent();
@@ -109,7 +130,7 @@ class StaffingRuleControllerTest extends WebTestCase
$this->entityManager->flush(); $this->entityManager->flush();
// same date: ordered by product code // same date: ordered by product code
$this->client->request('GET', '/admin/system/staffing-rule/preview?limit=1&page=2'); $this->client->request('GET', '/administrative/system/staffing-rule/preview?limit=1&page=2');
$content = (string) $this->client->getResponse()->getContent(); $content = (string) $this->client->getResponse()->getContent();
@@ -124,7 +145,7 @@ class StaffingRuleControllerTest extends WebTestCase
$this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP'); $this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP');
$this->entityManager->flush(); $this->entityManager->flush();
$this->client->request('GET', '/admin/system/staffing-rule/export'); $this->client->request('GET', '/administrative/system/staffing-rule/export');
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); $this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
$this->assertSame( $this->assertSame(
@@ -135,7 +156,7 @@ class StaffingRuleControllerTest extends WebTestCase
private function submitCreate(string $productCode): void private function submitCreate(string $productCode): void
{ {
$crawler = $this->client->request('GET', '/admin/system/staffing-rule/create'); $crawler = $this->client->request('GET', '/administrative/system/staffing-rule/create');
$form = $crawler->filter('form')->form([ $form = $crawler->filter('form')->form([
'staffing_rule[productCode]' => $productCode, 'staffing_rule[productCode]' => $productCode,
'staffing_rule[guides]' => '2', 'staffing_rule[guides]' => '2',
@@ -152,13 +173,13 @@ class StaffingRuleControllerTest extends WebTestCase
return self::getContainer()->get(StaffingRuleRepository::class); return self::getContainer()->get(StaffingRuleRepository::class);
} }
private function admin(): User private function user(string $role): User
{ {
$user = (new User()) $user = (new User())
->setFirstName('Anna') ->setFirstName('Anna')
->setLastName('Admin') ->setLastName('Admin')
->setEmail('anna.admin@example.com') ->setEmail(sprintf('%s@example.com', strtolower($role)))
->setRoles(['ROLE_TEAM_ADMIN']) ->setRoles([$role])
->setBusProAddressId(1) ->setBusProAddressId(1)
->setBusProPersonId(1) ->setBusProPersonId(1)
; ;