Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions prime-angular-frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AccessDeniedComponent } from '@lib/modules/root-routes/components/acces
import { MaintenanceComponent } from '@lib/modules/root-routes/components/maintenance/maintenance.component';
import { PageNotFoundComponent } from '@lib/modules/root-routes/components/page-not-found/page-not-found.component';
import { HelpComponent } from '@lib/modules/root-routes/components/help/help.component';
import { UnderagedComponent } from '@lib/modules/root-routes/components/underaged/underaged.component';

import { AuthRoutes } from '@auth/auth.routes';
import { EnrolmentRoutes } from '@enrolment/enrolment.routes';
Expand All @@ -19,6 +18,7 @@ import { SatEformsRoutes } from '@sat/sat-eforms.routes';
import { GisEnrolmentRoutes } from '@gis/gis-enrolment.routes';
import { HealthAuthSiteRegRoutes } from '@health-auth/health-auth-site-reg.routes';
import { PaperEnrolmentRoutes } from '@paper-enrolment/paper-enrolment.routes';
import { NotEligibleComponent } from '@lib/modules/root-routes/components/not-eligible/not-eligible.component';

const routes: Routes = [
{
Expand Down Expand Up @@ -70,11 +70,18 @@ const routes: Routes = [
},
{
path: AppRoutes.UNDERAGED,
component: UnderagedComponent,
component: NotEligibleComponent,
data: {
title: 'Underaged'
}
},
{
path: AppRoutes.IDENTITY_INSURANCE_LEVEL,
component: NotEligibleComponent,
data: {
title: 'Identity Insurance Level Not Met'
}
},
{
path: AppRoutes.MAINTENANCE,
component: MaintenanceComponent,
Expand Down Expand Up @@ -110,4 +117,4 @@ const routes: Routes = [
imports: [RouterModule.forRoot(routes, { enableTracing: false })],
exports: [RouterModule]
})
export class AppRoutingModule {}
export class AppRoutingModule { }
1 change: 1 addition & 0 deletions prime-angular-frontend/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export class AppRoutes {
public static DENIED = 'denied';
public static UNDERAGED = 'underaged';
public static IDENTITY_INSURANCE_LEVEL = 'identity-insurance-level';

Check warning on line 4 in prime-angular-frontend/src/app/app.routes.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make this public static property readonly.

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ7xGx94UQCvAIt9uRjy&open=AZ7xGx94UQCvAIt9uRjy&pullRequest=2875
public static MAINTENANCE = 'maintenance';
public static PAGE_NOT_FOUND = 'page-not-found';
public static HELP = 'help';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TestBed } from '@angular/core/testing';
import { CanActivateFn } from '@angular/router';

import { IdentityInsuranceLevelGuard } from './identity-insurance-level.guard';

describe('IdentityInsuranceLevelGuard', () => {
const executeGuard: CanActivateFn = (...guardParameters) =>
TestBed.runInInjectionContext(() => IdentityInsuranceLevelGuard(...guardParameters));
Comment thread
bergomi02 marked this conversation as resolved.
Fixed

beforeEach(() => {
TestBed.configureTestingModule({});
});

it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Injectable } from '@angular/core';
import { Route, UrlSegment, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';

import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { AppRoutes } from 'app/app.routes';
import { AuthService } from '@auth/shared/services/auth.service';
import { BcscUser } from '@auth/shared/models/bcsc-user.model';

@Injectable({
providedIn: 'root'
})
export class IdentityInsuranceLevelGuard {
constructor(
private router: Router,

Check warning on line 15 in prime-angular-frontend/src/app/core/guards/identity-insurance-level.guard.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Member 'router: Router' is never reassigned; mark it as `readonly`.

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ7xGx9aUQCvAIt9uRjw&open=AZ7xGx9aUQCvAIt9uRjw&pullRequest=2875
private authService: AuthService

Check warning on line 16 in prime-angular-frontend/src/app/core/guards/identity-insurance-level.guard.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Member 'authService: AuthService' is never reassigned; mark it as `readonly`.

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ7xGx9aUQCvAIt9uRjx&open=AZ7xGx9aUQCvAIt9uRjx&pullRequest=2875
) { }

public canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.checkIdentityInsuranceLevel();
}

public canActivateChild(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.canActivate(next, state);
}

public canLoad(
route: Route,
segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
return this.checkIdentityInsuranceLevel();
}

private checkIdentityInsuranceLevel(): Observable<boolean> | Promise<boolean> | boolean {
return this.authService.getUser$()
.pipe(
map((user: BcscUser) => user.identityInsuranceLevel),
map((identityInsuranceLevel: number) => identityInsuranceLevel < 3),
map((unauthorized: boolean) => {
if (unauthorized) {
this.router.navigate([AppRoutes.IDENTITY_INSURANCE_LEVEL]);
return false;
}

return true;
})
);
}
}
50 changes: 25 additions & 25 deletions prime-angular-frontend/src/app/core/guards/underaged.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AuthService } from '@auth/shared/services/auth.service';
import { AppRoutes } from 'app/app.routes';
import { UnderagedComponent } from '@lib/modules/root-routes/components/underaged/underaged.component';
import { KeycloakService } from 'keycloak-angular';
import { MockAuthService } from 'test/mocks/mock-auth.service';


import { UnderagedGuard } from './underaged.guard';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { NonEligibleComponent } from '@lib/modules/root-routes/components/not-eligible/not-eligible.component';


describe('UnderagedGuard', () => {
let guard: UnderagedGuard;
let guard: UnderagedGuard;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([
{
path: AppRoutes.UNDERAGED,
component: UnderagedComponent
}
])],
providers: [
{
provide: AuthService,
useClass: MockAuthService
},
KeycloakService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
]
});
guard = TestBed.inject(UnderagedGuard);
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes([
{
path: AppRoutes.UNDERAGED,
component: NonEligibleComponent
}
])],
providers: [
{
provide: AuthService,
useClass: MockAuthService
},
KeycloakService,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting()
]
});
guard = TestBed.inject(UnderagedGuard);
});

