-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Domain\User\Specification; | ||
|
||
use App\Domain\User\Enum\OrganizationRolesEnum; | ||
use App\Domain\User\Organization; | ||
use App\Infrastructure\Security\SymfonyUser; | ||
|
||
class CanUserEditOrganization | ||
{ | ||
public function isSatisfiedBy(Organization $organization, SymfonyUser $user): bool | ||
{ | ||
foreach ($user->getOrganizationUsers() as $organizationUser) { | ||
if ($organizationUser->uuid !== $organization->getUuid()) { | ||
continue; | ||
} | ||
|
||
return \in_array(OrganizationRolesEnum::ROLE_ORGA_ADMIN->value, $organizationUser->roles); | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Domain\User\Specification; | ||
|
||
use App\Domain\User\Organization; | ||
use App\Infrastructure\Security\SymfonyUser; | ||
|
||
class CanUserViewOrganization | ||
{ | ||
public function isSatisfiedBy(Organization $organization, SymfonyUser $user): bool | ||
{ | ||
return \in_array($organization->getUuid(), $user->getOrganizationUuids()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
tests/Unit/Domain/User/Specification/CanUserEditOrganizationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Unit\Domain\User\Specification; | ||
|
||
use App\Application\User\View\OrganizationView; | ||
use App\Domain\User\Enum\OrganizationRolesEnum; | ||
use App\Domain\User\Organization; | ||
use App\Domain\User\Specification\CanUserEditOrganization; | ||
use App\Infrastructure\Security\SymfonyUser; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class CanUserEditOrganizationTest extends TestCase | ||
{ | ||
public function testCanEdit(): void | ||
{ | ||
$organization = $this->createMock(Organization::class); | ||
$organization | ||
->expects(self::once()) | ||
->method('getUuid') | ||
->willReturn('c1790745-b915-4fb5-96e7-79b104092a55'); | ||
|
||
$symfonyUser = $this->createMock(SymfonyUser::class); | ||
$symfonyUser | ||
->expects(self::once()) | ||
->method('getOrganizationUsers') | ||
->willReturn([ | ||
new OrganizationView('c1790745-b915-4fb5-96e7-79b104092a55', 'Dialog', [OrganizationRolesEnum::ROLE_ORGA_ADMIN->value]), | ||
]); | ||
|
||
$pattern = new CanUserEditOrganization(); | ||
$this->assertTrue($pattern->isSatisfiedBy($organization, $symfonyUser)); | ||
} | ||
|
||
public function testCannotEdit(): void | ||
{ | ||
$organization = $this->createMock(Organization::class); | ||
$organization | ||
->expects(self::once()) | ||
->method('getUuid') | ||
->willReturn('c1790745-b915-4fb5-96e7-79b104092a55'); | ||
|
||
$symfonyUser = $this->createMock(SymfonyUser::class); | ||
$symfonyUser | ||
->expects(self::once()) | ||
->method('getOrganizationUsers') | ||
->willReturn([ | ||
new OrganizationView('c1790745-b915-4fb5-96e7-79b104092a55', 'Dialog', [OrganizationRolesEnum::ROLE_ORGA_CONTRIBUTOR->value]), | ||
]); | ||
|
||
$pattern = new CanUserEditOrganization(); | ||
$this->assertFalse($pattern->isSatisfiedBy($organization, $symfonyUser)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/Unit/Domain/User/Specification/CanUserViewOrganizationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Unit\Domain\User\Specification; | ||
|
||
use App\Domain\User\Organization; | ||
use App\Domain\User\Specification\CanUserViewOrganization; | ||
use App\Infrastructure\Security\SymfonyUser; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class CanUserViewOrganizationTest extends TestCase | ||
{ | ||
public function testCanView(): void | ||
{ | ||
$organization = $this->createMock(Organization::class); | ||
$organization | ||
->expects(self::once()) | ||
->method('getUuid') | ||
->willReturn('c1790745-b915-4fb5-96e7-79b104092a55'); | ||
|
||
$symfonyUser = $this->createMock(SymfonyUser::class); | ||
$symfonyUser | ||
->expects(self::once()) | ||
->method('getOrganizationUuids') | ||
->willReturn(['c1790745-b915-4fb5-96e7-79b104092a55']); | ||
|
||
$pattern = new CanUserViewOrganization(); | ||
$this->assertTrue($pattern->isSatisfiedBy($organization, $symfonyUser)); | ||
} | ||
|
||
public function testCannotView(): void | ||
{ | ||
$organization = $this->createMock(Organization::class); | ||
$organization | ||
->expects(self::once()) | ||
->method('getUuid') | ||
->willReturn('28aaef2a-e9d1-4189-9ead-17e866a8726f'); | ||
|
||
$symfonyUser = $this->createMock(SymfonyUser::class); | ||
$symfonyUser | ||
->expects(self::once()) | ||
->method('getOrganizationUuids') | ||
->willReturn(['c1790745-b915-4fb5-96e7-79b104092a55']); | ||
|
||
$pattern = new CanUserViewOrganization(); | ||
$this->assertFalse($pattern->isSatisfiedBy($organization, $symfonyUser)); | ||
} | ||
} |