-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic for downloading attachment for A2 GUI (#421)
* Add logic for downloading attachment for A2 GUI * null check fileName * Checkout before using action (#423) * Fix deploy permission (#425) * Fix: Ensure correspondence is fetched before updating to Read or Confirmed (#427) * fix: validate correspondence has been fetched before it can be read and confirmed * update tests * typo fix * Handle potential null value for IsConfirmationNeeded * reuse factory for client initialization * rename testname * add Fetched to statuses available for Recipient * Legacy/overview auth! (#430) * Initial functionality for legacy correspondenceOverview * improvements * better naming * better text for api route * add auth for legacy overview * better error message * fix variable names * improve minAuthLevel function * Better naming --------- Co-authored-by: Hammerbeck <[email protected]> * Missing reference to Github environment in CI/CD (#436) * Add logic to check if user is recipient * Fix deploy permission (#425) * Fix: Ensure correspondence is fetched before updating to Read or Confirmed (#427) * fix: validate correspondence has been fetched before it can be read and confirmed * update tests * typo fix * Handle potential null value for IsConfirmationNeeded * reuse factory for client initialization * rename testname * add Fetched to statuses available for Recipient * Missing reference to Github environment in CI/CD (#436) * remove duplicate and rewrite userClaim logic * remove unused usings * add norwegian org prefix to recipient check --------- Co-authored-by: Roar Mjelde <[email protected]> Co-authored-by: Andreas Hammerbeck <[email protected]> Co-authored-by: Hammerbeck <[email protected]>
- Loading branch information
1 parent
e6e2d6e
commit 4cb90ac
Showing
4 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ication/DownloadCorrespondenceAttachment/LegacyDownloadCorrespondenceAttachmentHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Altinn.Correspondence.Application.Helpers; | ||
using Altinn.Correspondence.Core.Repositories; | ||
using Altinn.Correspondence.Core.Services; | ||
using Altinn.Correspondence.Core.Services.Enums; | ||
using Hangfire; | ||
using OneOf; | ||
|
||
namespace Altinn.Correspondence.Application.DownloadCorrespondenceAttachment; | ||
|
||
public class LegacyDownloadCorrespondenceAttachmentHandler : IHandler<DownloadCorrespondenceAttachmentRequest, DownloadCorrespondenceAttachmentResponse> | ||
{ | ||
private readonly ICorrespondenceRepository _correspondenceRepository; | ||
private readonly IStorageRepository _storageRepository; | ||
private readonly IAttachmentRepository _attachmentRepository; | ||
private readonly IAltinnRegisterService _altinnRegisterService; | ||
private readonly UserClaimsHelper _userClaimsHelper; | ||
private readonly IBackgroundJobClient _backgroundJobClient; | ||
|
||
public LegacyDownloadCorrespondenceAttachmentHandler(IStorageRepository storageRepository, IAttachmentRepository attachmentRepository, ICorrespondenceRepository correspondenceRepository, UserClaimsHelper userClaimsHelper, IBackgroundJobClient backgroundJobClient, IAltinnRegisterService altinnRegisterService) | ||
{ | ||
_correspondenceRepository = correspondenceRepository; | ||
_storageRepository = storageRepository; | ||
_attachmentRepository = attachmentRepository; | ||
_altinnRegisterService = altinnRegisterService; | ||
_userClaimsHelper = userClaimsHelper; | ||
_backgroundJobClient = backgroundJobClient; | ||
} | ||
|
||
public async Task<OneOf<DownloadCorrespondenceAttachmentResponse, Error>> Process(DownloadCorrespondenceAttachmentRequest request, CancellationToken cancellationToken) | ||
{ | ||
var partyId = _userClaimsHelper.GetPartyId(); | ||
if (partyId is null) | ||
{ | ||
return Errors.InvalidPartyId; | ||
} | ||
var party = await _altinnRegisterService.LookUpPartyByPartyId(partyId.Value, cancellationToken); | ||
if (party is null || (string.IsNullOrEmpty(party.SSN) && string.IsNullOrEmpty(party.OrgNumber))) | ||
{ | ||
return Errors.CouldNotFindOrgNo; | ||
} | ||
|
||
var correspondence = await _correspondenceRepository.GetCorrespondenceById(request.CorrespondenceId, true, false, cancellationToken); | ||
if (correspondence is null) | ||
{ | ||
return Errors.CorrespondenceNotFound; | ||
} | ||
var attachment = await _attachmentRepository.GetAttachmentByCorrespondenceIdAndAttachmentId(request.CorrespondenceId, request.AttachmentId, cancellationToken); | ||
if (attachment is null) | ||
{ | ||
return Errors.AttachmentNotFound; | ||
} | ||
bool isRecipient = correspondence.Recipient == ("0192:"+party.OrgNumber) || correspondence.Recipient == party.SSN; | ||
if (!isRecipient) | ||
{ | ||
return Errors.CorrespondenceNotFound; | ||
} | ||
var latestStatus = correspondence.GetLatestStatus(); | ||
if (!latestStatus.Status.IsAvailableForRecipient()) | ||
{ | ||
return Errors.CorrespondenceNotFound; | ||
} | ||
var attachmentStream = await _storageRepository.DownloadAttachment(attachment.Id, cancellationToken); | ||
_backgroundJobClient.Enqueue<IDialogportenService>((dialogportenService) => dialogportenService.CreateInformationActivity(request.CorrespondenceId, DialogportenActorType.Recipient, DialogportenTextType.DownloadStarted, attachment.FileName ?? attachment.Name)); | ||
return new DownloadCorrespondenceAttachmentResponse(){ | ||
FileName = attachment.FileName ?? attachment.Name, | ||
Stream = attachmentStream | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters