-
-
Notifications
You must be signed in to change notification settings - Fork 4k
[5.x] Feature: Strict authorization in CanAuthorizeAccess #18879
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,9 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| namespace Filament\Pages\Concerns; | ||||||||||||||||||
|
|
||||||||||||||||||
| use Filament\Facades\Filament; | ||||||||||||||||||
| use LogicException; | ||||||||||||||||||
|
|
||||||||||||||||||
| trait CanAuthorizeAccess | ||||||||||||||||||
| { | ||||||||||||||||||
| public function mountCanAuthorizeAccess(): void | ||||||||||||||||||
|
|
@@ -11,6 +14,8 @@ public function mountCanAuthorizeAccess(): void | |||||||||||||||||
|
|
||||||||||||||||||
| public static function canAccess(): bool | ||||||||||||||||||
| { | ||||||||||||||||||
| return true; | ||||||||||||||||||
| return Filament::isAuthorizationStrict() | ||||||||||||||||||
| ? throw new LogicException(sprintf('Strict authorization mode is enabled, but [canAccess()] method in [%s] class is not defined.', static::class)) | ||||||||||||||||||
| : true; | ||||||||||||||||||
|
Comment on lines
+17
to
+19
|
||||||||||||||||||
| return Filament::isAuthorizationStrict() | |
| ? throw new LogicException(sprintf('Strict authorization mode is enabled, but [canAccess()] method in [%s] class is not defined.', static::class)) | |
| : true; | |
| if (Filament::isAuthorizationStrict()) { | |
| throw new LogicException(sprintf('Strict authorization mode is enabled, but [canAccess()] method in [%s] class is not defined.', static::class)); | |
| } | |
| return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message states that "canAccess() method... is not defined" which is technically incorrect - the method IS defined in the CanAuthorizeAccess trait. Consider rewording to be more accurate, such as "Strict authorization mode is enabled, but the default canAccess() implementation is being used in class [%s]. Please override canAccess() to define custom authorization logic." This would better communicate to developers what action they need to take.