diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 3bbe540..43f126f 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,7 +4,6 @@ import {Irish} from "./shared/irish"; import {ErrorPageComponent} from "./openaireLibrary/error/errorPage.component"; import {AdminLoginGuard} from "./openaireLibrary/login/adminLoginGuard.guard"; import {HasConsentGuard} from "./shared/hasConsent.guard"; -import {LoginGuard} from "./openaireLibrary/login/loginGuard.guard"; const routes: Routes = [ { @@ -40,7 +39,7 @@ const routes: Routes = [ { path: 'upload-dois', loadChildren: () => import('./upload-dois/upload-dois.module').then(m => m.UploadDoisModule), - data: {title: Irish.METADATA_PREFIX}, canActivate: [LoginGuard, HasConsentGuard] + data: {title: Irish.METADATA_PREFIX}, canActivate: [HasConsentGuard] }, { path: 'admin', @@ -50,13 +49,13 @@ const routes: Routes = [ }, {path: 'public-logs', loadChildren: () => import('./public-logs/public-logs.module').then(m => m.PublicLogsModule)}, {path: 'user-policy', loadChildren: () => import('./user-policy/user-policy.module').then(m => m.UserPolicyModule)}, - {path: 'participate', loadChildren: () => import('./claims/claims.module').then(m => m.ClaimsModule), canActivate: [LoginGuard, HasConsentGuard]}, + {path: 'participate', loadChildren: () => import('./claims/claims.module').then(m => m.ClaimsModule), canActivate: [HasConsentGuard]}, { path: '', loadChildren: () => import('./national/national.module').then(m => m.NationalModule) }, - {path: 'orcid', loadChildren: () => import('./orcid/orcid.module').then(m => m.LibOrcidModule), canActivate: [LoginGuard, HasConsentGuard]}, - {path: 'my-orcid-links', loadChildren: () => import('./orcid/my-orcid-links/myOrcidLinks.module').then(m => m.LibMyOrcidLinksModule), canActivate: [LoginGuard, HasConsentGuard]}, + {path: 'orcid', loadChildren: () => import('./orcid/orcid.module').then(m => m.LibOrcidModule), canActivate: [HasConsentGuard]}, + {path: 'my-orcid-links', loadChildren: () => import('./orcid/my-orcid-links/myOrcidLinks.module').then(m => m.LibMyOrcidLinksModule), canActivate: [HasConsentGuard]}, {path: 'error', component: ErrorPageComponent}, {path: '**', pathMatch: 'full', component: ErrorPageComponent} ]; diff --git a/src/app/public-logs/public-logs.component.ts b/src/app/public-logs/public-logs.component.ts index 528fe16..185deed 100644 --- a/src/app/public-logs/public-logs.component.ts +++ b/src/app/public-logs/public-logs.component.ts @@ -5,8 +5,6 @@ import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service'; import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service'; import {Meta, Title} from '@angular/platform-browser'; import {LogService} from "../openaireLibrary/utils/log/log.service"; -import {UserManagementService} from "../openaireLibrary/services/user-management.service"; -import {CookieLawService} from "../openaireLibrary/sharedComponents/cookie-law/cookie-law.service"; @Component({ selector: 'public-logs', @@ -90,8 +88,7 @@ export class PublicLogsComponent extends BaseComponent implements OnInit { protected _piwikService: PiwikService, protected _title: Title, protected _meta: Meta, - private _logService:LogService, - private userManagementsService: UserManagementService, private cookieLawService: CookieLawService) { + private _logService:LogService) { super(); this.startDate.setFullYear(2023,11,1) this.months = Array.from({ length:12 }, (_, index) => 12 - index); diff --git a/src/app/shared/hasConsent.guard.ts b/src/app/shared/hasConsent.guard.ts index 6eb05a9..3275904 100644 --- a/src/app/shared/hasConsent.guard.ts +++ b/src/app/shared/hasConsent.guard.ts @@ -1,32 +1,48 @@ -import {ActivatedRouteSnapshot, Route, Router, RouterStateSnapshot, UrlTree} from '@angular/router'; -import {Observable} from 'rxjs'; +import {ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree} from '@angular/router'; +import {Observable, merge, forkJoin} from 'rxjs'; import {UserProfileService} from "../openaireLibrary/services/userProfile.service"; -import {map, tap} from "rxjs/operators"; +import {filter, map, take} from "rxjs/operators"; import {Injectable} from "@angular/core"; - +import {UserManagementService} from "../openaireLibrary/services/user-management.service"; +import {LoginErrorCodes} from "../openaireLibrary/login/utils/guardHelper.class"; @Injectable({ providedIn: 'root' }) export class HasConsentGuard { constructor(private router: Router, - private _userProfileService: UserProfileService) { + private _userProfileService: UserProfileService, + private userManagementService: UserManagementService) { } check(path: string): Observable | boolean { - return this._userProfileService.getUserProfile().pipe(map(userProfile => { - return userProfile.consent; - }),tap(hasConsent => { - if(!hasConsent) { - this.router.navigate(['/user-policy'], { - queryParams: { - 'redirectUrl': path + return forkJoin([ + this.userManagementService.getUserInfo().pipe(take(1)), + this._userProfileService.getUserProfile().pipe(take(1)) + ]).pipe( + map(([user, userProfile]) => { + if (user) { + if(userProfile && userProfile.consent){ + return true; + }else{ + this.router.navigate(['/user-policy'], { + queryParams: { + 'redirectUrl': path + } + }); + return false; } - }); - } - })); - - + }else{ + this.router.navigate(['/user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_LOGIN, + 'redirectUrl': path + } + }) + return false; + } + }) + ); } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { @@ -36,8 +52,8 @@ export class HasConsentGuard { canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { return this.check(state.url); } - +/* canLoad(route: Route): Observable | Promise | boolean { return this.check('/' + route.path); - } + }*/ } diff --git a/src/app/user-policy/user-policy.component.ts b/src/app/user-policy/user-policy.component.ts index 2c288d2..bce3fd9 100644 --- a/src/app/user-policy/user-policy.component.ts +++ b/src/app/user-policy/user-policy.component.ts @@ -11,7 +11,7 @@ import {UserProfileService} from "../openaireLibrary/services/userProfile.servic @Component({ selector: 'user-policy', template: ` -
+

User Policy

@@ -22,7 +22,6 @@ import {UserProfileService} from "../openaireLibrary/services/userProfile.servic Accept policy
-
@@ -34,6 +33,7 @@ export class UserPolicyComponent extends BaseComponent implements OnInit { hasConsent = false; value = false; redirectEnabled =true; + loading = true; constructor(protected _router: Router, protected _route: ActivatedRoute, protected seoService: SEOService, @@ -46,6 +46,7 @@ export class UserPolicyComponent extends BaseComponent implements OnInit { } ngOnInit() { + this.loading = true; this.title = 'User policy'; this.description = 'OA Monitor Ireland - User policy'; this.setMetadata(); @@ -58,8 +59,10 @@ export class UserPolicyComponent extends BaseComponent implements OnInit { if(this.hasConsent && this.redirectEnabled){ this.redirect(); } + this.loading = false; }, error => { this.hasConsent = false; + this.loading = false; })); } accept(){