From e9938bc61d58a79a90e76b11fae615191dd91bd5 Mon Sep 17 00:00:00 2001 From: argirok Date: Tue, 19 Dec 2023 17:20:01 +0200 Subject: [PATCH] [angular-16-irish-monitor | DONE | CHANGED] UserProfile service: update initialize method - not initialize in constructor --- src/app/app.module.ts | 5 +- src/app/openaireLibrary | 2 +- src/app/user-policy/user-policy.component.ts | 87 ++++++++++++++++++++ src/app/user-policy/user-policy.module.ts | 21 +++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/app/user-policy/user-policy.component.ts create mode 100644 src/app/user-policy/user-policy.module.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index cb3c8f3..783fd71 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -16,6 +16,8 @@ import {ErrorModule} from "./openaireLibrary/error/error.module"; import {CookieLawModule} from "./openaireLibrary/sharedComponents/cookie-law/cookie-law.module"; import {SearchResearchResultsServiceModule} from "./openaireLibrary/services/searchResearchResultsService.module"; import {SearchOrcidService} from "./openaireLibrary/claims/claim-utils/service/searchOrcid.service"; +import {LoginGuard} from "./openaireLibrary/login/loginGuard.guard"; +import {HasConsentGuard} from "./shared/hasConsent.guard"; @NgModule({ declarations: [ @@ -48,7 +50,8 @@ import {SearchOrcidService} from "./openaireLibrary/claims/claim-utils/service/s multi: true }, [{provide: HTTP_INTERCEPTORS, useClass: TimeoutInterceptor, multi: true}], - [{provide: DEFAULT_TIMEOUT, useValue: 30000}] + [{provide: DEFAULT_TIMEOUT, useValue: 30000}], + ], bootstrap: [AppComponent] }) diff --git a/src/app/openaireLibrary b/src/app/openaireLibrary index 48ce09e..c6dd26d 160000 --- a/src/app/openaireLibrary +++ b/src/app/openaireLibrary @@ -1 +1 @@ -Subproject commit 48ce09e400ba9aa3f278aa23a89fd6dd7120b3a1 +Subproject commit c6dd26dcee5de3ccb19299a03f3866ac36e70831 diff --git a/src/app/user-policy/user-policy.component.ts b/src/app/user-policy/user-policy.component.ts new file mode 100644 index 0000000..2c288d2 --- /dev/null +++ b/src/app/user-policy/user-policy.component.ts @@ -0,0 +1,87 @@ +import {Component, OnInit} from '@angular/core'; +import {BaseComponent} from '../openaireLibrary/sharedComponents/base/base.component'; +import {ActivatedRoute, Router} from '@angular/router'; +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 {UserProfileService} from "../openaireLibrary/services/userProfile.service"; + +@Component({ + selector: 'user-policy', + template: ` +
+

User Policy

+
+
+ National Open Access Monitor - Ireland requires users to accept user privacy policy, to proceed with certain actions.
+ Please read the user privacy policy. +
+
+ Accept policy
+ + + +
+ +
+ + ` +}) +export class UserPolicyComponent extends BaseComponent implements OnInit { + redirectUrl = null; + hasConsent = false; + value = false; + redirectEnabled =true; + constructor(protected _router: Router, + protected _route: ActivatedRoute, + protected seoService: SEOService, + protected _piwikService: PiwikService, + protected _title: Title, + protected _meta: Meta, + private _logService:LogService, + private userManagementsService: UserManagementService, private _userProfileService: UserProfileService) { + super(); + } + + ngOnInit() { + this.title = 'User policy'; + this.description = 'OA Monitor Ireland - User policy'; + this.setMetadata(); + this.subscriptions.push(this._route.queryParams.subscribe(params => { + this.redirectUrl = params['redirectUrl']; + this.redirectEnabled = params['redirect'] == 'false'?false:true; + })); + this.subscriptions.push(this._userProfileService.getUserProfile().subscribe(userProfile => { + this.hasConsent = userProfile.consent; + if(this.hasConsent && this.redirectEnabled){ + this.redirect(); + } + }, error => { + this.hasConsent = false; + })); + } + accept(){ + this.subscriptions.push(this._userProfileService.saveConsentInUserProfile(this.properties).subscribe(userProfile => { + this._userProfileService.setUserProfile(userProfile); + this.redirect(); + })); + } + undo(){ + this.subscriptions.push(this._userProfileService.undoConsentInUserProfile(this.properties).subscribe(userProfile => { + this._userProfileService.setUserProfile(userProfile); + })); + } + redirect() { + //if parameters are not read yet, force them to use the function parameter + if (this.redirectUrl && this.redirectUrl != "") { + this.redirectUrl = decodeURIComponent(this.redirectUrl); + this.userManagementsService.setRedirectUrl(this.redirectUrl); + this._router.navigate(['/reload']); + }else{ + this._router.navigate(['/']); + } + } + +} diff --git a/src/app/user-policy/user-policy.module.ts b/src/app/user-policy/user-policy.module.ts new file mode 100644 index 0000000..cc95319 --- /dev/null +++ b/src/app/user-policy/user-policy.module.ts @@ -0,0 +1,21 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {UserPolicyComponent} from "./user-policy.component"; +import {LogServiceModule} from "../openaireLibrary/utils/log/LogService.module"; +import {Route, RouterModule} from "@angular/router"; + +const routes: Route[] = [ + { + path: '', component: UserPolicyComponent + } +]; + + +@NgModule({ + declarations: [UserPolicyComponent], + imports: [ + CommonModule, RouterModule.forChild(routes), LogServiceModule, RouterModule + ], + exports: [UserPolicyComponent] +}) +export class UserPolicyModule { }