Skip to content

Commit 00e186e

Browse files
authored
Merge pull request #667 from bcgov/yj
feat(dss-868)
2 parents 617657d + 78b8016 commit 00e186e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

server/StrDss.Api/Controllers/RentalListingReportsController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,14 @@ public async Task<ActionResult> GetRentalListingHistory(long? platformId, int pa
7878
return Ok(history);
7979
}
8080

81-
[ApiAuthorize(Permissions.UploadHistoryRead)]
81+
[ApiAuthorize(Permissions.LicenceFileUpload, Permissions.ListingFileUpload)]
8282
[HttpGet("uploads/{uploadId}/errorfile")]
8383
public async Task<ActionResult> GetRentalListingErrorFile(long uploadId)
8484
{
85-
var bytes = await _uploadService.GetRentalListingErrorFile(uploadId);
85+
var (bytes, hasPermission) = await _uploadService.GetRentalListingErrorFile(uploadId);
86+
87+
if (!hasPermission)
88+
return Unauthorized();
8689

8790
if (bytes == null)
8891
return NotFound();

server/StrDss.Service/UploadDeliveryService.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface IUploadDeliveryService
1919
Task<Dictionary<string, List<string>>> UploadPlatformData(string reportType, string reportPeriod, long orgId, Stream stream);
2020
Task<(Dictionary<string, List<string>>, string header)> ValidateAndParseUploadAsync(string reportPeriod, long orgId, string reportType, string hashValue, string[] mandatoryFields, TextReader textReader, List<DssUploadLine> uploadLines);
2121
Task<PagedDto<UploadHistoryViewDto>> GetUploadHistory(long? orgId, int pageSize, int pageNumber, string orderBy, string direction, string[] reportTypes);
22-
Task<byte[]?> GetRentalListingErrorFile(long uploadId);
22+
Task<(byte[]?, bool hasAccess)> GetRentalListingErrorFile(long uploadId);
2323
Task<DssUploadDelivery?> GetNonTakedownUploadToProcessAsync();
2424
Task<DssUploadDelivery?> GetUploadToProcessAsync(string reportType);
2525
}
@@ -501,15 +501,25 @@ public async Task<PagedDto<UploadHistoryViewDto>> GetUploadHistory(long? orgId,
501501
return await _uploadRepo.GetUploadHistory(orgId, pageSize, pageNumber, orderBy, direction, reportTypes);
502502
}
503503

504-
public async Task<byte[]?> GetRentalListingErrorFile(long uploadId)
504+
public async Task<(byte[]?, bool hasAccess)> GetRentalListingErrorFile(long uploadId)
505505
{
506506
var upload = await _uploadRepo.GetRentalListingUploadWithErrors(uploadId);
507507

508-
if (upload == null) return null;
508+
if (upload == null) return (null, true);
509509

510-
var fullData = upload.UploadDeliveryType == UploadDeliveryTypes.LicenceData;
510+
// so far, there are two types of error files - ListingData and LicenceData
511+
var licenceData = upload.UploadDeliveryType == UploadDeliveryTypes.LicenceData;
511512

512-
var linesWithError = await _uploadRepo.GetUploadLineIdsWithErrors(uploadId, fullData);
513+
var hasPermission = licenceData
514+
? _currentUser.Permissions.Contains(Permissions.LicenceFileUpload)
515+
: _currentUser.Permissions.Contains(Permissions.ListingFileUpload);
516+
517+
if (!hasPermission)
518+
{
519+
return (null, false);
520+
}
521+
522+
var linesWithError = await _uploadRepo.GetUploadLineIdsWithErrors(uploadId, licenceData);
513523

514524
var memoryStream = new MemoryStream(upload.SourceBin!);
515525
using TextReader textReader = new StreamReader(memoryStream, Encoding.UTF8);
@@ -532,7 +542,7 @@ public async Task<PagedDto<UploadHistoryViewDto>> GetUploadHistory(long? orgId,
532542
contents.AppendLine(line.LineText.TrimEndNewLine() + $",\"{line.ErrorText ?? ""}\"");
533543
}
534544

535-
return Encoding.UTF8.GetBytes(contents.ToString());
545+
return (Encoding.UTF8.GetBytes(contents.ToString()), hasPermission);
536546
}
537547

538548
public async Task<DssUploadDelivery?> GetNonTakedownUploadToProcessAsync()

0 commit comments

Comments
 (0)