-
Notifications
You must be signed in to change notification settings - Fork 11
OHID-504 Prevent enrollee with Identity Insurance Level lower than 3 to enroll #2875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
d3d52f8
ff025dc
ef25ed3
3b0f511
e8d59e0
cdc5aad
0a5742e
ca9ead7
c78342f
9305fda
08aa500
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)); | ||
|
|
||
| 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
|
||
| private authService: AuthService | ||
|
Check warning on line 16 in prime-angular-frontend/src/app/core/guards/identity-insurance-level.guard.ts
|
||
| ) { } | ||
|
|
||
| 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; | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
| 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
|
||
| }) | ||
| 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
|
||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.