diff --git a/framework/core/src/Group/Command/CreateGroupHandler.php b/framework/core/src/Group/Command/CreateGroupHandler.php index 036443213..8a000679e 100644 --- a/framework/core/src/Group/Command/CreateGroupHandler.php +++ b/framework/core/src/Group/Command/CreateGroupHandler.php @@ -49,6 +49,7 @@ class CreateGroupHandler $actor = $command->actor; $data = $command->data; + $this->assertRegistered($actor); $this->assertCan($actor, 'createGroup'); $group = Group::build( diff --git a/framework/core/src/User/AssertPermissionTrait.php b/framework/core/src/User/AssertPermissionTrait.php index 7646e8080..4845d85dd 100644 --- a/framework/core/src/User/AssertPermissionTrait.php +++ b/framework/core/src/User/AssertPermissionTrait.php @@ -55,28 +55,17 @@ trait AssertPermissionTrait * @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/framework/core/src/User/Command/RegisterUserHandler.php b/framework/core/src/User/Command/RegisterUserHandler.php index f2d1818f8..e839e1c2b 100644 --- a/framework/core/src/User/Command/RegisterUserHandler.php +++ b/framework/core/src/User/Command/RegisterUserHandler.php @@ -74,7 +74,7 @@ class RegisterUserHandler $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/framework/core/tests/integration/api/users/ListTest.php b/framework/core/tests/integration/api/users/ListTest.php index bbae90ecf..f1c8660b4 100644 --- a/framework/core/tests/integration/api/users/ListTest.php +++ b/framework/core/tests/integration/api/users/ListTest.php @@ -50,7 +50,7 @@ class ListTest extends TestCase $this->request('GET', '/api/users') ); - $this->assertEquals(401, $response->getStatusCode()); + $this->assertEquals(403, $response->getStatusCode()); } /**