Commit 64aab217 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Fix introduced bug with group caching

parent 5de0d8b7
Pipeline #9063 passed with stages
in 2 minutes and 57 seconds
......@@ -122,11 +122,15 @@ class ApiAuthorizer implements Authorizer
*/
protected function getGroupsForUser(string $userId): array
{
if (!$this->userGroups) {
$this->userGroups = static::groupNames($this->groupUserRepository->getGroupsForUser($userId));
if ($userId === $this->currentUserId) {
if (!$this->userGroups) {
$this->userGroups = static::groupNames($this->groupUserRepository->getGroupsForUser($userId));
}
return $this->userGroups;
}
return $this->userGroups;
return static::groupNames($this->groupUserRepository->getGroupsForUser($userId));
}
/**
......
......@@ -56,11 +56,12 @@ class AuthorizerTest extends TestCase
/**
* @param array $perms
* @return \Source\Entities\User
* @throws \Source\Exceptions\EntityExistsException
* @throws \Source\Exceptions\EntityNotFoundException
*/
protected function createUserWithPerms(array $perms): User
{
$this->users->create($user = new User(
$user = $this->users->create(new User(
0,
'',
'',
......@@ -81,6 +82,7 @@ class AuthorizerTest extends TestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_always_allows_admin(): void
{
......@@ -93,6 +95,7 @@ class AuthorizerTest extends TestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_denies_unauthorized_peeps(): void
{
......@@ -105,6 +108,7 @@ class AuthorizerTest extends TestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_requires_one(): void
{
......@@ -116,6 +120,7 @@ class AuthorizerTest extends TestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_requires_all(): void
{
......@@ -127,6 +132,7 @@ class AuthorizerTest extends TestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_requires_all_when_they_have_partial(): void
{
......@@ -139,6 +145,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_when_all_is_required(): void
{
......@@ -152,6 +159,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_when_one_is_required(): void
{
......@@ -165,6 +173,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_does_not_throw_when_authorized():void
{
......@@ -179,6 +188,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_protects_with_protect(): void
{
......@@ -203,6 +213,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function protect_admin_rights_throws_an_exception_when_modifying_admin(): void
{
......@@ -216,6 +227,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function protect_admin_rights_non_admins_do_not_have_rights_to_admins(): void
{
......@@ -230,6 +242,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function protect_admin_rights_admins_can_modify_admins(): void
{
......@@ -243,6 +256,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function protect_admin_rights_non_admins_do_not_have_rights_to_admin_groups(): void
{
......@@ -257,6 +271,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function protect_admin_rights_admins_have_rights_for_admin_group(): void
{
......@@ -271,6 +286,7 @@ class AuthorizerTest extends TestCase
* @test
* @throws \Source\Exceptions\AuthorizationException
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function protect_admin_rights_throws_an_exception_when_a_group_cannot_be_found(): void
{
......@@ -298,6 +314,7 @@ class AuthorizerTest extends TestCase
/**
* @test
* @throws \Source\Exceptions\EntityNotFoundException
* @throws \Source\Exceptions\EntityExistsException
*/
public function it_gets_permissions(): void
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment