update hasConsent Guard logic, remove loginGuard from app routing module
This commit is contained in:
parent
c6234de801
commit
d03d92f027
|
@ -4,7 +4,6 @@ import {Irish} from "./shared/irish";
|
||||||
import {ErrorPageComponent} from "./openaireLibrary/error/errorPage.component";
|
import {ErrorPageComponent} from "./openaireLibrary/error/errorPage.component";
|
||||||
import {AdminLoginGuard} from "./openaireLibrary/login/adminLoginGuard.guard";
|
import {AdminLoginGuard} from "./openaireLibrary/login/adminLoginGuard.guard";
|
||||||
import {HasConsentGuard} from "./shared/hasConsent.guard";
|
import {HasConsentGuard} from "./shared/hasConsent.guard";
|
||||||
import {LoginGuard} from "./openaireLibrary/login/loginGuard.guard";
|
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -40,7 +39,7 @@ const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'upload-dois',
|
path: 'upload-dois',
|
||||||
loadChildren: () => import('./upload-dois/upload-dois.module').then(m => m.UploadDoisModule),
|
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',
|
path: 'admin',
|
||||||
|
@ -50,13 +49,13 @@ const routes: Routes = [
|
||||||
},
|
},
|
||||||
{path: 'public-logs', loadChildren: () => import('./public-logs/public-logs.module').then(m => m.PublicLogsModule)},
|
{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: '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: '',
|
path: '',
|
||||||
loadChildren: () => import('./national/national.module').then(m => m.NationalModule)
|
loadChildren: () => import('./national/national.module').then(m => m.NationalModule)
|
||||||
},
|
},
|
||||||
{path: 'orcid', loadChildren: () => import('./orcid/orcid.module').then(m => m.LibOrcidModule), 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: [LoginGuard, HasConsentGuard]},
|
{path: 'my-orcid-links', loadChildren: () => import('./orcid/my-orcid-links/myOrcidLinks.module').then(m => m.LibMyOrcidLinksModule), canActivate: [HasConsentGuard]},
|
||||||
{path: 'error', component: ErrorPageComponent},
|
{path: 'error', component: ErrorPageComponent},
|
||||||
{path: '**', pathMatch: 'full', component: ErrorPageComponent}
|
{path: '**', pathMatch: 'full', component: ErrorPageComponent}
|
||||||
];
|
];
|
||||||
|
|
|
@ -5,8 +5,6 @@ import {SEOService} from '../openaireLibrary/sharedComponents/SEO/SEO.service';
|
||||||
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
||||||
import {Meta, Title} from '@angular/platform-browser';
|
import {Meta, Title} from '@angular/platform-browser';
|
||||||
import {LogService} from "../openaireLibrary/utils/log/log.service";
|
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({
|
@Component({
|
||||||
selector: 'public-logs',
|
selector: 'public-logs',
|
||||||
|
@ -90,8 +88,7 @@ export class PublicLogsComponent extends BaseComponent implements OnInit {
|
||||||
protected _piwikService: PiwikService,
|
protected _piwikService: PiwikService,
|
||||||
protected _title: Title,
|
protected _title: Title,
|
||||||
protected _meta: Meta,
|
protected _meta: Meta,
|
||||||
private _logService:LogService,
|
private _logService:LogService) {
|
||||||
private userManagementsService: UserManagementService, private cookieLawService: CookieLawService) {
|
|
||||||
super();
|
super();
|
||||||
this.startDate.setFullYear(2023,11,1)
|
this.startDate.setFullYear(2023,11,1)
|
||||||
this.months = Array.from({ length:12 }, (_, index) => 12 - index);
|
this.months = Array.from({ length:12 }, (_, index) => 12 - index);
|
||||||
|
|
|
@ -1,32 +1,48 @@
|
||||||
import {ActivatedRouteSnapshot, Route, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
import {ActivatedRouteSnapshot, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable, merge, forkJoin} from 'rxjs';
|
||||||
import {UserProfileService} from "../openaireLibrary/services/userProfile.service";
|
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 {Injectable} from "@angular/core";
|
||||||
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
||||||
|
import {LoginErrorCodes} from "../openaireLibrary/login/utils/guardHelper.class";
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class HasConsentGuard {
|
export class HasConsentGuard {
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
private _userProfileService: UserProfileService) {
|
private _userProfileService: UserProfileService,
|
||||||
|
private userManagementService: UserManagementService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
check(path: string): Observable<boolean> | boolean {
|
check(path: string): Observable<boolean> | boolean {
|
||||||
return this._userProfileService.getUserProfile().pipe(map(userProfile => {
|
return forkJoin([
|
||||||
return userProfile.consent;
|
this.userManagementService.getUserInfo().pipe(take(1)),
|
||||||
}),tap(hasConsent => {
|
this._userProfileService.getUserProfile().pipe(take(1))
|
||||||
if(!hasConsent) {
|
]).pipe(
|
||||||
this.router.navigate(['/user-policy'], {
|
map(([user, userProfile]) => {
|
||||||
queryParams: {
|
if (user) {
|
||||||
'redirectUrl': path
|
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<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
|
@ -36,8 +52,8 @@ export class HasConsentGuard {
|
||||||
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
|
||||||
return this.check(state.url);
|
return this.check(state.url);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||||
return this.check('/' + route.path);
|
return this.check('/' + route.path);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {UserProfileService} from "../openaireLibrary/services/userProfile.servic
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'user-policy',
|
selector: 'user-policy',
|
||||||
template: `
|
template: `
|
||||||
<div class="uk-container uk-container-large uk-margin-top">
|
<div *ngIf="!loading" class="uk-container uk-container-large uk-margin-top">
|
||||||
<h3>User Policy</h3>
|
<h3>User Policy</h3>
|
||||||
<div class="">
|
<div class="">
|
||||||
<div>
|
<div>
|
||||||
|
@ -22,7 +22,6 @@ import {UserProfileService} from "../openaireLibrary/services/userProfile.servic
|
||||||
<input type="checkbox" (change)="value = !value"> Accept policy</div>
|
<input type="checkbox" (change)="value = !value"> Accept policy</div>
|
||||||
<button class="uk-button uk-button-primary uk-margin-top" [class.uk-disabled]="!value" (click)="accept()"> Accept and proceed</button>
|
<button class="uk-button uk-button-primary uk-margin-top" [class.uk-disabled]="!value" (click)="accept()"> Accept and proceed</button>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,6 +33,7 @@ export class UserPolicyComponent extends BaseComponent implements OnInit {
|
||||||
hasConsent = false;
|
hasConsent = false;
|
||||||
value = false;
|
value = false;
|
||||||
redirectEnabled =true;
|
redirectEnabled =true;
|
||||||
|
loading = true;
|
||||||
constructor(protected _router: Router,
|
constructor(protected _router: Router,
|
||||||
protected _route: ActivatedRoute,
|
protected _route: ActivatedRoute,
|
||||||
protected seoService: SEOService,
|
protected seoService: SEOService,
|
||||||
|
@ -46,6 +46,7 @@ export class UserPolicyComponent extends BaseComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.loading = true;
|
||||||
this.title = 'User policy';
|
this.title = 'User policy';
|
||||||
this.description = 'OA Monitor Ireland - User policy';
|
this.description = 'OA Monitor Ireland - User policy';
|
||||||
this.setMetadata();
|
this.setMetadata();
|
||||||
|
@ -58,8 +59,10 @@ export class UserPolicyComponent extends BaseComponent implements OnInit {
|
||||||
if(this.hasConsent && this.redirectEnabled){
|
if(this.hasConsent && this.redirectEnabled){
|
||||||
this.redirect();
|
this.redirect();
|
||||||
}
|
}
|
||||||
|
this.loading = false;
|
||||||
}, error => {
|
}, error => {
|
||||||
this.hasConsent = false;
|
this.hasConsent = false;
|
||||||
|
this.loading = false;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
accept(){
|
accept(){
|
||||||
|
|
Loading…
Reference in New Issue