mirror of
https://github.com/flarum/framework.git
synced 2025-02-23 03:57:40 +08: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:
parent
0836d99e83
commit
b60617b849
@ -72,7 +72,6 @@ class ListUsersController extends AbstractListController
|
|||||||
{
|
{
|
||||||
$actor = $request->getAttribute('actor');
|
$actor = $request->getAttribute('actor');
|
||||||
|
|
||||||
$this->assertRegistered($actor);
|
|
||||||
$this->assertCan($actor, 'viewUserList');
|
$this->assertCan($actor, 'viewUserList');
|
||||||
|
|
||||||
$query = Arr::get($this->extractFilter($request), 'q');
|
$query = Arr::get($this->extractFilter($request), 'q');
|
||||||
|
@ -49,7 +49,6 @@ class CreateGroupHandler
|
|||||||
$actor = $command->actor;
|
$actor = $command->actor;
|
||||||
$data = $command->data;
|
$data = $command->data;
|
||||||
|
|
||||||
$this->assertRegistered($actor);
|
|
||||||
$this->assertCan($actor, 'createGroup');
|
$this->assertCan($actor, 'createGroup');
|
||||||
|
|
||||||
$group = Group::build(
|
$group = Group::build(
|
||||||
|
@ -55,15 +55,23 @@ trait AssertPermissionTrait
|
|||||||
* @param User $actor
|
* @param User $actor
|
||||||
* @param string $ability
|
* @param string $ability
|
||||||
* @param mixed $arguments
|
* @param mixed $arguments
|
||||||
|
* @throws NotAuthenticatedException
|
||||||
* @throws PermissionDeniedException
|
* @throws PermissionDeniedException
|
||||||
*/
|
*/
|
||||||
protected function assertCan(User $actor, $ability, $arguments = [])
|
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));
|
$this->assertPermission($actor->can($ability, $arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $actor
|
* @param User $actor
|
||||||
|
* @throws NotAuthenticatedException
|
||||||
* @throws PermissionDeniedException
|
* @throws PermissionDeniedException
|
||||||
*/
|
*/
|
||||||
protected function assertAdmin(User $actor)
|
protected function assertAdmin(User $actor)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user