diff --git a/migrations/Version20260917130000.php b/migrations/Version20260917130000.php new file mode 100644 index 0000000..f4b9321 --- /dev/null +++ b/migrations/Version20260917130000.php @@ -0,0 +1,26 @@ +addSql('DROP INDEX uniq_resource_label ON resource'); + } + + public function down(Schema $schema): void + { + $this->addSql('CREATE UNIQUE INDEX uniq_resource_label ON resource (type, label)'); + } +} diff --git a/src/Entity/Resource.php b/src/Entity/Resource.php index 7133c0d..6b59533 100644 --- a/src/Entity/Resource.php +++ b/src/Entity/Resource.php @@ -7,15 +7,12 @@ namespace App\Entity; use App\Enum\ResourceType; use App\Repository\ResourceRepository; use Doctrine\ORM\Mapping as ORM; -use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; /** * A bookable thing: a desk, a parking spot or a portable device. */ #[ORM\Entity(repositoryClass: ResourceRepository::class)] -#[ORM\UniqueConstraint(name: 'uniq_resource_label', columns: ['type', 'label'])] -#[UniqueEntity(fields: ['type', 'label'], message: 'Diese Bezeichnung ist bereits vergeben.', errorPath: 'label')] class Resource { #[ORM\Id] diff --git a/templates/admin/_modal_resource_delete.html.twig b/templates/admin/_modal_resource_delete.html.twig index 349c1d9..be39e36 100644 --- a/templates/admin/_modal_resource_delete.html.twig +++ b/templates/admin/_modal_resource_delete.html.twig @@ -4,7 +4,8 @@ {% block content %}
- {{ resource.type.label }} {{ resource.label }} wird endgültig gelöscht. + {{ resource.type.label }} {{ resource.label }} + {%- if resource.group %} ({{ resource.group.label }}){% endif %} wird endgültig gelöscht.
{% if upcoming > 0 or past > 0 %}diff --git a/templates/booking/_modal_create.html.twig b/templates/booking/_modal_create.html.twig index fbb0b52..68f3173 100644 --- a/templates/booking/_modal_create.html.twig +++ b/templates/booking/_modal_create.html.twig @@ -24,6 +24,7 @@
{{ resource.type.label }} · {{ resource.label }} + {%- if resource.group %} · {{ resource.group.label }}{% endif %}
{% include 'booking/_fields.html.twig' %} diff --git a/templates/booking/_modal_edit.html.twig b/templates/booking/_modal_edit.html.twig index c14c4cc..0daff73 100644 --- a/templates/booking/_modal_edit.html.twig +++ b/templates/booking/_modal_edit.html.twig @@ -21,6 +21,7 @@{{ resource.type.label }} · {{ booking.date|format_datetime(pattern: 'EEEE, d. MMMM y') }} + {%- if resource.group %} · {{ resource.group.label }}{% endif %}
{% if booking.partOfSeries %} diff --git a/templates/booking/_modal_end_series.html.twig b/templates/booking/_modal_end_series.html.twig index 2cb42a2..99a4dc2 100644 --- a/templates/booking/_modal_end_series.html.twig +++ b/templates/booking/_modal_end_series.html.twig @@ -4,7 +4,8 @@ {% block content %}- {{ series.resource.label }} · {{ series.describe }} + {{ series.resource.label }} + {%- if series.resource.group %} ({{ series.resource.group.label }}){% endif %} · {{ series.describe }} {% if series.user.id != app.user.id %} — Wiederkehrende Buchung von {{ series.user.name }} {% endif %} diff --git a/templates/dashboard/index.html.twig b/templates/dashboard/index.html.twig index e7ff2df..ef391a4 100644 --- a/templates/dashboard/index.html.twig +++ b/templates/dashboard/index.html.twig @@ -33,7 +33,8 @@ {% endif %} {% if tile.mine %} - {{ tile.mine.resource.label }} + {{ tile.mine.resource.label }} + {%- if tile.mine.resource.group %} · {{ tile.mine.resource.group.label }}{% endif %} {% endif %} diff --git a/tests/Controller/Admin/ResourceAdminControllerTest.php b/tests/Controller/Admin/ResourceAdminControllerTest.php index e8ecf25..2268613 100644 --- a/tests/Controller/Admin/ResourceAdminControllerTest.php +++ b/tests/Controller/Admin/ResourceAdminControllerTest.php @@ -82,28 +82,18 @@ class ResourceAdminControllerTest extends WebTestCase self::assertTrue($created->isActive()); } - public function testADuplicateLabelIsRejectedInTheModal(): void + /** + * Labels are not unique: two desks may both be called "Schreibtisch 01", e.g. in different rooms. + */ + public function testADuplicateLabelIsAccepted(): void { $this->resource('Schreibtisch 01'); $this->client->loginUser($this->admin()); $response = $this->submit('/admin/resources/new/desk', 'resource_form', ['label' => 'Schreibtisch 01']); - self::assertSame(Response::HTTP_UNPROCESSABLE_ENTITY, $response->getStatusCode()); - self::assertStringContainsString('bereits vergeben', (string) $response->getContent()); - } - - /** - * The same label is fine for another type -- uniqueness is per type, like the database's. - */ - public function testTheSameLabelMayExistForAnotherType(): void - { - $this->resource('A1'); - $this->client->loginUser($this->admin()); - - $response = $this->submit('/admin/resources/new/parking', 'resource_form', ['label' => 'A1']); - self::assertSame('/admin/resources', $response->headers->get('HX-Redirect')); + self::assertCount(2, $this->em->getRepository(Resource::class)->findBy(['label' => 'Schreibtisch 01'])); } /**