Skip to content

Commit

Permalink
Merge pull request #1847 from cultuurnet/III-6370-expose-email-in-own…
Browse files Browse the repository at this point in the history
…ership

III-6370 Expose email in ownership
  • Loading branch information
LucWollants authored Oct 22, 2024
2 parents dc42296 + d73c0dc commit 21b60f2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/Ownership/OwnershipServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
);

Expand Down
2 changes: 2 additions & 0 deletions features/ownership/approve.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "approved"

Expand All @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "approved"

Expand Down
6 changes: 6 additions & 0 deletions features/ownership/delete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "deleted"

Expand All @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "deleted"

Expand All @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "deleted"

Expand All @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "deleted"

Expand All @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "deleted"

Expand All @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "deleted"

Expand Down
2 changes: 2 additions & 0 deletions features/ownership/reject.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "rejected"

Expand All @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "auth0|64089494e980aedd96740212"
And the JSON response at "state" should be "rejected"

Expand Down
1 change: 1 addition & 0 deletions features/ownership/request.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
And the JSON response at "requesterId" should be "7a583ed3-cbc1-481d-93b1-d80fff0174dd"
And the JSON response at "state" should be "requested"

Expand Down
12 changes: 10 additions & 2 deletions src/Ownership/Readmodels/OwnershipLDProjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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();

Expand Down
17 changes: 16 additions & 1 deletion tests/Ownership/Readmodels/OwnershipLDProjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
'[email protected]'
));

$this->ownershipLDProjector = new OwnershipLDProjector(
$this->ownershipRepository,
$userIdentityResolver
);
}

/**
Expand Down Expand Up @@ -200,6 +214,7 @@ private function createOwnershipJsonDocument(
$jsonLD->{'itemId'} = '9e68dafc-01d8-4c1c-9612-599c918b981d';
$jsonLD->{'itemType'} = 'organizer';
$jsonLD->{'ownerId'} = 'auth0|63e22626e39a8ca1264bd29b';
$jsonLD->{'ownerEmail'} = '[email protected]';
$jsonLD->{'requesterId'} = 'google-oauth2|102486314601596809843';
$jsonLD->{'state'} = $state->toString();
$jsonLD->{'created'} = $recordedOn->toString();
Expand Down

0 comments on commit 21b60f2

Please sign in to comment.