From fc8e3789e06ba8f739b9276ef7db4b10f06d93d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 17 Apr 2025 15:47:38 +0200 Subject: [PATCH] Refactor SavedExportVoter to improve export permission check Revised the permission logic in `canUserGenerate` to enhance clarity and maintainability. Replaced nested condition with early return and updated the export permission check to use `isGrantedForElement`. --- .../Security/Authorization/SavedExportVoter.php | 9 +++++++-- .../Tests/Entity/Workflow/SavedExportTest.php | 15 ++++++++++++++- .../Authorization/SavedExportVoterTest.php | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php index 43e788c90..8c4db8a60 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/SavedExportVoter.php @@ -60,7 +60,12 @@ class SavedExportVoter extends Voter private function canUserGenerate(User $user, SavedExport $savedExport): bool { - return ($savedExport->getUser() === $user || $savedExport->isSharedWithUser($user)) - && $this->security->isGranted(ChillExportVoter::EXPORT, $this->exportManager->getExport($savedExport->getExportAlias())); + if (!($savedExport->getUser() === $user || $savedExport->isSharedWithUser($user))) { + return false; + } + + $export = $this->exportManager->getExport($savedExport->getExportAlias()); + + return $this->exportManager->isGrantedForElement($export); } } diff --git a/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/SavedExportTest.php b/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/SavedExportTest.php index 999d127ed..cd98df66f 100644 --- a/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/SavedExportTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Entity/Workflow/SavedExportTest.php @@ -1,13 +1,26 @@ prophesize(Security::class); if (null !== $isGranted) {