Skip to content

Commit

Permalink
Merge pull request #927 from bcgov/feature/ALCS-1098
Browse files Browse the repository at this point in the history
Bug Fixes Pt 2
  • Loading branch information
dhaselhan authored Aug 31, 2023
2 parents dcd7b7c + 961160c commit 76216e5
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export class SelectGovernmentComponent extends StepComponent implements OnInit,
}
});

if (this.draftMode) {
this.localGovernment.disable();
}

this.filteredLocalGovernments = this.localGovernment.valueChanges.pipe(
startWith(''),
map((value) => this.filter(value || ''))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h4>Application Documents</h4>
<ng-container matColumnDef='actions'>
<th mat-header-cell *matHeaderCellDef>Actions</th>
<td mat-cell *matCellDef='let element'>
<button mat-icon-button (click)='openFile(element.uuid)'>
<button mat-icon-button (click)='downloadFile(element.uuid)'>
<mat-icon>file_download</mat-icon>
</button>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ export class SubmissionDocumentsComponent implements OnInit, OnDestroy {
}
}

async downloadFile(uuid: string) {
const res = await this.applicationDocumentService.downloadFile(uuid);
if (res) {
const downloadLink = document.createElement('a');
downloadLink.href = res.url;
downloadLink.download = res.url.split('/').pop()!;
if (window.webkitURL == null) {
downloadLink.onclick = (event: MouseEvent) => document.body.removeChild(<Node>event.target);
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
}
downloadLink.click();
}
}

ngOnDestroy(): void {
this.$destroy.next();
this.$destroy.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ <h2>Government</h2>
submit, you will need to contact the ALC directly: &nbsp;<a href="mailto:ALC.Portal@gov.bc.ca">ALC.Portal@gov.bc.ca</a
>&nbsp;/&nbsp;<a href="tel:236-468-3342">236-468-3342</a>
</app-warning-banner>
<app-warning-banner *ngIf="selectedOwnGovernment" class="full-row">
You're logged in with a Business BCeID that is associated with the government selected above. You will have the
opportunity to complete the local or first nation government review form immediately after this notice of intent is
submitted.
</app-warning-banner>
<p>
Please Note: If your Local or First Nation Government is not listed, please contact the ALC directly.
<a href="mailto:ALC.Portal@gov.bc.ca">ALC.Portal@gov.bc.ca</a> / <a href="tel:236-468-3342">236-468-3342</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class SelectGovernmentComponent extends StepComponent implements OnInit,

localGovernment = new FormControl<string | any>('', [Validators.required]);
showWarning = false;
selectedOwnGovernment = false;
selectGovernmentUuid = '';
localGovernments: LocalGovernmentDto[] = [];
filteredLocalGovernments!: Observable<LocalGovernmentDto[]>;
Expand Down Expand Up @@ -74,8 +73,6 @@ export class SelectGovernmentComponent extends StepComponent implements OnInit,
} else {
this.localGovernment.setErrors({ invalid: localGovernment.hasGuid });
}

this.selectedOwnGovernment = localGovernment.matchesUserGuid;
}
}
}
Expand Down Expand Up @@ -141,7 +138,6 @@ export class SelectGovernmentComponent extends StepComponent implements OnInit,
if (!lg.hasGuid) {
this.localGovernment.setErrors({ invalid: true });
}
this.selectedOwnGovernment = lg.matchesUserGuid;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export class ApplicationDocumentService {
return undefined;
}

async downloadFile(fileUuid: string) {
try {
return await firstValueFrom(this.httpClient.get<{ url: string }>(`${this.serviceUrl}/${fileUuid}/download`));
} catch (e) {
console.error(e);
this.toastService.showErrorToast('Failed to download the document, please try again');
}
return undefined;
}

async deleteExternalFile(fileUuid: string) {
try {
this.overlayService.showSpinner();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ export class ApplicationDecisionProfile extends AutomapperProfile {
mapper,
ApplicationDecision,
ApplicationPortalDecisionDto,
forMember(
(ad) => ad.date,
mapFrom((a) => a.date?.getTime()),
),
forMember(
(a) => a.reconsiders,
mapFrom((dec) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class ApplicationPortalDecisionDto {
@AutoMap()
uuid: string;

@AutoMap()
date: number;

@AutoMap(() => ApplicationDecisionOutcomeCodeDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('ApplicationDocumentController', () => {
);
});

it('should call through for download', async () => {
it('should call through for open', async () => {
const fakeUrl = 'fake-url';
appDocumentService.getInlineUrl.mockResolvedValue(fakeUrl);
appDocumentService.get.mockResolvedValue(mockDocument);
Expand All @@ -131,6 +131,20 @@ describe('ApplicationDocumentController', () => {
expect(res.url).toEqual(fakeUrl);
});

it('should call through for download', async () => {
const fakeUrl = 'fake-url';
appDocumentService.getDownloadUrl.mockResolvedValue(fakeUrl);
appDocumentService.get.mockResolvedValue(mockDocument);

const res = await controller.download('fake-uuid', {
user: {
entity: {},
},
});

expect(res.url).toEqual(fakeUrl);
});

it('should call out to service to attach external document', async () => {
const user = { user: { entity: 'Bruce' } };
const fakeUuid = 'fakeUuid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ export class ApplicationDocumentController {
return { url };
}

@Get('/:uuid/download')
async download(@Param('uuid') fileUuid: string, @Req() req) {
const document = await this.applicationDocumentService.get(fileUuid);

//TODO: How do we know which documents applicant can access?
// await this.applicationSubmissionService.verifyAccess(
// document.applicationUuid,
// req.user.entity,
// );

const url = await this.applicationDocumentService.getDownloadUrl(document);
return { url };
}

@Patch('/application/:fileNumber')
async update(
@Param('fileNumber') fileNumber: string,
Expand Down

0 comments on commit 76216e5

Please sign in to comment.