Skip to content

Commit 619a553

Browse files
committed
5110: Made event organizer required
1 parent 76cfaae commit 619a553

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See [keep a changelog] for information about writing changes to this log.
88

99
## [Unreleased]
1010

11-
- Updated fixtures
11+
- Updated fixtures. Made event organizer required.
1212

1313
## [1.1.6] - 2025-03-27
1414

src/Controller/Admin/EventCrudController.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
use App\Service\ImageServiceInterface;
88
use App\Types\UserRoles;
99
use Doctrine\Common\Collections\Order;
10-
use Doctrine\ORM\QueryBuilder;
1110
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
1211
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
1312
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
1413
use EasyCorp\Bundle\EasyAdminBundle\Config\Asset;
15-
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
1614
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
1715
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
1816
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
@@ -134,20 +132,22 @@ public function configureFields(string $pageName): iterable
134132
yield FormField::addFieldset('Organizer information')
135133
->setLabel(new TranslatableMessage('admin.event.organizer.headline'));
136134

137-
if ($this->isGranted(UserRoles::ROLE_EDITOR->value)) {
138-
yield AssociationField::new('organization')
139-
->setLabel(new TranslatableMessage('admin.event.edited.organization'));
140-
} else {
141-
yield AssociationField::new('organization')
142-
->setLabel(new TranslatableMessage('admin.event.edited.organization'))
143-
->setQueryBuilder(
144-
fn (QueryBuilder $queryBuilder) => $queryBuilder
145-
->select('o')
146-
->from(Organization::class, 'o')
147-
->where(':user MEMBER OF o.users')
148-
->setParameter('user', $this->getUser())
149-
);
135+
$organization = AssociationField::new('organization')
136+
->setLabel(new TranslatableMessage('admin.event.edited.organization'))
137+
// We assume at least one organization exist for non-editor users
138+
// (cf. editor stuff below).
139+
->setRequired(true)
140+
->setFormTypeOption('placeholder', new TranslatableMessage('admin.event.organizer.placeholder'));
141+
// Limit organization choices for non-editors to the organizations the user is a member of.
142+
if (!$this->isGranted(UserRoles::ROLE_EDITOR->value)) {
143+
$userOrganizations = $this->getUser()->getOrganizations();
144+
$organization
145+
->setFormTypeOption('choices', $userOrganizations)
146+
// Make sure that the user is not forced to make a choice if none exists.
147+
->setRequired($userOrganizations->count() > 0);
150148
}
149+
yield $organization;
150+
151151
yield AssociationField::new('partners')
152152
->setLabel(new TranslatableMessage('admin.event.edited.partners'))
153153
->hideOnDetail();

translations/messages+intl-icu.da.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@
653653
<source>admin.user.registrationNotes</source>
654654
<target state="translated">Ønskede arrangører</target>
655655
</trans-unit>
656+
<trans-unit id="MaqqeAe" resname="admin.event.organizer.placeholder">
657+
<source>admin.event.organizer.placeholder</source>
658+
<target state="translated">Vælg arrangør</target>
659+
</trans-unit>
656660
</body>
657661
</file>
658662
</xliff>

translations/messages+intl-icu.en.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@
653653
<source>admin.user.registrationNotes</source>
654654
<target>Requested organizers</target>
655655
</trans-unit>
656+
<trans-unit id="MaqqeAe" resname="admin.event.organizer.placeholder">
657+
<source>admin.event.organizer.placeholder</source>
658+
<target>admin.event.organizer.placeholder</target>
659+
</trans-unit>
656660
</body>
657661
</file>
658662
</xliff>

0 commit comments

Comments
 (0)