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`.
This commit is contained in:
2025-04-17 15:47:38 +02:00
parent a14ed78e25
commit fc8e3789e0
3 changed files with 36 additions and 4 deletions

View File

@@ -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);
}
}