-
Notifications
You must be signed in to change notification settings - Fork 0
5104: Require event organizer #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0b135c7
5104: Updated fixtures
rimi-itk 76a50aa
5104: Made event organizer required
rimi-itk 92edb10
5104: Cleaned up config
rimi-itk 3691842
Merge branch 'develop' into feature/5110-require-event-organizer
turegjorup 5ca8e9f
5110: Fix copy paste error
turegjorup 79169c8
5110: Add user filters and console command to find users without orga…
turegjorup 905ce5f
5110: Pre-fill organization when user has only one
turegjorup 64ba604
5110: Add filter for events without organization
turegjorup 02e4454
5110: Add command to fix events without organizer
turegjorup 26e991a
5110: Replace form error summary with scroll-to-first-error
turegjorup 652bbf8
5110: Fix twig-cs-fixer errors in EasyAdmin crud templates
turegjorup 566c0fd
Update src/Command/Event/FixEventsWithoutOrganizerCommand.php
turegjorup f1db3c6
Update public/scripts/form-scroll-to-error.js
turegjorup 83791dd
Update src/Command/User/ListUsersWithoutOrganizationCommand.php
turegjorup 3d04f20
5110: Remove redundant twig templates
turegjorup 75afa7a
5110: Use entity property names
turegjorup 28470d5
5110: Set 'organization' field disabled for users with only one organ…
turegjorup 08b724c
5110: Change firewall rule for dev toolbar assets to apply for both s…
turegjorup bcfcd2c
5110: Add validation requiring organization for org-role users and tr…
turegjorup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| document.addEventListener('ea.form.error', function (event) { | ||
| const form = event.detail.form; | ||
| const firstInvalid = form.querySelector(':invalid:not(:disabled)'); | ||
|
|
||
| if (firstInvalid) { | ||
| firstInvalid.scrollIntoView({ behavior: 'smooth', block: 'center' }); | ||
| firstInvalid.focus({ preventScroll: true }); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| <?php | ||
|
|
||
| namespace App\Command\Event; | ||
|
|
||
| use App\Repository\EventRepository; | ||
| use App\Repository\UserRepository; | ||
| use Doctrine\ORM\EntityManagerInterface; | ||
| use Symfony\Component\Console\Attribute\AsCommand; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
|
||
| #[AsCommand( | ||
| name: 'app:event:fix-without-organizer', | ||
| description: 'Set organization on events without organizer based on the creating user\'s organization' | ||
| )] | ||
| final class FixEventsWithoutOrganizerCommand extends Command | ||
| { | ||
| public function __construct( | ||
| private readonly EventRepository $eventRepository, | ||
| private readonly UserRepository $userRepository, | ||
| private readonly EntityManagerInterface $entityManager, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| protected function configure(): void | ||
| { | ||
| $this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Show what would be changed without persisting'); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| $io = new SymfonyStyle($input, $output); | ||
| $dryRun = $input->getOption('dry-run'); | ||
|
|
||
| if ($dryRun) { | ||
| $io->note('Running in dry-run mode. No changes will be persisted.'); | ||
| } | ||
|
|
||
| $events = $this->eventRepository->findBy(['organization' => null]); | ||
|
|
||
| if (0 === \count($events)) { | ||
| $io->success('No events found without an organization.'); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
|
|
||
| $io->info(sprintf('Found %d event(s) without an organization.', \count($events))); | ||
|
|
||
| $fixed = 0; | ||
| $skipped = []; | ||
|
|
||
| foreach ($events as $event) { | ||
| $createdBy = $event->getCreatedBy(); | ||
|
|
||
| if ('' === $createdBy) { | ||
| $skipped[] = [$event->getId(), $event->getTitle(), 'Not created by a user']; | ||
| continue; | ||
| } | ||
|
|
||
| $user = $this->userRepository->findOneBy(['mail' => $createdBy]); | ||
|
|
||
| if (null === $user) { | ||
| $skipped[] = [$event->getId(), $event->getTitle(), sprintf('User "%s" not found', $createdBy)]; | ||
| continue; | ||
| } | ||
|
|
||
| $organizations = $user->getOrganizations(); | ||
|
|
||
| if (1 !== $organizations->count()) { | ||
| $skipped[] = [$event->getId(), $event->getTitle(), sprintf('User "%s" has %d organizations', $createdBy, $organizations->count())]; | ||
| continue; | ||
| } | ||
|
|
||
| $organization = $organizations->first(); | ||
| $event->setOrganization($organization); | ||
| ++$fixed; | ||
|
|
||
| $io->text(sprintf('Event #%d "%s" → Organization "%s"', $event->getId(), $event->getTitle(), $organization)); | ||
| } | ||
|
|
||
| if (\count($skipped) > 0) { | ||
| $io->section('Skipped events'); | ||
| $io->table(['ID', 'Title', 'Reason'], $skipped); | ||
| } | ||
|
|
||
| if ($fixed > 0 && !$dryRun) { | ||
| $this->entityManager->flush(); | ||
| } | ||
|
|
||
| $io->success(sprintf('%s %d event(s).', $dryRun ? 'Would fix' : 'Fixed', $fixed)); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| namespace App\Command\User; | ||
|
|
||
| use App\Repository\UserRepository; | ||
| use App\Types\UserRoles; | ||
| use Symfony\Component\Console\Attribute\AsCommand; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
|
||
| #[AsCommand( | ||
| name: 'app:user:list-without-organization', | ||
| description: 'List users below editor role who have no organization' | ||
| )] | ||
| final class ListUsersWithoutOrganizationCommand extends Command | ||
| { | ||
| public function __construct( | ||
| private readonly UserRepository $userRepository, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int | ||
| { | ||
| $io = new SymfonyStyle($input, $output); | ||
|
|
||
| $editorOrAbove = [ | ||
| UserRoles::ROLE_EDITOR->value, | ||
| UserRoles::ROLE_ADMIN->value, | ||
| UserRoles::ROLE_SUPER_ADMIN->value, | ||
| ]; | ||
turegjorup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $qb = $this->userRepository->createQueryBuilder('u') | ||
| ->leftJoin('u.organizations', 'o') | ||
| ->where('o.id IS NULL'); | ||
|
|
||
| // Roles are stored as a JSON array in the database, so we use `LIKE` to checks if a role is in the array. | ||
| foreach ($editorOrAbove as $i => $role) { | ||
turegjorup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $qb->andWhere("u.roles NOT LIKE :role{$i}") | ||
| ->setParameter("role{$i}", "%\"{$role}\"%"); | ||
| } | ||
|
|
||
| $users = $qb->orderBy('u.name', 'ASC') | ||
| ->getQuery() | ||
| ->getResult(); | ||
|
|
||
| if (0 === \count($users)) { | ||
| $io->success('No users found matching the criteria.'); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
|
|
||
| $rows = array_map(fn ($user) => [ | ||
| $user->getId(), | ||
| $user->getName(), | ||
| $user->getMail(), | ||
| implode(', ', $user->getRoles()), | ||
| $user->isEnabled() ? 'Yes' : 'No', | ||
| ], $users); | ||
|
|
||
| $io->table( | ||
| ['ID', 'Name', 'Email', 'Roles', 'Enabled'], | ||
| $rows, | ||
| ); | ||
|
|
||
| $io->note(sprintf('Found %d user(s) without an organization who are not at least editor.', \count($users))); | ||
|
|
||
| return Command::SUCCESS; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.