mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
added missing typedoc
This commit is contained in:
@@ -14,15 +14,39 @@ import { cloneDeep } from 'lodash';
|
|||||||
import { ANONYMOUS_STORAGE_NAME_KLARO, klaroConfiguration } from './klaro-configuration';
|
import { ANONYMOUS_STORAGE_NAME_KLARO, klaroConfiguration } from './klaro-configuration';
|
||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cookie for has_agreed_end_user
|
||||||
|
*/
|
||||||
export const HAS_AGREED_END_USER = 'dsHasAgreedEndUser';
|
export const HAS_AGREED_END_USER = 'dsHasAgreedEndUser';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata field to store a user's cookie consent preferences in
|
||||||
|
*/
|
||||||
export const COOKIE_MDFIELD = 'dspace.agreements.cookies';
|
export const COOKIE_MDFIELD = 'dspace.agreements.cookies';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prefix key for app title messages
|
||||||
|
*/
|
||||||
const cookieNameMessagePrefix = 'cookies.consent.app.title.';
|
const cookieNameMessagePrefix = 'cookies.consent.app.title.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prefix key for app description messages
|
||||||
|
*/
|
||||||
const cookieDescriptionMessagePrefix = 'cookies.consent.app.description.';
|
const cookieDescriptionMessagePrefix = 'cookies.consent.app.description.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prefix key for app purpose messages
|
||||||
|
*/
|
||||||
const cookiePurposeMessagePrefix = 'cookies.consent.purpose.';
|
const cookiePurposeMessagePrefix = 'cookies.consent.purpose.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Browser implementation for the KlaroService, representing a service for handling Klaro consent preferences and UI
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BrowserKlaroService extends KlaroService {
|
export class BrowserKlaroService extends KlaroService {
|
||||||
|
/**
|
||||||
|
* Initial Klaro configuration
|
||||||
|
*/
|
||||||
klaroConfig = klaroConfiguration;
|
klaroConfig = klaroConfiguration;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -32,9 +56,14 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
private cookieService: CookieService) {
|
private cookieService: CookieService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Initializes the service:
|
||||||
|
* - Retrieves the current authenticated user
|
||||||
|
* - Checks if the translation service is ready
|
||||||
|
* - Initialize configuration for users
|
||||||
|
* - Add and translate klaro configuration messages
|
||||||
|
*/
|
||||||
initialize() {
|
initialize() {
|
||||||
console.log(this.klaroConfig)
|
|
||||||
this.translateService.setDefaultLang(environment.defaultLanguage);
|
this.translateService.setDefaultLang(environment.defaultLanguage);
|
||||||
|
|
||||||
const user$: Observable<EPerson> = this.getUser$();
|
const user$: Observable<EPerson> = this.getUser$();
|
||||||
@@ -66,6 +95,10 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize configuration for the logged in user
|
||||||
|
* @param user The authenticated user
|
||||||
|
*/
|
||||||
private initializeUser(user: EPerson) {
|
private initializeUser(user: EPerson) {
|
||||||
this.klaroConfig.callback = (consent, app) => this.updateSettingsForUsers(user);
|
this.klaroConfig.callback = (consent, app) => this.updateSettingsForUsers(user);
|
||||||
this.klaroConfig.storageName = this.getStorageName(user.uuid);
|
this.klaroConfig.storageName = this.getStorageName(user.uuid);
|
||||||
@@ -79,6 +112,10 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the currently logged in user
|
||||||
|
* Returns undefined when no one is logged in
|
||||||
|
*/
|
||||||
private getUser$() {
|
private getUser$() {
|
||||||
return this.authService.isAuthenticated()
|
return this.authService.isAuthenticated()
|
||||||
.pipe(
|
.pipe(
|
||||||
@@ -93,14 +130,26 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a title translation key
|
||||||
|
* @param title
|
||||||
|
*/
|
||||||
private getTitleTranslation(title: string) {
|
private getTitleTranslation(title: string) {
|
||||||
return cookieNameMessagePrefix + title;
|
return cookieNameMessagePrefix + title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a description translation key
|
||||||
|
* @param description
|
||||||
|
*/
|
||||||
private getDescriptionTranslation(description: string) {
|
private getDescriptionTranslation(description: string) {
|
||||||
return cookieDescriptionMessagePrefix + description;
|
return cookieDescriptionMessagePrefix + description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a purpose translation key
|
||||||
|
* @param purpose
|
||||||
|
*/
|
||||||
private getPurposeTranslation(purpose: string) {
|
private getPurposeTranslation(purpose: string) {
|
||||||
return cookiePurposeMessagePrefix + purpose;
|
return cookiePurposeMessagePrefix + purpose;
|
||||||
}
|
}
|
||||||
@@ -136,6 +185,10 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
this.translate(this.klaroConfig.translations.en);
|
this.translate(this.klaroConfig.translations.en);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate string values in an object
|
||||||
|
* @param object The object containing translation keys
|
||||||
|
*/
|
||||||
private translate(object) {
|
private translate(object) {
|
||||||
if (typeof (object) === 'string') {
|
if (typeof (object) === 'string') {
|
||||||
return this.translateService.instant(object);
|
return this.translateService.instant(object);
|
||||||
@@ -146,11 +199,20 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the stored Klaro consent settings for a user
|
||||||
|
* @param user The user to resolve the consent for
|
||||||
|
*/
|
||||||
getSettingsForUser(user: EPerson) {
|
getSettingsForUser(user: EPerson) {
|
||||||
const mdValue = user.firstMetadataValue(COOKIE_MDFIELD);
|
const mdValue = user.firstMetadataValue(COOKIE_MDFIELD);
|
||||||
return hasValue(mdValue) ? JSON.parse(mdValue) : undefined;
|
return hasValue(mdValue) ? JSON.parse(mdValue) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the Klaro consent settings for a user in a metadata field
|
||||||
|
* @param user The user to save the settings for
|
||||||
|
* @param config The consent settings for the user to save
|
||||||
|
*/
|
||||||
setSettingsForUser(user: EPerson, config: object) {
|
setSettingsForUser(user: EPerson, config: object) {
|
||||||
user.setMetadata(COOKIE_MDFIELD, undefined, JSON.stringify(config));
|
user.setMetadata(COOKIE_MDFIELD, undefined, JSON.stringify(config));
|
||||||
this.ePersonService.createPatchFromCache(user)
|
this.ePersonService.createPatchFromCache(user)
|
||||||
@@ -166,14 +228,26 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
).subscribe();
|
).subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores the users consent settings cookie based on the user's stored consent settings
|
||||||
|
* @param user The user to save the settings for
|
||||||
|
*/
|
||||||
restoreSettingsForUsers(user: EPerson) {
|
restoreSettingsForUsers(user: EPerson) {
|
||||||
this.cookieService.set(this.getStorageName(user.uuid), this.getSettingsForUser(user));
|
this.cookieService.set(this.getStorageName(user.uuid), this.getSettingsForUser(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the consent settings for a user based on the current cookie for this user
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
updateSettingsForUsers(user: EPerson) {
|
updateSettingsForUsers(user: EPerson) {
|
||||||
this.setSettingsForUser(user, this.cookieService.get(this.getStorageName(user.uuid)))
|
this.setSettingsForUser(user, this.cookieService.get(this.getStorageName(user.uuid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the storage name for klaro cookies based on the user's identifier
|
||||||
|
* @param identifier The user's uuid
|
||||||
|
*/
|
||||||
getStorageName(identifier: string) {
|
getStorageName(identifier: string) {
|
||||||
return 'klaro-' + identifier
|
return 'klaro-' + identifier
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,15 @@ import { IMPERSONATING_COOKIE, REDIRECT_COOKIE } from '../../core/auth/auth.serv
|
|||||||
import { LANG_COOKIE } from '../../core/locale/locale.service';
|
import { LANG_COOKIE } from '../../core/locale/locale.service';
|
||||||
import { HAS_AGREED_END_USER } from './browser-klaro.service';
|
import { HAS_AGREED_END_USER } from './browser-klaro.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage name used to store klaro cookie
|
||||||
|
*/
|
||||||
export const ANONYMOUS_STORAGE_NAME_KLARO = 'klaro-anonymous';
|
export const ANONYMOUS_STORAGE_NAME_KLARO = 'klaro-anonymous';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Klaro configuration
|
||||||
|
* For more information see https://kiprotect.com/docs/klaro/annotated-config
|
||||||
|
*/
|
||||||
export const klaroConfiguration: any = {
|
export const klaroConfiguration: any = {
|
||||||
storageName: ANONYMOUS_STORAGE_NAME_KLARO,
|
storageName: ANONYMOUS_STORAGE_NAME_KLARO,
|
||||||
|
|
||||||
|
@@ -1,7 +1,17 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class representing a service for handling Klaro consent preferences and UI
|
||||||
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export abstract class KlaroService {
|
export abstract class KlaroService {
|
||||||
|
/**
|
||||||
|
* Initializes the service
|
||||||
|
*/
|
||||||
abstract initialize();
|
abstract initialize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a the dialog with the current consent preferences
|
||||||
|
*/
|
||||||
abstract showSettings();
|
abstract showSettings();
|
||||||
}
|
}
|
||||||
|
@@ -990,7 +990,7 @@
|
|||||||
|
|
||||||
"cookies.consent.app.title.google-analytics": "Google Analytics",
|
"cookies.consent.app.title.google-analytics": "Google Analytics",
|
||||||
|
|
||||||
"cookies.consent.app.description.google-analytics": "Required for storing statistical data",
|
"cookies.consent.app.description.google-analytics": "Allows us to track statistical data",
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user