From 6be681433138b911c1acf09d080e439a1d5bbfe6 Mon Sep 17 00:00:00 2001 From: Timo Notheisen <65653426+tnotheis@users.noreply.github.com> Date: Wed, 22 May 2024 17:10:06 +0200 Subject: [PATCH] Consumer API: RelationshipReactivationCompleted external event is sent to wrong relationship participant (#665) * fix: always send external event to peer * ci: add missing dependencies to publish helm chart job * refactor: extract GetPeer method on Relationship --- .github/workflows/publish.yml | 2 ++ .../Commands/AcceptRelationshipReactivation/Handler.cs | 3 ++- .../Commands/RejectRelationshipReactivation/Handler.cs | 6 +++--- .../Handler.cs | 7 +++---- .../RequestRelationshipReactivationCommand.cs | 5 ++--- .../RequestRelationshipReactivationResponse.cs | 2 +- .../Commands/RevokeRelationshipReactivation/Handler.cs | 5 ++--- .../Controllers/RelationshipsController.cs | 2 +- .../Aggregates/Relationships/Relationship.cs | 5 +++++ .../Outgoing/RelationshipStatusChangedDomainEvent.cs | 5 +++-- .../AcceptRelationshipReactivation/HandlerTests.cs | 3 ++- .../RejectRelationshipReactivation/HandlerTests.cs | 3 ++- .../RelationshipReactivationRequest/HandlerTests.cs | 3 ++- 13 files changed, 30 insertions(+), 21 deletions(-) rename Modules/Relationships/src/Relationships.Application/Relationships/Commands/{RelationshipReactivationRequest => RequestRelationshipReactivation}/Handler.cs (90%) rename Modules/Relationships/src/Relationships.Application/Relationships/Commands/{RelationshipReactivationRequest => RequestRelationshipReactivation}/RequestRelationshipReactivationCommand.cs (66%) rename Modules/Relationships/src/Relationships.Application/Relationships/Commands/{RelationshipReactivationRequest => RequestRelationshipReactivation}/RequestRelationshipReactivationResponse.cs (89%) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a558b4365b..97d5e735e8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -203,6 +203,8 @@ jobs: - publish-admin-ui - publish-consumer-api - publish-event-handler + - publish-database-migrator + - publish-identity-deletion-jobs steps: - name: Checkout uses: actions/checkout@v4 diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationshipReactivation/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationshipReactivation/Handler.cs index 89f2c15210..824a71df45 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationshipReactivation/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationshipReactivation/Handler.cs @@ -7,6 +7,7 @@ using MediatR; namespace Backbone.Modules.Relationships.Application.Relationships.Commands.AcceptRelationshipReactivation; + public class Handler : IRequestHandler { private readonly IRelationshipsRepository _relationshipsRepository; @@ -31,7 +32,7 @@ public async Task Handle(AcceptRelations await _relationshipsRepository.Update(relationship); - _eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, _activeIdentity)); + _eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, relationship.GetPeer(_activeIdentity))); return new AcceptRelationshipReactivationResponse(relationship); } diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationshipReactivation/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationshipReactivation/Handler.cs index 4999c8e8ef..b83dd4bd82 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationshipReactivation/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationshipReactivation/Handler.cs @@ -1,5 +1,4 @@ -using Backbone.BuildingBlocks.Application.Abstractions.Exceptions; -using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; +using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext; using Backbone.DevelopmentKit.Identity.ValueObjects; using Backbone.Modules.Relationships.Application.Infrastructure.Persistence.Repository; @@ -8,6 +7,7 @@ using MediatR; namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RejectRelationshipReactivation; + public class Handler : IRequestHandler { private readonly IRelationshipsRepository _relationshipsRepository; @@ -33,7 +33,7 @@ public async Task Handle(RejectRelations await _relationshipsRepository.Update(relationship); - _eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, _activeIdentity)); + _eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, relationship.GetPeer(_activeIdentity))); return new RejectRelationshipReactivationResponse(relationship); } diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/Handler.cs similarity index 90% rename from Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/Handler.cs rename to Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/Handler.cs index 96c5a40307..794d5306b6 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/Handler.cs @@ -6,7 +6,7 @@ using Backbone.Modules.Relationships.Domain.DomainEvents.Outgoing; using MediatR; -namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RelationshipReactivationRequest; +namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RequestRelationshipReactivation; public class Handler : IRequestHandler { @@ -22,6 +22,7 @@ public Handler(IRelationshipsRepository relationshipsRepository, IUserContext us _activeIdentity = userContext.GetAddress(); _activeDevice = userContext.GetDeviceId(); } + public async Task Handle(RequestRelationshipReactivationCommand request, CancellationToken cancellationToken) { var relationshipId = RelationshipId.Parse(request.RelationshipId); @@ -31,9 +32,7 @@ public async Task Handle(RequestRelatio await _relationshipsRepository.Update(relationship); - var peer = relationship.To == _activeIdentity ? relationship.From : relationship.To; - - _eventBus.Publish(new RelationshipReactivationRequestedDomainEvent(relationship, _activeIdentity, peer)); + _eventBus.Publish(new RelationshipReactivationRequestedDomainEvent(relationship, _activeIdentity, relationship.GetPeer(_activeIdentity))); return new RequestRelationshipReactivationResponse(relationship); } diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/RequestRelationshipReactivationCommand.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/RequestRelationshipReactivationCommand.cs similarity index 66% rename from Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/RequestRelationshipReactivationCommand.cs rename to Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/RequestRelationshipReactivationCommand.cs index 8c5ca12646..35b159e3b6 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/RequestRelationshipReactivationCommand.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/RequestRelationshipReactivationCommand.cs @@ -1,7 +1,6 @@ -using Backbone.BuildingBlocks.Application.Attributes; -using MediatR; +using MediatR; -namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RelationshipReactivationRequest; +namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RequestRelationshipReactivation; public class RequestRelationshipReactivationCommand : IRequest { diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/RequestRelationshipReactivationResponse.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/RequestRelationshipReactivationResponse.cs similarity index 89% rename from Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/RequestRelationshipReactivationResponse.cs rename to Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/RequestRelationshipReactivationResponse.cs index faabab8b83..c974bb541c 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RelationshipReactivationRequest/RequestRelationshipReactivationResponse.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RequestRelationshipReactivation/RequestRelationshipReactivationResponse.cs @@ -1,7 +1,7 @@ using Backbone.Modules.Relationships.Application.Relationships.DTOs; using Backbone.Modules.Relationships.Domain.Aggregates.Relationships; -namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RelationshipReactivationRequest; +namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RequestRelationshipReactivation; public class RequestRelationshipReactivationResponse : RelationshipMetadataDTO { diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationshipReactivation/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationshipReactivation/Handler.cs index a8a32f0ecd..1f01551069 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationshipReactivation/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationshipReactivation/Handler.cs @@ -7,6 +7,7 @@ using MediatR; namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RevokeRelationshipReactivation; + public class Handler : IRequestHandler { private readonly IRelationshipsRepository _relationshipsRepository; @@ -31,9 +32,7 @@ public async Task Handle(RevokeRelations await _relationshipsRepository.Update(relationship); - var peer = relationship.To == _activeIdentity ? relationship.From : relationship.To; - - _eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, peer)); + _eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, relationship.GetPeer(_activeIdentity))); return new RevokeRelationshipReactivationResponse(relationship); } diff --git a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs index 39865b343b..2eaeeeb19c 100644 --- a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs +++ b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs @@ -10,7 +10,7 @@ using Backbone.Modules.Relationships.Application.Relationships.Commands.DecomposeRelationship; using Backbone.Modules.Relationships.Application.Relationships.Commands.RejectRelationship; using Backbone.Modules.Relationships.Application.Relationships.Commands.RejectRelationshipReactivation; -using Backbone.Modules.Relationships.Application.Relationships.Commands.RelationshipReactivationRequest; +using Backbone.Modules.Relationships.Application.Relationships.Commands.RequestRelationshipReactivation; using Backbone.Modules.Relationships.Application.Relationships.Commands.RevokeRelationship; using Backbone.Modules.Relationships.Application.Relationships.Commands.RevokeRelationshipReactivation; using Backbone.Modules.Relationships.Application.Relationships.Commands.TerminateRelationship; diff --git a/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs b/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs index 7a889ae47a..a3d14b82f4 100644 --- a/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs +++ b/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs @@ -62,6 +62,11 @@ public Relationship(RelationshipTemplate relationshipTemplate, IdentityAddress a public bool FromHasDecomposed { get; private set; } public bool ToHasDecomposed { get; private set; } + public IdentityAddress GetPeer(IdentityAddress activeIdentity) + { + return From == activeIdentity ? To : From; + } + private static void EnsureTargetIsNotSelf(RelationshipTemplate relationshipTemplate, IdentityAddress activeIdentity) { if (activeIdentity == relationshipTemplate.CreatedBy) diff --git a/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs b/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs index 06c7943f68..f6eb31a812 100644 --- a/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs +++ b/Modules/Relationships/src/Relationships.Domain/DomainEvents/Outgoing/RelationshipStatusChangedDomainEvent.cs @@ -6,12 +6,13 @@ namespace Backbone.Modules.Relationships.Domain.DomainEvents.Outgoing; public class RelationshipStatusChangedDomainEvent : DomainEvent { - public RelationshipStatusChangedDomainEvent(Relationship relationship) : base($"{relationship.Id}/StatusChanged/{relationship.AuditLog.OrderBy(a => a.CreatedAt).Last().CreatedAt.ToUniversalString()}") + public RelationshipStatusChangedDomainEvent(Relationship relationship) : base( + $"{relationship.Id}/StatusChanged/{relationship.AuditLog.OrderBy(a => a.CreatedAt).Last().CreatedAt.ToUniversalString()}") { RelationshipId = relationship.Id; Status = relationship.Status.ToString(); Initiator = relationship.LastModifiedBy; - Peer = relationship.LastModifiedBy == relationship.From ? relationship.To : relationship.From; + Peer = relationship.GetPeer(relationship.LastModifiedBy); } public string RelationshipId { get; set; } diff --git a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/AcceptRelationshipReactivation/HandlerTests.cs b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/AcceptRelationshipReactivation/HandlerTests.cs index af4895f119..de7681ddaa 100644 --- a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/AcceptRelationshipReactivation/HandlerTests.cs +++ b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/AcceptRelationshipReactivation/HandlerTests.cs @@ -11,6 +11,7 @@ using Xunit; namespace Backbone.Modules.Relationships.Application.Tests.Tests.Relationships.Commands.AcceptRelationshipReactivation; + public class HandlerTests { [Fact] @@ -108,7 +109,7 @@ await handler.Handle(new AcceptRelationshipReactivationCommand A.CallTo( () => mockEventBus.Publish(A.That.Matches(e => e.RelationshipId == relationship.Id && - e.Peer == activeIdentity) + e.Peer == identityTo) )) .MustHaveHappenedOnceExactly(); } diff --git a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RejectRelationshipReactivation/HandlerTests.cs b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RejectRelationshipReactivation/HandlerTests.cs index 5ca82397ff..629cbae927 100644 --- a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RejectRelationshipReactivation/HandlerTests.cs +++ b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RejectRelationshipReactivation/HandlerTests.cs @@ -11,6 +11,7 @@ using Xunit; namespace Backbone.Modules.Relationships.Application.Tests.Tests.Relationships.Commands.RejectRelationshipReactivation; + public class HandlerTests { [Fact] @@ -76,7 +77,7 @@ await handler.Handle(new RejectRelationshipReactivationCommand A.CallTo( () => mockEventBus.Publish(A.That.Matches(e => e.RelationshipId == relationship.Id && - e.Peer == activeIdentity) + e.Peer == identityTo) )) .MustHaveHappenedOnceExactly(); } diff --git a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RelationshipReactivationRequest/HandlerTests.cs b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RelationshipReactivationRequest/HandlerTests.cs index 23ce2c0c66..e37f00543e 100644 --- a/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RelationshipReactivationRequest/HandlerTests.cs +++ b/Modules/Relationships/test/Relationships.Application.Tests/Tests/Relationships/Commands/RelationshipReactivationRequest/HandlerTests.cs @@ -1,7 +1,7 @@ using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext; using Backbone.Modules.Relationships.Application.Infrastructure.Persistence.Repository; -using Backbone.Modules.Relationships.Application.Relationships.Commands.RelationshipReactivationRequest; +using Backbone.Modules.Relationships.Application.Relationships.Commands.RequestRelationshipReactivation; using Backbone.Modules.Relationships.Application.Tests.TestHelpers; using Backbone.Modules.Relationships.Domain.Aggregates.Relationships; using Backbone.UnitTestTools.Data; @@ -10,6 +10,7 @@ using Xunit; namespace Backbone.Modules.Relationships.Application.Tests.Tests.Relationships.Commands.RelationshipReactivationRequest; + public class HandlerTests { [Fact]