From feffa4282be9dde9562548a2d9429159621ebff5 Mon Sep 17 00:00:00 2001 From: argirok Date: Fri, 15 Dec 2023 11:37:20 +0200 Subject: [PATCH] add log Action Guard, add consent view and proceed button --- src/app/app-routing.module.ts | 10 ++- src/app/app.component.ts | 9 +++ src/app/national/national.module.ts | 3 +- src/app/openaireLibrary | 2 +- src/app/public-logs/public-logs.component.ts | 77 ++++++++++++++------ src/app/public-logs/public-logs.module.ts | 5 +- src/app/repository/repository.module.ts | 3 +- src/app/researcher/researcher.module.ts | 5 +- src/app/rfo/rfo.module.ts | 3 +- src/app/rpo/rpo.module.ts | 3 +- src/app/shared/logActions.guard.ts | 38 ++++++++++ src/environments/environment.beta.ts | 2 + src/environments/environment.prod.ts | 2 + 13 files changed, 128 insertions(+), 34 deletions(-) create mode 100644 src/app/shared/logActions.guard.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index fc04606..c491e6a 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -3,6 +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 {LoginGuard} from "./openaireLibrary/login/loginGuard.guard"; +import {LogActionsGuard} from "./shared/logActions.guard"; const routes: Routes = [ { @@ -38,7 +40,7 @@ const routes: Routes = [ { path: 'upload-dois', loadChildren: () => import('./upload-dois/upload-dois.module').then(m => m.UploadDoisModule), - data: {title: Irish.METADATA_PREFIX} + data: {title: Irish.METADATA_PREFIX}, canActivate: [LogActionsGuard] }, { path: 'admin', @@ -46,13 +48,13 @@ const routes: Routes = [ data: {title: Irish.METADATA_PREFIX + ' Admin | ', monitorCurator: true}, canActivateChild: [AdminLoginGuard] }, - {path: 'participate', loadChildren: () => import('./claims/claims.module').then(m => m.ClaimsModule)}, + {path: 'participate', loadChildren: () => import('./claims/claims.module').then(m => m.ClaimsModule), canActivate: [LogActionsGuard]}, { path: '', loadChildren: () => import('./national/national.module').then(m => m.NationalModule) }, - {path: 'orcid', loadChildren: () => import('./orcid/orcid.module').then(m => m.LibOrcidModule)}, - {path: 'my-orcid-links', loadChildren: () => import('./orcid/my-orcid-links/myOrcidLinks.module').then(m => m.LibMyOrcidLinksModule)}, + {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: 'error', component: ErrorPageComponent}, {path: '**', pathMatch: 'full', component: ErrorPageComponent} diff --git a/src/app/app.component.ts b/src/app/app.component.ts index abb15ba..7910610 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -43,6 +43,15 @@ import {properties} from "../environments/environment"; points="7 4 13 10 7 16"> --> + ` }) export class AppComponent extends ResearcherBaseComponent implements OnInit { diff --git a/src/app/national/national.module.ts b/src/app/national/national.module.ts index 822f62f..8ce0664 100644 --- a/src/app/national/national.module.ts +++ b/src/app/national/national.module.ts @@ -7,11 +7,12 @@ 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"}}, + {path: 'search', loadChildren: () => import('../search/search.module').then(m => m.SearchModule), data: {activeMenuItem: "national"}, canActivate: [LogActionsGuard]}, {path: '', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule), data: {activeMenuItem: "national"}}, ], data: {stakeholder: 'irish'} } diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index 704f52c..c977bb0 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit 704f52c9696180fd791562fba7aec0f859a3b5ad +Subproject commit c977bb0898e26fa3d3c32b6c533b2b3d5e37c439 diff --git a/src/app/public-logs/public-logs.component.ts b/src/app/public-logs/public-logs.component.ts index 027c245..8659c60 100644 --- a/src/app/public-logs/public-logs.component.ts +++ b/src/app/public-logs/public-logs.component.ts @@ -5,13 +5,15 @@ 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', template: `
-

Public logs

- +

Public logs

+ - +
+ +
+ National Open Access Monitor - Ireland, creates public logs for user actions.
+ By using the National Open Access Monitor - Ireland portal you consent to log your actions View Public logs + + + +
+
+
-
Viewing last {{logs.length}} actions.
+
Viewing last {{logs.length}} actions.
+
No logs yet.
On {{log.date | date: 'd/M/yyyy, hh:mm':'GMT' }} {{log.message}}
@@ -58,13 +74,16 @@ export class PublicLogsComponent extends BaseComponent implements OnInit { uploadDoisLogs; claimsLogs; orcidClaimsLogs; + isConsent = false; + redirectUrl = null; constructor(protected _router: Router, protected _route: ActivatedRoute, protected seoService: SEOService, protected _piwikService: PiwikService, protected _title: Title, protected _meta: Meta, - private _logService:LogService) { + private _logService:LogService, + private userManagementsService: UserManagementService, private cookieLawService: CookieLawService) { super(); } @@ -72,26 +91,42 @@ export class PublicLogsComponent extends BaseComponent implements OnInit { this.title = 'Public logs'; this.description = 'Public logs of user actions in OA monitor - Ireland'; this.setMetadata(); - this.subscriptions.push(this._logService.getLogs(this.properties).subscribe(logs => { - this.allLogs = logs.slice(logs.length -10 ,logs.length); - this.uploadDoisLogs = []; - this.claimsLogs = []; - this.orcidClaimsLogs = []; - for(let i=logs.length; i--; i==0){ - let log = logs[i]; - log.date = new Date(log.date); + this.subscriptions.push(this._route.queryParams.subscribe(params => { - if(log.action == 'upload-dois' && this.uploadDoisLogs.length <10){ - this.uploadDoisLogs.push(log); - }else if(log.action == 'link' && this.claimsLogs.length <10){ - this.claimsLogs.push(log); - } else if(log.action == 'orcid-link' && this.orcidClaimsLogs.length <10){ - this.orcidClaimsLogs.push(log); - } + this.isConsent = params && params['redirectUrl']; + this.redirectUrl = params['redirectUrl']; + if(!this.isConsent){ + this.subscriptions.push(this._logService.getLogs(this.properties).subscribe(logs => { + this.allLogs = logs.slice(logs.length -10 ,logs.length); + this.uploadDoisLogs = []; + this.claimsLogs = []; + this.orcidClaimsLogs = []; + for(let i=logs.length; i--; i==0){ + let log = logs[i]; + log.date = new Date(log.date); + + if(log.action == 'upload-dois' && this.uploadDoisLogs.length <10){ + this.uploadDoisLogs.push(log); + }else if(log.action == 'link' && this.claimsLogs.length <10){ + this.claimsLogs.push(log); + } else if(log.action == 'orcid-link' && this.orcidClaimsLogs.length <10){ + this.orcidClaimsLogs.push(log); + } + } + + })); } - })); } + redirect() { + //if parameters are not read yet, force them to use the function parameter + this.cookieLawService.storeCookie("logActions-NOAMIreland") + if (this.redirectUrl && this.redirectUrl != "") { + this.redirectUrl = decodeURIComponent(this.redirectUrl); + this.userManagementsService.setRedirectUrl(this.redirectUrl); + this._router.navigate(['/reload']); + } + } } diff --git a/src/app/public-logs/public-logs.module.ts b/src/app/public-logs/public-logs.module.ts index c99c621..8e6ae69 100644 --- a/src/app/public-logs/public-logs.module.ts +++ b/src/app/public-logs/public-logs.module.ts @@ -3,13 +3,14 @@ import {CommonModule} from '@angular/common'; import {PublicLogsComponent} from "./public-logs.component"; import {PublicLogsRoutingModule} from "./public-logs-routing.module"; import {LogServiceModule} from "../openaireLibrary/utils/log/LogService.module"; +import {RouterModule} from "@angular/router"; @NgModule({ declarations: [PublicLogsComponent], imports: [ - CommonModule, PublicLogsRoutingModule, LogServiceModule - + CommonModule, PublicLogsRoutingModule, LogServiceModule, RouterModule ], + exports: [PublicLogsComponent] }) export class PublicLogsModule { } diff --git a/src/app/repository/repository.module.ts b/src/app/repository/repository.module.ts index ab20215..ee28955 100644 --- a/src/app/repository/repository.module.ts +++ b/src/app/repository/repository.module.ts @@ -10,12 +10,13 @@ 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)}, + {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivate: [LogActionsGuard]}, {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)} ] } diff --git a/src/app/researcher/researcher.module.ts b/src/app/researcher/researcher.module.ts index da31580..ecb75aa 100644 --- a/src/app/researcher/researcher.module.ts +++ b/src/app/researcher/researcher.module.ts @@ -8,13 +8,14 @@ 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)}, - {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule)} + {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]} ] } ]; diff --git a/src/app/rfo/rfo.module.ts b/src/app/rfo/rfo.module.ts index 7c01cea..b484a1e 100644 --- a/src/app/rfo/rfo.module.ts +++ b/src/app/rfo/rfo.module.ts @@ -8,12 +8,13 @@ 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)}, + {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivate: [LogActionsGuard]}, {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)} ] } diff --git a/src/app/rpo/rpo.module.ts b/src/app/rpo/rpo.module.ts index 0cdced4..0205cac 100644 --- a/src/app/rpo/rpo.module.ts +++ b/src/app/rpo/rpo.module.ts @@ -8,12 +8,13 @@ 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)}, + {path: ':stakeholder/search', loadChildren: () => import('../search/resultLanding.module').then(m => m.ResultLandingModule), canActivate: [LogActionsGuard]}, {path: ':stakeholder', loadChildren: () => import('../shared/monitor/monitor.module').then(m => m.MonitorModule)} ] } diff --git a/src/app/shared/logActions.guard.ts b/src/app/shared/logActions.guard.ts new file mode 100644 index 0000000..b41bfcb --- /dev/null +++ b/src/app/shared/logActions.guard.ts @@ -0,0 +1,38 @@ +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"; + +@Injectable({ + providedIn: 'root' +}) +export class LogActionsGuard { + + constructor(private router: Router, + private cookieLawService: CookieLawService) { + } + + check(path: string): boolean { + let seen = this.cookieLawService.seen("logActions-NOAMIreland"); + if (!seen) { + this.router.navigate(['/public-logs'], { + queryParams: { + 'redirectUrl': path + } + }); + } + return seen; + } + + canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { + return this.check(state.url); + } + + 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/environments/environment.beta.ts b/src/environments/environment.beta.ts index c9744d0..0c5cc16 100644 --- a/src/environments/environment.beta.ts +++ b/src/environments/environment.beta.ts @@ -2,6 +2,8 @@ import {EnvProperties} from "../app/openaireLibrary/utils/properties/env-propert import {common, commonBeta} from "../app/openaireLibrary/utils/properties/environments/environment"; let props: EnvProperties = { + monitorServiceAPIURL: "https://beta.services.openaire.eu/irish-monitor-service/", + monitorStatsFrameUrl:"https://beta.services.openaire.eu/stats-tool/", piwikSiteId: "786", enablePiwikTrack: true, diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 56a2ddc..a113843 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -2,6 +2,8 @@ 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/", + monitorStatsFrameUrl:"https://beta.services.openaire.eu/stats-tool/", piwikSiteId: "787", enablePiwikTrack: true,