Skip to content

Commit

Permalink
Consumer API: RelationshipReactivationCompleted external event is sen…
Browse files Browse the repository at this point in the history
…t 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
  • Loading branch information
tnotheis authored May 22, 2024
1 parent 536e207 commit 6be6814
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MediatR;

namespace Backbone.Modules.Relationships.Application.Relationships.Commands.AcceptRelationshipReactivation;

public class Handler : IRequestHandler<AcceptRelationshipReactivationCommand, AcceptRelationshipReactivationResponse>
{
private readonly IRelationshipsRepository _relationshipsRepository;
Expand All @@ -31,7 +32,7 @@ public async Task<AcceptRelationshipReactivationResponse> Handle(AcceptRelations

await _relationshipsRepository.Update(relationship);

_eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, _activeIdentity));
_eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, relationship.GetPeer(_activeIdentity)));

return new AcceptRelationshipReactivationResponse(relationship);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +7,7 @@
using MediatR;

namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RejectRelationshipReactivation;

public class Handler : IRequestHandler<RejectRelationshipReactivationCommand, RejectRelationshipReactivationResponse>
{
private readonly IRelationshipsRepository _relationshipsRepository;
Expand All @@ -33,7 +33,7 @@ public async Task<RejectRelationshipReactivationResponse> Handle(RejectRelations

await _relationshipsRepository.Update(relationship);

_eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, _activeIdentity));
_eventBus.Publish(new RelationshipReactivationCompletedDomainEvent(relationship, relationship.GetPeer(_activeIdentity)));

return new RejectRelationshipReactivationResponse(relationship);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestRelationshipReactivationCommand, RequestRelationshipReactivationResponse>
{
Expand All @@ -22,6 +22,7 @@ public Handler(IRelationshipsRepository relationshipsRepository, IUserContext us
_activeIdentity = userContext.GetAddress();
_activeDevice = userContext.GetDeviceId();
}

public async Task<RequestRelationshipReactivationResponse> Handle(RequestRelationshipReactivationCommand request, CancellationToken cancellationToken)
{
var relationshipId = RelationshipId.Parse(request.RelationshipId);
Expand All @@ -31,9 +32,7 @@ public async Task<RequestRelationshipReactivationResponse> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<RequestRelationshipReactivationResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MediatR;

namespace Backbone.Modules.Relationships.Application.Relationships.Commands.RevokeRelationshipReactivation;

public class Handler : IRequestHandler<RevokeRelationshipReactivationCommand, RevokeRelationshipReactivationResponse>
{
private readonly IRelationshipsRepository _relationshipsRepository;
Expand All @@ -31,9 +32,7 @@ public async Task<RevokeRelationshipReactivationResponse> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Xunit;

namespace Backbone.Modules.Relationships.Application.Tests.Tests.Relationships.Commands.AcceptRelationshipReactivation;

public class HandlerTests
{
[Fact]
Expand Down Expand Up @@ -108,7 +109,7 @@ await handler.Handle(new AcceptRelationshipReactivationCommand
A.CallTo(
() => mockEventBus.Publish(A<RelationshipReactivationCompletedDomainEvent>.That.Matches(e =>
e.RelationshipId == relationship.Id &&
e.Peer == activeIdentity)
e.Peer == identityTo)
))
.MustHaveHappenedOnceExactly();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Xunit;

namespace Backbone.Modules.Relationships.Application.Tests.Tests.Relationships.Commands.RejectRelationshipReactivation;

public class HandlerTests
{
[Fact]
Expand Down Expand Up @@ -76,7 +77,7 @@ await handler.Handle(new RejectRelationshipReactivationCommand
A.CallTo(
() => mockEventBus.Publish(A<RelationshipReactivationCompletedDomainEvent>.That.Matches(e =>
e.RelationshipId == relationship.Id &&
e.Peer == activeIdentity)
e.Peer == identityTo)
))
.MustHaveHappenedOnceExactly();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +10,7 @@
using Xunit;

namespace Backbone.Modules.Relationships.Application.Tests.Tests.Relationships.Commands.RelationshipReactivationRequest;

public class HandlerTests
{
[Fact]
Expand Down

0 comments on commit 6be6814

Please sign in to comment.