Skip to content

Commit

Permalink
[Unregistartion] update validation groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg committed Oct 10, 2024
1 parent 2520322 commit 58ae769
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Adherent/Unregistration/UnregistrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

class UnregistrationCommand
{
#[Assert\Choice(choices: Unregistration::REASONS_LIST_ADHERENT, multiple: true, groups: ['unregister'])]
#[Assert\NotBlank(message: 'adherent.unregistration.reasons')]
#[Assert\Choice(choices: Unregistration::REASONS_LIST_ADHERENT, multiple: true, groups: ['unregister_adherent'])]
#[Assert\Choice(choices: Unregistration::REASONS_LIST_USER, multiple: true, groups: ['unregister_user'])]
#[Assert\NotBlank(message: 'adherent.unregistration.reasons', groups: ['unregister'])]
#[Groups('unregister')]
private array $reasons;

#[Assert\Length(max: 1000, groups: ['Default', 'admin'])]
#[Assert\Length(max: 1000, groups: ['Default', 'admin', 'unregister'])]
#[Groups('unregister')]
private ?string $comment;

Expand Down
8 changes: 7 additions & 1 deletion src/Controller/Api/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ public function terminateMembershipAction(
],
]);

$violations = $validator->validate($unregistrationCommand, null, ['unregister']);
$validationGroups = [$user->isAdherent() ? 'unregister_adherent' : 'unregister_user'];

if ($user->getAuthAppVersion() >= 590) {
$validationGroups[] = 'unregister';
}

$violations = $validator->validate($unregistrationCommand, null, $validationGroups);

if (0 < $violations->count()) {
$errors = $serializer->serialize($violations, 'jsonproblem');
Expand Down

0 comments on commit 58ae769

Please sign in to comment.