diff --git a/src/Group/Command/CreateGroupHandler.php b/src/Group/Command/CreateGroupHandler.php index 0364432137d..8a000679e2e 100644 --- a/src/Group/Command/CreateGroupHandler.php +++ b/src/Group/Command/CreateGroupHandler.php @@ -49,6 +49,7 @@ public function handle(CreateGroup $command) $actor = $command->actor; $data = $command->data; + $this->assertRegistered($actor); $this->assertCan($actor, 'createGroup'); $group = Group::build( diff --git a/src/User/AssertPermissionTrait.php b/src/User/AssertPermissionTrait.php index 7646e8080a9..4845d85dd42 100644 --- a/src/User/AssertPermissionTrait.php +++ b/src/User/AssertPermissionTrait.php @@ -55,28 +55,17 @@ protected function assertRegistered(User $actor) * @param User $actor * @param string $ability * @param mixed $arguments - * @throws NotAuthenticatedException * @throws PermissionDeniedException */ protected function assertCan(User $actor, $ability, $arguments = []) { - // Identify whether guest or user has the permission. - $can = $actor->can($ability, $arguments); - - // For non-authenticated users, we throw a different exception to signal - // that logging in may help. - if (! $can) { - $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($can); + $this->assertPermission( + $actor->can($ability, $arguments) + ); } /** * @param User $actor - * @throws NotAuthenticatedException * @throws PermissionDeniedException */ protected function assertAdmin(User $actor) diff --git a/src/User/Command/RegisterUserHandler.php b/src/User/Command/RegisterUserHandler.php index f2d1818f899..e839e1c2bdd 100644 --- a/src/User/Command/RegisterUserHandler.php +++ b/src/User/Command/RegisterUserHandler.php @@ -74,7 +74,7 @@ public function handle(RegisterUser $command) $data = $command->data; if (! $this->settings->get('allow_sign_up')) { - $this->assertPermission($actor->can('administrate')); + $this->assertAdmin($actor); } $password = Arr::get($data, 'attributes.password'); diff --git a/tests/integration/api/users/ListTest.php b/tests/integration/api/users/ListTest.php index bbae90ecfb7..f1c8660b45b 100644 --- a/tests/integration/api/users/ListTest.php +++ b/tests/integration/api/users/ListTest.php @@ -50,7 +50,7 @@ public function disallows_index_for_guest() $this->request('GET', '/api/users') ); - $this->assertEquals(401, $response->getStatusCode()); + $this->assertEquals(403, $response->getStatusCode()); } /**