Add hasConsentGuard, add it in routes, add user policy page, remove previously committed LogActionsGuard

This commit is contained in:
argirok 2023-12-19 17:23:59 +02:00
parent 278d3cf74f
commit 401ddaa0ce
12 changed files with 43 additions and 36 deletions

View File

@ -3,8 +3,8 @@ import { RouterModule, Routes } from '@angular/router';
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";
import {LogActionsGuard} from "./shared/logActions.guard";
const routes: Routes = [
{
@ -40,22 +40,23 @@ const routes: Routes = [
{
path: 'upload-dois',
loadChildren: () => import('./upload-dois/upload-dois.module').then(m => m.UploadDoisModule),
data: {title: Irish.METADATA_PREFIX}, canActivate: [LogActionsGuard]
data: {title: Irish.METADATA_PREFIX}, canActivate: [LoginGuard, HasConsentGuard]
},
{
path: 'admin',
loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule),
data: {title: Irish.METADATA_PREFIX + ' Admin | ', monitorCurator: true},
canActivateChild: [AdminLoginGuard]
canActivateChild: [AdminLoginGuard, HasConsentGuard]
},
{path: 'participate', loadChildren: () => import('./claims/claims.module').then(m => m.ClaimsModule), canActivate: [LogActionsGuard]},
{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: '',
loadChildren: () => import('./national/national.module').then(m => m.NationalModule)
},
{path: 'orcid', loadChildren: () => import('./orcid/orcid.module').then(m => m.LibOrcidModule), canActivate: [LogActionsGuard]},
{path: 'my-orcid-links', loadChildren: () => import('./orcid/my-orcid-links/myOrcidLinks.module').then(m => m.LibMyOrcidLinksModule), canActivate: [LogActionsGuard]},
{path: 'public-logs', loadChildren: () => import('./public-logs/public-logs.module').then(m => m.PublicLogsModule)},
{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: 'error', component: ErrorPageComponent},
{path: '**', pathMatch: 'full', component: ErrorPageComponent}
];

View File

@ -8,13 +8,10 @@ import {CustomFilterService} from "./openaireLibrary/shared/customFilter.service
import {UserManagementService} from "./openaireLibrary/services/user-management.service";
import {Session, User} from "./openaireLibrary/login/utils/helper.class";
import {SmoothScroll} from "./openaireLibrary/utils/smooth-scroll";
import {StakeholderBaseComponent} from "./openaireLibrary/monitor-admin/utils/stakeholder-base.component";
import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
import {StakeholderUtils} from "./openaireLibrary/monitor-admin/utils/indicator-utils";
import {ResearcherBaseComponent} from "./shared/researcher-base.component";
import {SearchOrcidService} from "./openaireLibrary/claims/claim-utils/service/searchOrcid.service";
import {SearchResearchResultsService} from "./openaireLibrary/services/searchResearchResults.service";
import {properties} from "../environments/environment";
import {UserProfileService} from "./openaireLibrary/services/userProfile.service";
@Component({
selector: 'app-root',
@ -76,13 +73,12 @@ export class AppComponent extends ResearcherBaseComponent implements OnInit {
constructor(protected _route: ActivatedRoute,
protected _router: Router,
protected cdr: ChangeDetectorRef,
protected _searchOrcidService: SearchOrcidService,
protected _searchResearchResultsService: SearchResearchResultsService,
private layoutService: LayoutService,
private smoothScroll: SmoothScroll,
private configurationService: ConfigurationService,
private customFilterService: CustomFilterService,
private userManagementService: UserManagementService,
private userProfileService:UserProfileService
) {
super();
this.configurationService.initStaticPortal(this.irish.portal);
@ -93,11 +89,17 @@ export class AppComponent extends ResearcherBaseComponent implements OnInit {
this.customFilterService.clearSubscriptions();
this.configurationService.clearSubscriptions();
this.smoothScroll.clearSubscriptions();
this.userProfileService.clearSubscriptions();
}
ngOnInit() {
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
if(user){
this.userProfileService.initUserProfile()
}else{
this.userProfileService.setUserProfile(null);
}
this.initialize();
}));
this.subscriptions.push(this.layoutService.rootClass.subscribe(rootClass => {

View File

@ -7,12 +7,11 @@ import {RoleVerificationModule} from "../openaireLibrary/role-verification/role-
import {IconsModule} from "../openaireLibrary/utils/icons/icons.module";
import {IconsService} from "../openaireLibrary/utils/icons/icons.service";
import {open_access} from "../openaireLibrary/utils/icons/icons";
import {LogActionsGuard} from "../shared/logActions.guard";
const routes: Route[] = [
{
path: '', component: NationalComponent, children: [
{path: 'search', loadChildren: () => import('../search/search.module').then(m => m.SearchModule), data: {activeMenuItem: "national"}, canActivate: [LogActionsGuard]},
{path: 'search', loadChildren: () => import('../search/search.module').then(m => m.SearchModule), data: {activeMenuItem: "national"}},
{path: '', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), data: {activeMenuItem: "national"}},
], data: {stakeholder: 'irish'}
}

View File

@ -10,13 +10,12 @@ import {EntityMetadataModule} from "../openaireLibrary/landingPages/landing-util
import {IconsService} from "../openaireLibrary/utils/icons/icons.service";
import {open_access} from "../openaireLibrary/utils/icons/icons";
import {LogoUrlPipeModule} from "../openaireLibrary/utils/pipes/logoUrlPipe.module";
import {LogActionsGuard} from "../shared/logActions.guard";
const routes: Route[] = [
{
path: '', component: RepositoryComponent, children: [
{path: '', loadChildren: () => import('./browse-repositories/browse-repositories.module').then(m => m.BrowseRepositoriesModule)},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivate: [LogActionsGuard]},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)},
{path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)}
]
}

View File

@ -8,14 +8,13 @@ import {LoadingModule} from "../openaireLibrary/utils/loading/loading.module";
import {IconsModule} from '../openaireLibrary/utils/icons/icons.module';
import {IconsService} from '../openaireLibrary/utils/icons/icons.service';
import {open_access} from '../openaireLibrary/utils/icons/icons';
import {LogActionsGuard} from "../shared/logActions.guard";
const routes: Route[] = [
{
path: '', component: ResearcherComponent, children: [
{path: '', loadChildren: () => import('./search-researcher/search-researcher.module').then(m => m.SearchResearcherModule)},
{path: ':stakeholder', loadChildren: () => import('./author/author.module').then(m => m.AuthorModule), canActivate: [LogActionsGuard]},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivate: [LogActionsGuard]}
{path: ':stakeholder', loadChildren: () => import('./author/author.module').then(m => m.AuthorModule)},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)}
]
}
];

