add log Action Guard, add consent view and proceed button

This commit is contained in:
argirok 2023-12-15 11:37:20 +02:00
parent 3c7c6cf6e0
commit feffa4282b
13 changed files with 128 additions and 34 deletions

View File

@ -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}

View File

@ -43,6 +43,15 @@ import {properties} from "../environments/environment";
points="7 4 13 10 7 16"></polyline></svg>
</span></a>-->
</cookie-law>
<!--<cookie-law *ngIf="isClient" position="top" cookieName="logActions-NOAMIreland">
National Open Access Monitor - Ireland, creates public logs for user actions.<br>
By using the National Open Access Monitor - Ireland portal you consent to log your actions <a
routerLink="/public-logs"> View Public logs <span class="uk-icon">
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
points="7 4 13 10 7 16"></polyline></svg>
</span></a>
</cookie-law>-->
`
})
export class AppComponent extends ResearcherBaseComponent implements OnInit {

View File

@ -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'}
}

@ -1 +1 @@
Subproject commit 704f52c9696180fd791562fba7aec0f859a3b5ad
Subproject commit c977bb0898e26fa3d3c32b6c533b2b3d5e37c439

View File

@ -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: `
<div class="uk-container uk-container-large uk-margin-top">
<h3>Public logs</h3>
<ng-container *ngIf="allLogs">
<ng-container *ngIf="!isConsent">
<ul class="uk-tab " uk-switcher>
<li><a href="#">Linking</a></li>
<li><a href="#">ORCID Claim</a></li>
@ -42,9 +44,23 @@ import {LogService} from "../openaireLibrary/utils/log/log.service";
</li>
</ul>
</ng-container>
<ng-container *ngIf="isConsent">
<div class="uk-alert uk-alert-warning">
National Open Access Monitor - Ireland, creates public logs for user actions.<br>
By using the National Open Access Monitor - Ireland portal you consent to log your actions <a
routerLink="/public-logs"> View Public logs <span class="uk-icon">
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="chevron-right"
ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.03"
points="7 4 13 10 7 16"></polyline></svg>
</span></a>
<button class="uk-button uk-button-primary" (click)="redirect()">Proceed</button>
</div>
</ng-container>
</div>
<ng-template #formattedLogs let-logs="logs">
<div class="uk-text-meta "> Viewing last {{logs.length}} actions.</div>
<div *ngIf="logs && logs.length > 0" class="uk-text-meta "> Viewing last {{logs.length}} actions.</div>
<div *ngIf="!logs || logs.length == 0" class="uk-text-meta "> No logs yet.</div>
<div *ngFor="let log of logs">
On {{log.date | date: 'd/M/yyyy, hh:mm':'GMT' }} {{log.message}}
</div>
@ -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,6 +91,11 @@ 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._route.queryParams.subscribe(params => {
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 = [];
@ -92,6 +116,17 @@ export class PublicLogsComponent extends BaseComponent implements OnInit {
}));
}
}));
}
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']);
}
}
}

View File

@ -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 { }

View File

@ -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)}
]
}

View File

@ -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]}
]
}
];

View File

@ -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)}
]
}

View File

@ -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)}
]
}

View File

@ -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<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.check(state.url);
}
canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.check(state.url);
}
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
return this.check('/' + route.path);
}
}

View File

@ -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,

View File

@ -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,