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:
Franz Liedke 2019-08-21 23:46:00 +02:00 committed by Daniël Klabbers
parent 6797770c75
commit 22b32bd601
3 changed files with 8 additions and 2 deletions

View File

@ -70,7 +70,6 @@ class ListUsersController extends AbstractListController
{
$actor = $request->getAttribute('actor');
$this->assertRegistered($actor);
$this->assertCan($actor, 'viewUserList');
$query = Arr::get($this->extractFilter($request), 'q');

View File

@ -47,7 +47,6 @@ class CreateGroupHandler
$actor = $command->actor;
$data = $command->data;
$this->assertRegistered($actor);
$this->assertCan($actor, 'createGroup');
$group = Group::build(

View File

@ -53,15 +53,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)