View File

@ -8,13 +8,12 @@ import {IconsModule} from "../openaireLibrary/utils/icons/icons.module";
import {LogoUrlPipeModule} from "../openaireLibrary/utils/pipes/logoUrlPipe.module";
import {IconsService} from "../openaireLibrary/utils/icons/icons.service";
import {open_access} from "../openaireLibrary/utils/icons/icons";
import {LogActionsGuard} from "../shared/logActions.guard";
const routes: Route[] = [
{
path: '', component: RfoComponent, children: [
{path: '', loadChildren: () => import('../shared/browse-stakeholders/browse-stakeholders.module').then(m => m.BrowseStakeholdersModule)},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivate: [LogActionsGuard]},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)},
{path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)}
]
}

View File

@ -8,13 +8,12 @@ import {IconsModule} from "../openaireLibrary/utils/icons/icons.module";
import {LogoUrlPipeModule} from "../openaireLibrary/utils/pipes/logoUrlPipe.module";
import {IconsService} from "../openaireLibrary/utils/icons/icons.service";
import {open_access} from "../openaireLibrary/utils/icons/icons";
import {LogActionsGuard} from "../shared/logActions.guard";
const routes: Route[] = [
{
path: '', component: RpoComponent, children: [
{path: '', loadChildren: () => import('../shared/browse-stakeholders/browse-stakeholders.module').then(m => m.BrowseStakeholdersModule)},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivate: [LogActionsGuard]},
{path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)},
{path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)}
]
}

View File

@ -1,27 +1,32 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Route, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
import {Observable} from 'rxjs';
import {CookieLawService} from "../openaireLibrary/sharedComponents/cookie-law/cookie-law.service";
import {UserProfileService} from "../openaireLibrary/services/userProfile.service";
import {map, tap} from "rxjs/operators";
import {Injectable} from "@angular/core";
@Injectable({
providedIn: 'root'
})
export class LogActionsGuard {
export class HasConsentGuard {
constructor(private router: Router,
private cookieLawService: CookieLawService) {
private _userProfileService: UserProfileService) {
}
check(path: string): boolean {
let seen = this.cookieLawService.seen("logActions-NOAMIreland");
if (!seen) {
this.router.navigate(['/public-logs'], {
check(path: string): Observable<boolean> | boolean {
return this._userProfileService.getUserProfile().pipe(map(userProfile => {
return userProfile.consent;
}),tap(hasConsent => {
if(!hasConsent) {
this.router.navigate(['/user-policy'], {
queryParams: {
'redirectUrl': path
}
});
}
return seen;
}));
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {

View File

@ -12,7 +12,8 @@ let props: EnvProperties = {
domain: "https://beta.oamonitor.ireland.openaire.eu",
logServiceUrl: "https://beta.oamonitor.ireland.openaire.eu/",
logFilesPath: "/srv/nodejs/irish-monitor-action-logs/",
myClaimsLink:"/participate/myclaims"
myClaimsLink:"/participate/myclaims",
afterLoginRedirectLink: "/user-policy"
}
export let properties: EnvProperties = {

View File

@ -2,7 +2,7 @@ import {EnvProperties} from "../app/openaireLibrary/utils/properties/env-propert
import {common, commonProd} from "../app/openaireLibrary/utils/properties/environments/environment";
let props: EnvProperties = {
monitorServiceAPIURL: "https://beta.services.openaire.eu/irish-monitor-service/",
monitorServiceAPIURL: "https://services.openaire.eu/irish-monitor-service/",
monitorStatsFrameUrl:"https://beta.services.openaire.eu/stats-tool/",
piwikSiteId: "787",
enablePiwikTrack: true,
@ -12,7 +12,8 @@ let props: EnvProperties = {
domain: "https://oamonitor.ireland.openaire.eu",
logServiceUrl: "https://oamonitor.ireland.openaire.eu/",
logFilesPath: "/srv/static/nodejs/irish-monitor-action-logs/",
myClaimsLink:"/participate/myclaims"
myClaimsLink:"/participate/myclaims",
afterLoginRedirectLink: "/user-policy"
}

View File

@ -25,6 +25,8 @@ let props: EnvProperties = {
loginUrl: ["http://duffy.di.uoa.gr:19780/irish-monitor-service/openid_connect_login", <string>commonDev.loginUrl],
userInfoUrl: "http://duffy.di.uoa.gr:19780/irish-monitor-service/userInfo",
logoutUrl: ["http://duffy.di.uoa.gr:19780/irish-monitor-service/openid_logout", <string>commonDev.logoutUrl],
afterLoginRedirectLink: "/user-policy"
}
export let properties: EnvProperties = {