it('should be created', () => {
expect(guard).toBeTruthy();
});
it('should be created', () => {
expect(guard).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="row justify-content-center">
<div class="col-sm-12 col-md-8 col-lg-6 text-center">
<p class="mb-5">
You are not eligible to enrol in PRIME. If you believe you have received this page in error, please call
<app-prime-phone></app-prime-phone> or email <app-prime-email></app-prime-email>
You are not eligible to enrol in PRIME. If you believe you have received this page in error, please
email <app-prime-email></app-prime-email>
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';

import { UnderagedComponent } from './underaged.component';
import { NotEligibleComponent } from './not-eligible.component';

describe('UnderagedComponent', () => {
let component: UnderagedComponent;
let fixture: ComponentFixture<UnderagedComponent>;
describe('NotEligibleComponent', () => {
let component: NotEligibleComponent;
let fixture: ComponentFixture<NotEligibleComponent>;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [UnderagedComponent],
declarations: [NotEligibleComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(UnderagedComponent);
fixture = TestBed.createComponent(NotEligibleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-not-eligible',
templateUrl: './not-eligible.component.html',
styleUrls: ['./not-eligible.component.scss'],
standalone: false

Check failure on line 7 in prime-angular-frontend/src/app/lib/modules/root-routes/components/not-eligible/not-eligible.component.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Components, Directives and Pipes should not opt out of standalone. Following this guide is highly recommended: https://angular.dev/reference/migrations/standalone

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ7xGx4yUQCvAIt9uRjt&open=AZ7xGx4yUQCvAIt9uRjt&pullRequest=2875
})
export class NotEligibleComponent implements OnInit {
constructor() { }

public ngOnInit(): void { }

Check failure on line 12 in prime-angular-frontend/src/app/lib/modules/root-routes/components/not-eligible/not-eligible.component.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected empty method 'ngOnInit'.

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ7xGx4yUQCvAIt9uRjv&open=AZ7xGx4yUQCvAIt9uRjv&pullRequest=2875

Check failure on line 12 in prime-angular-frontend/src/app/lib/modules/root-routes/components/not-eligible/not-eligible.component.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Lifecycle methods should not be empty

See more on https://sonarcloud.io/project/issues?id=bcgov_moh-prime&issues=AZ7xGx4yUQCvAIt9uRju&open=AZ7xGx4yUQCvAIt9uRju&pullRequest=2875
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PageNotFoundComponent } from './components/page-not-found/page-not-foun
import { MaintenanceComponent } from './components/maintenance/maintenance.component';
import { PageSimpleComponent } from './components/page-simple/page-simple.component';
import { HelpComponent } from './components/help/help.component';
import { UnderagedComponent } from './components/underaged/underaged.component';
import { NotEligibleComponent } from './components/not-eligible/not-eligible.component';

@NgModule({
imports: [
Expand All @@ -19,15 +19,15 @@ import { UnderagedComponent } from './components/underaged/underaged.component';
PageNotFoundComponent,
MaintenanceComponent,
HelpComponent,
UnderagedComponent
NotEligibleComponent,
],
exports: [
PageSimpleComponent,
AccessDeniedComponent,
PageNotFoundComponent,
MaintenanceComponent,
HelpComponent,
UnderagedComponent
NotEligibleComponent,
]
})
export class RootRoutesModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class EnrolleeAccessTermEnrolmentComponent extends AbstractComponent impl
phone,
phoneExtension,
enrolleeCareSettings,
identityInsuranceLevel,
...remainder
} = enrollee;

Expand All @@ -119,7 +120,8 @@ export class EnrolleeAccessTermEnrolmentComponent extends AbstractComponent impl
email,
smsPhone,
phone,
phoneExtension
phoneExtension,
identityInsuranceLevel
},
// Provide the default and allow it to be overridden
collectionNoticeAccepted: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import { EnrolleeAbsence } from '@shared/models/enrollee-absence.model';
import { AdjudicationRoutes } from '@adjudication/adjudication.routes';

@Component({
selector: 'app-enrollee-overview',
templateUrl: './enrollee-overview.component.html',
styleUrls: ['./enrollee-overview.component.scss'],
standalone: false
selector: 'app-enrollee-overview',
templateUrl: './enrollee-overview.component.html',
styleUrls: ['./enrollee-overview.component.scss'],
standalone: false
})
export class EnrolleeOverviewComponent extends AdjudicationContainerComponent implements OnInit {
public enrollee: HttpEnrollee;
Expand Down Expand Up @@ -144,6 +144,7 @@ export class EnrolleeOverviewComponent extends AdjudicationContainerComponent im
phone,
phoneExtension,
userProvidedGpid,
identityInsuranceLevel,
...remainder
} = enrollee;

Expand All @@ -168,7 +169,8 @@ export class EnrolleeOverviewComponent extends AdjudicationContainerComponent im
smsPhone,
phone,
phoneExtension,
userProvidedGpid
userProvidedGpid,
identityInsuranceLevel
},
// Provide the default and allow it to be overridden
collectionNoticeAccepted: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { HttpEnrollee, Enrolment } from '@shared/models/enrolment.model';
import { AdjudicationRoutes } from '@adjudication/adjudication.routes';

@Component({
selector: 'app-enrolment',
templateUrl: './enrolment.component.html',
styleUrls: ['./enrolment.component.scss'],
standalone: false
selector: 'app-enrolment',
templateUrl: './enrolment.component.html',
styleUrls: ['./enrolment.component.scss'],
standalone: false
})
export class EnrolmentComponent extends AbstractComponent implements OnInit {
public busy: Subscription;
Expand Down Expand Up @@ -76,6 +76,7 @@ export class EnrolmentComponent extends AbstractComponent implements OnInit {
smsPhone,
phone,
phoneExtension,
identityInsuranceLevel,
...remainder
} = enrollee;

Expand All @@ -100,7 +101,8 @@ export class EnrolmentComponent extends AbstractComponent implements OnInit {
email,
smsPhone,
phone,
phoneExtension
phoneExtension,
identityInsuranceLevel
},
// Provide the default and allow it to be overridden
collectionNoticeAccepted: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface BcscUser extends User {
givenNames: string;
dateOfBirth: string;
verifiedAddress: Address;
identityInsuranceLevel: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class AuthService implements IAuthService {
const city = token?.address?.locality;
const postal = token?.address?.postal_code;
const givenNames = token?.given_names;
const identityInsuranceLevel = token?.identity_assurance_level;

const userId = token?.sub;
const username = token?.preferred_username; // Expecting e.g. gtcochh2vajdtodkby27kspv554dn4is@bcsc
Expand Down Expand Up @@ -133,6 +134,7 @@ export class AuthService implements IAuthService {
dateOfBirth,
verifiedAddress,
email,
identityInsuranceLevel,
...claims
} as BcscUser;
}
Expand Down
Loading
Loading