Skip to content

Commit

Permalink
Add correct party ID to all events to ensure correct receiver for eve…
Browse files Browse the repository at this point in the history
…nt (#453)

* fix correct source on all events

* Add missing events with wrong or missing partyId

* add AlternativeSubject to events

---------

Co-authored-by: Hammerbeck <[email protected]>
  • Loading branch information
Andreass2 and Hammerbeck authored May 27, 2024
1 parent 52f87b1 commit 025dafa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public async Task<OneOf<Task, Error>> Process(ConfirmDownloadCommandRequest requ
{
return Task.CompletedTask;
}

await _actorFileTransferStatusRepository.InsertActorFileTransferStatus(request.FileTransferId, ActorFileTransferStatus.DownloadConfirmed, request.Token.Consumer, cancellationToken);
await _eventBus.Publish(AltinnEventType.DownloadConfirmed, fileTransfer.ResourceId, fileTransfer.FileTransferId.ToString(), request.Token.Consumer, cancellationToken);
await _eventBus.Publish(AltinnEventType.DownloadConfirmed, fileTransfer.ResourceId, fileTransfer.FileTransferId.ToString(), fileTransfer.Sender.ActorExternalId, cancellationToken);
bool shouldConfirmAll = fileTransfer.RecipientCurrentStatuses.Where(recipientStatus => recipientStatus.Actor.ActorExternalId != request.Token.Consumer).All(status => status.Status >= ActorFileTransferStatus.DownloadConfirmed);
if (shouldConfirmAll)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task<OneOf<Task, Error>> Process(ExpireFileTransferCommandRequest r
else if (!request.DoNotUpdateStatus)
{
await _fileTransferStatusRepository.InsertFileTransferStatus(fileTransfer.FileTransferId, Core.Domain.Enums.FileTransferStatus.Purged, cancellationToken: cancellationToken);
await _eventBus.Publish(AltinnEventType.FilePurged, fileTransfer.ResourceId, fileTransfer.FileTransferId.ToString(), null, cancellationToken);
await _eventBus.Publish(AltinnEventType.FilePurged, fileTransfer.ResourceId, fileTransfer.FileTransferId.ToString(), fileTransfer.Sender.ActorExternalId, cancellationToken);
}
if (request.Force || fileTransfer.ExpirationTime < DateTime.UtcNow)
{
Expand All @@ -58,6 +58,7 @@ public async Task<OneOf<Task, Error>> Process(ExpireFileTransferCommandRequest r
_logger.LogError("Recipient {recipientExternalReference} did not download the fileTransfer with id {fileTransferId}", recipient.Actor.ActorExternalId, recipient.FileTransferId.ToString());
await _eventBus.Publish(AltinnEventType.FileNeverConfirmedDownloaded, fileTransfer.ResourceId, fileTransfer.FileTransferId.ToString(), recipient.Actor.ActorExternalId, cancellationToken);
}
await _eventBus.Publish(AltinnEventType.FileNeverConfirmedDownloaded, fileTransfer.ResourceId, fileTransfer.FileTransferId.ToString(), fileTransfer.Sender.ActorExternalId, cancellationToken);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public async Task<OneOf<Task, Error>> Process(ScanResultData data, CancellationT
_logger.LogInformation("Non-malicious result for {fileTransferId} with result type {scanResultType}", fileTransferId, data.ScanResultType);
await _fileTransferStatusRepository.InsertFileTransferStatus(fileTransferId, Core.Domain.Enums.FileTransferStatus.Published, cancellationToken: cancellationToken);
await _eventBus.Publish(AltinnEventType.Published, fileTransfer.ResourceId, fileTransferIdFromUri, fileTransfer.Sender.ActorExternalId, cancellationToken);
foreach (var recipient in fileTransfer.RecipientCurrentStatuses)
{
await _eventBus.Publish(AltinnEventType.Published, fileTransfer.ResourceId, fileTransferIdFromUri, recipient.Actor.ActorExternalId, cancellationToken);
}
return Task.CompletedTask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task Publish(AltinnEventType type, string resourceId, string fileTr
if (partyId != null) await _partyRepository.InitializeParty(organizationId, partyId);
}
}
var cloudEvent = CreateCloudEvent(type, resourceId, fileTransferId, partyId);
var cloudEvent = CreateCloudEvent(type, resourceId, fileTransferId, partyId, organizationId);
var serializerOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = new LowerCaseNamingPolicy()
Expand All @@ -53,7 +53,7 @@ public async Task Publish(AltinnEventType type, string resourceId, string fileTr
}
}

private CloudEvent CreateCloudEvent(AltinnEventType type, string resourceId, string fileTransferId, string? partyId)
private CloudEvent CreateCloudEvent(AltinnEventType type, string resourceId, string fileTransferId, string? partyId, string? alternativeSubject)
{
CloudEvent cloudEvent = new CloudEvent()
{
Expand All @@ -63,8 +63,9 @@ private CloudEvent CreateCloudEvent(AltinnEventType type, string resourceId, str
Resource = "urn:altinn:resource:" + resourceId,
ResourceInstance = fileTransferId,
Type = "no.altinn.broker." + type.ToString().ToLowerInvariant(),
Source = _altinnOptions.PlatformGatewayUrl + "broker/api/v1/file",
Subject = !string.IsNullOrWhiteSpace(partyId) ? "/party/" + partyId : null
Source = _altinnOptions.PlatformGatewayUrl + "broker/api/v1/filetransfer",
Subject = !string.IsNullOrWhiteSpace(partyId) ? "/party/" + partyId : null,
AlternativeSubject = !string.IsNullOrWhiteSpace(alternativeSubject) ? "/organisation/" + alternativeSubject : null,
};

return cloudEvent;
Expand Down

0 comments on commit 025dafa

Please sign in to comment.