mirror of
https://github.com/flarum/core.git
synced 2025-10-28 22:07:33 +01:00
Move authentication check into assertCan() method
This will cause the right error (HTTP 401) to be thrown whenever we're checking for a specific permission, but the user is not even logged in. Authenticated users will still get HTTP 403.
This commit is contained in:
@@ -55,15 +55,23 @@ trait AssertPermissionTrait
|
||||
* @param User $actor
|
||||
* @param string $ability
|
||||
* @param mixed $arguments
|
||||
* @throws NotAuthenticatedException
|
||||
* @throws PermissionDeniedException
|
||||
*/
|
||||
protected function assertCan(User $actor, $ability, $arguments = [])
|
||||
{
|
||||
// For non-authenticated users, we throw a different exception to signal
|
||||
// that logging in may help.
|
||||
$this->assertRegistered($actor);
|
||||
|
||||
// If we're logged in, then we need to communicate that the current
|
||||
// account simply does not have enough permissions.
|
||||
$this->assertPermission($actor->can($ability, $arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $actor
|
||||
* @throws NotAuthenticatedException
|
||||
* @throws PermissionDeniedException
|
||||
*/
|
||||
protected function assertAdmin(User $actor)
|
||||
|
||||
Reference in New Issue
Block a user