From c7b359e549db00e5b355f8fd87224e0b5ccf4ddb Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Mon, 21 Oct 2024 09:44:21 +0200 Subject: [PATCH 1/4] Add ownerEmail to JSON projection --- src/Ownership/Readmodels/OwnershipLDProjector.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Ownership/Readmodels/OwnershipLDProjector.php b/src/Ownership/Readmodels/OwnershipLDProjector.php index 11d5a87ad..122fcb8e0 100644 --- a/src/Ownership/Readmodels/OwnershipLDProjector.php +++ b/src/Ownership/Readmodels/OwnershipLDProjector.php @@ -17,6 +17,7 @@ use CultuurNet\UDB3\ReadModel\DocumentRepository; use CultuurNet\UDB3\ReadModel\JsonDocument; use CultuurNet\UDB3\RecordedOn; +use CultuurNet\UDB3\User\UserIdentityResolver; final class OwnershipLDProjector implements EventListener { @@ -25,10 +26,14 @@ final class OwnershipLDProjector implements EventListener } private DocumentRepository $repository; + private UserIdentityResolver $userIdentityResolver; - public function __construct(DocumentRepository $repository) - { + public function __construct( + DocumentRepository $repository, + UserIdentityResolver $userIdentityResolver + ) { $this->repository = $repository; + $this->userIdentityResolver = $userIdentityResolver; } public function handle(DomainMessage $domainMessage): void @@ -50,6 +55,8 @@ public function handle(DomainMessage $domainMessage): void public function applyOwnershipRequested(OwnershipRequested $ownershipRequested, DomainMessage $domainMessage): JsonDocument { + $ownerDetails = $this->userIdentityResolver->getUserById($ownershipRequested->getOwnerId()); + $jsonDocument = new JsonDocument($ownershipRequested->getId()); $body = $jsonDocument->getBody(); @@ -58,6 +65,7 @@ public function applyOwnershipRequested(OwnershipRequested $ownershipRequested, $body->itemId = $ownershipRequested->getItemId(); $body->itemType = $ownershipRequested->getItemType(); $body->ownerId = $ownershipRequested->getOwnerId(); + $body->ownerEmail = $ownerDetails !== null ? $ownerDetails->getEmailAddress() : null; $body->requesterId = $ownershipRequested->getRequesterId(); $body->state = OwnershipState::requested()->toString(); From 266f6dddb913b58f05c83f9d32256a9462110f5b Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Mon, 21 Oct 2024 09:44:32 +0200 Subject: [PATCH 2/4] Bootstrapping --- app/Ownership/OwnershipServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Ownership/OwnershipServiceProvider.php b/app/Ownership/OwnershipServiceProvider.php index bc35f38e4..8567e8ff4 100644 --- a/app/Ownership/OwnershipServiceProvider.php +++ b/app/Ownership/OwnershipServiceProvider.php @@ -13,6 +13,7 @@ use CultuurNet\UDB3\Ownership\Readmodels\OwnershipSearchProjector; use CultuurNet\UDB3\Ownership\Repositories\Search\DBALOwnershipSearchRepository; use CultuurNet\UDB3\Ownership\Repositories\Search\OwnershipSearchRepository; +use CultuurNet\UDB3\User\UserIdentityResolver; use Ramsey\Uuid\UuidFactory; final class OwnershipServiceProvider extends AbstractServiceProvider @@ -56,7 +57,8 @@ public function register(): void $container->addShared( OwnershipLDProjector::class, fn () => new OwnershipLDProjector( - $container->get(OwnershipServiceProvider::OWNERSHIP_JSONLD_REPOSITORY) + $container->get(OwnershipServiceProvider::OWNERSHIP_JSONLD_REPOSITORY), + $container->get(UserIdentityResolver::class) ) ); From 5b09bb6abb01781f7f5663c9aef3beec8352eb0a Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Mon, 21 Oct 2024 09:44:39 +0200 Subject: [PATCH 3/4] Update unit tests --- .../Readmodels/OwnershipLDProjectorTest.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/Ownership/Readmodels/OwnershipLDProjectorTest.php b/tests/Ownership/Readmodels/OwnershipLDProjectorTest.php index 4a76a65f3..1c0662219 100644 --- a/tests/Ownership/Readmodels/OwnershipLDProjectorTest.php +++ b/tests/Ownership/Readmodels/OwnershipLDProjectorTest.php @@ -15,6 +15,8 @@ use CultuurNet\UDB3\ReadModel\InMemoryDocumentRepository; use CultuurNet\UDB3\ReadModel\JsonDocument; use CultuurNet\UDB3\RecordedOn; +use CultuurNet\UDB3\User\UserIdentityDetails; +use CultuurNet\UDB3\User\UserIdentityResolver; use PHPUnit\Framework\TestCase; class OwnershipLDProjectorTest extends TestCase @@ -29,7 +31,19 @@ protected function setUp(): void $this->ownershipRepository = new InMemoryDocumentRepository(); - $this->ownershipLDProjector = new OwnershipLDProjector($this->ownershipRepository); + $userIdentityResolver = $this->createMock(UserIdentityResolver::class); + $userIdentityResolver->expects($this->any()) + ->method('getUserById') + ->willReturn(new UserIdentityDetails( + 'auth0|63e22626e39a8ca1264bd29b', + 'dev+e2e', + 'dev+e2e@publiq.be' + )); + + $this->ownershipLDProjector = new OwnershipLDProjector( + $this->ownershipRepository, + $userIdentityResolver + ); } /** @@ -200,6 +214,7 @@ private function createOwnershipJsonDocument( $jsonLD->{'itemId'} = '9e68dafc-01d8-4c1c-9612-599c918b981d'; $jsonLD->{'itemType'} = 'organizer'; $jsonLD->{'ownerId'} = 'auth0|63e22626e39a8ca1264bd29b'; + $jsonLD->{'ownerEmail'} = 'dev+e2e@publiq.be'; $jsonLD->{'requesterId'} = 'google-oauth2|102486314601596809843'; $jsonLD->{'state'} = $state->toString(); $jsonLD->{'created'} = $recordedOn->toString(); From 58a5520e1b9b54792eb79926d14b5f62bbd6c8b6 Mon Sep 17 00:00:00 2001 From: Luc Wollants Date: Mon, 21 Oct 2024 09:45:28 +0200 Subject: [PATCH 4/4] Update acceptance tests --- features/ownership/approve.feature | 2 ++ features/ownership/delete.feature | 6 ++++++ features/ownership/reject.feature | 2 ++ features/ownership/request.feature | 1 + 4 files changed, 11 insertions(+) diff --git a/features/ownership/approve.feature b/features/ownership/approve.feature index 9b378efd4..a75bf9d1c 100644 --- a/features/ownership/approve.feature +++ b/features/ownership/approve.feature @@ -16,6 +16,7 @@ Feature: Test approving ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "approved" @@ -29,6 +30,7 @@ Feature: Test approving ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "approved" diff --git a/features/ownership/delete.feature b/features/ownership/delete.feature index adb2fd6e4..a4db65422 100644 --- a/features/ownership/delete.feature +++ b/features/ownership/delete.feature @@ -16,6 +16,7 @@ Feature: Test deleting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "deleted" @@ -31,6 +32,7 @@ Feature: Test deleting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "deleted" @@ -46,6 +48,7 @@ Feature: Test deleting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "deleted" @@ -59,6 +62,7 @@ Feature: Test deleting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "deleted" @@ -73,6 +77,7 @@ Feature: Test deleting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "deleted" @@ -87,6 +92,7 @@ Feature: Test deleting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "deleted" diff --git a/features/ownership/reject.feature b/features/ownership/reject.feature index 3704dba26..642714df7 100644 --- a/features/ownership/reject.feature +++ b/features/ownership/reject.feature @@ -16,6 +16,7 @@ Feature: Test rejecting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "rejected" @@ -29,6 +30,7 @@ Feature: Test rejecting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212" And the JSON response at "state" should be "rejected" diff --git a/features/ownership/request.feature b/features/ownership/request.feature index 855d946c3..9a9737242 100644 --- a/features/ownership/request.feature +++ b/features/ownership/request.feature @@ -13,6 +13,7 @@ Feature: Test requesting ownership And the JSON response at "itemId" should be "%{organizerId}" And the JSON response at "itemType" should be "organizer" And the JSON response at "ownerId" should be "auth0|64089494e980aedd96740212" + And the JSON response at "ownerEmail" should be "dev+e2etest@publiq.be" And the JSON response at "requesterId" should be "7a583ed3-cbc1-481d-93b1-d80fff0174dd" And the JSON response at "state" should be "requested"