Skip to content
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

Admin : nouveau paramètre qui permet d'empêcher les membres de (in)valider leur propre créneau #801

Merged
merged 4 commits into from
Apr 5, 2023

Conversation

raphodn
Copy link
Member

@raphodn raphodn commented Apr 4, 2023

Suite de #796

Quoi ?

  • nouveau paramètre forbid_own_shift_validate_admin
  • si vrai, alors les membres qui ont accès à l'interface admin (mais qui ne sont pas ROLE_ADMIN) ne pourront pas (in)valider leur propre créneaux

Modifications annexes :

  • j'en ai profité pour renommer la route shift_validate en shift_validate_admin (vu que ce n'est seulement possible via l'admin)
  • et j'ai rajouté une securité sur la route

Pourquoi ?

Pour restreindre le nombre de membres qui peuvent s'auto-valider leur créneaux

@raphodn raphodn requested a review from petitalb April 4, 2023 10:42
@raphodn raphodn self-assigned this Apr 4, 2023
@raphodn raphodn force-pushed the raphodn/shift-validate-disable-self branch from a7bdb82 to 598bca4 Compare April 4, 2023 10:43
Base automatically changed from raphodn/shift-free-disable-self to master April 4, 2023 13:51
@raphodn raphodn force-pushed the raphodn/shift-validate-disable-self branch from d02a6fd to 53e45fb Compare April 4, 2023 13:54
$validate = $form->get('validate')->getData() == 1;
$current = $shift->getWasCarriedOut() == 1;
if ($validate == $current) {
$shifter_is_current_user = $current_app_user->getBeneficiary() == $shift->getShifter();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention un user n'a pas toujours de beneficiary (ex les salariés). Je ne sais pas si ce cas est problématique.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T'as raison, je vais tester

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok testé : $current_app_user->getBeneficiary() = null si le user n'a pas de beneficiary, donc ca passe

if ($validate == $current) {
$shifter_is_current_user = $current_app_user->getBeneficiary() == $shift->getShifter();
// check if user is allowed to (in)validate shift
if ($shifter_is_current_user && $this->forbid_own_shift_validate_admin && !$this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Au debut de la methode tu as un voters :

$this->denyAccessUnlessGranted(ShiftVoter::VALIDATE, $shift);

Ca serait plus logique de mettre cette condition dans le voter

Copy link
Member Author

@raphodn raphodn Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah oui c'est vrai que je n'avais pas considéré le voter pour shift_free, mais ici ca peut être possible à faire..

Copy link
Member Author

@raphodn raphodn Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en fait j'ai un peu regardé, en passant par ShiftVoter on n'a pas la possibilité de mettre des message d'erreurs custom, si ?

là c'est une règle métier à un niveau supérieur que savoir si t'as l'authorisation d'accéder à cet endpoint, donc je vais laisser comme ça (mais si on trouve un moyen d'avoir des messages d'erreurs custom, on pourra les basculer dans ShiftVoter en effet)

@raphodn raphodn merged commit dcd50fe into master Apr 5, 2023
@raphodn raphodn deleted the raphodn/shift-validate-disable-self branch April 5, 2023 08:18
@raphodn raphodn linked an issue Apr 5, 2023 that may be closed by this pull request
6 tasks
OursDesCavernes pushed a commit to Les400Coop/gestion-compte that referenced this pull request Jan 20, 2024
…lider leur propre créneau (elefan-grenoble#801)

* If forbid_own_shift_validate_admin, then non-admin cannot (in)validate their own shift via admin

* Add security on shift_validate route

* Additional fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Admin : restreindre les actions possibles sur son propre compte
2 participants