mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-6565] LYRASIS7: Cookie consent shows analytics usage also when GA is disabled
This commit is contained in:
@@ -11,8 +11,13 @@ import { CookieService } from '../../core/services/cookie.service';
|
|||||||
import { getTestScheduler } from 'jasmine-marbles';
|
import { getTestScheduler } from 'jasmine-marbles';
|
||||||
import { MetadataValue } from '../../core/shared/metadata.models';
|
import { MetadataValue } from '../../core/shared/metadata.models';
|
||||||
import { cloneDeep } from 'lodash';
|
import { cloneDeep } from 'lodash';
|
||||||
|
import { ConfigurationDataService } from '../../core/data/configuration-data.service';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
|
||||||
|
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
|
||||||
|
|
||||||
describe('BrowserKlaroService', () => {
|
describe('BrowserKlaroService', () => {
|
||||||
|
const trackingIdProp = 'google.analytics.key';
|
||||||
|
const trackingIdTestValue = 'mock-tracking-id';
|
||||||
let translateService;
|
let translateService;
|
||||||
let ePersonService;
|
let ePersonService;
|
||||||
let authService;
|
let authService;
|
||||||
@@ -20,6 +25,14 @@ describe('BrowserKlaroService', () => {
|
|||||||
|
|
||||||
let user;
|
let user;
|
||||||
let service: BrowserKlaroService;
|
let service: BrowserKlaroService;
|
||||||
|
let configurationDataService: ConfigurationDataService;
|
||||||
|
const createConfigSuccessSpy = (...values: string[]) => jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$({
|
||||||
|
... new ConfigurationProperty(),
|
||||||
|
name: trackingIdProp,
|
||||||
|
values: values,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
let mockConfig;
|
let mockConfig;
|
||||||
let appName;
|
let appName;
|
||||||
@@ -38,6 +51,7 @@ describe('BrowserKlaroService', () => {
|
|||||||
isAuthenticated: observableOf(true),
|
isAuthenticated: observableOf(true),
|
||||||
getAuthenticatedUserFromStore: observableOf(user)
|
getAuthenticatedUserFromStore: observableOf(user)
|
||||||
});
|
});
|
||||||
|
configurationDataService = createConfigSuccessSpy(trackingIdTestValue);
|
||||||
cookieService = jasmine.createSpyObj('cookieService', {
|
cookieService = jasmine.createSpyObj('cookieService', {
|
||||||
get: '{%22token_item%22:true%2C%22impersonation%22:true%2C%22redirect%22:true%2C%22language%22:true%2C%22klaro%22:true%2C%22has_agreed_end_user%22:true%2C%22google-analytics%22:true}',
|
get: '{%22token_item%22:true%2C%22impersonation%22:true%2C%22redirect%22:true%2C%22language%22:true%2C%22klaro%22:true%2C%22has_agreed_end_user%22:true%2C%22google-analytics%22:true}',
|
||||||
set: () => {
|
set: () => {
|
||||||
@@ -63,6 +77,10 @@ describe('BrowserKlaroService', () => {
|
|||||||
{
|
{
|
||||||
provide: CookieService,
|
provide: CookieService,
|
||||||
useValue: cookieService
|
useValue: cookieService
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: ConfigurationDataService,
|
||||||
|
useValue: configurationDataService
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@@ -4,7 +4,7 @@ import { combineLatest as observableCombineLatest, Observable, of as observableO
|
|||||||
import { AuthService } from '../../core/auth/auth.service';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../../environments/environment';
|
||||||
import { switchMap, take } from 'rxjs/operators';
|
import { catchError, switchMap, take } from 'rxjs/operators';
|
||||||
import { EPerson } from '../../core/eperson/models/eperson.model';
|
import { EPerson } from '../../core/eperson/models/eperson.model';
|
||||||
import { KlaroService } from './klaro.service';
|
import { KlaroService } from './klaro.service';
|
||||||
import { hasValue, isNotEmpty } from '../empty.util';
|
import { hasValue, isNotEmpty } from '../empty.util';
|
||||||
@@ -13,6 +13,8 @@ import { EPersonDataService } from '../../core/eperson/eperson-data.service';
|
|||||||
import { cloneDeep, debounce } from 'lodash';
|
import { cloneDeep, debounce } 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';
|
||||||
|
import { getFirstCompletedRemoteData } from 'src/app/core/shared/operators';
|
||||||
|
import { ConfigurationDataService } from 'src/app/core/data/configuration-data.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metadata field to store a user's cookie consent preferences in
|
* Metadata field to store a user's cookie consent preferences in
|
||||||
@@ -52,6 +54,7 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
private translateService: TranslateService,
|
private translateService: TranslateService,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private ePersonService: EPersonDataService,
|
private ePersonService: EPersonDataService,
|
||||||
|
private configService: ConfigurationDataService,
|
||||||
private cookieService: CookieService) {
|
private cookieService: CookieService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -63,6 +66,15 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
* - Add and translate klaro configuration messages
|
* - Add and translate klaro configuration messages
|
||||||
*/
|
*/
|
||||||
initialize() {
|
initialize() {
|
||||||
|
this.configService.findByPropertyName('google.analytics.key').pipe(
|
||||||
|
getFirstCompletedRemoteData(),
|
||||||
|
catchError(this.removeGoogleAnalytics())
|
||||||
|
).subscribe((remoteData) => {
|
||||||
|
// make sure we got a success response from the backend
|
||||||
|
if (!remoteData.hasSucceeded) {
|
||||||
|
this.removeGoogleAnalytics();
|
||||||
|
}
|
||||||
|
});
|
||||||
this.translateService.setDefaultLang(environment.defaultLanguage);
|
this.translateService.setDefaultLang(environment.defaultLanguage);
|
||||||
|
|
||||||
const user$: Observable<EPerson> = this.getUser$();
|
const user$: Observable<EPerson> = this.getUser$();
|
||||||
@@ -253,4 +265,12 @@ export class BrowserKlaroService extends KlaroService {
|
|||||||
getStorageName(identifier: string) {
|
getStorageName(identifier: string) {
|
||||||
return 'klaro-' + identifier;
|
return 'klaro-' + identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove the google analytics from the services
|
||||||
|
*/
|
||||||
|
removeGoogleAnalytics() {
|
||||||
|
this.klaroConfig.services = klaroConfiguration.services.filter(config => config.name !== 'google-analytics');
|
||||||
|
return this.klaroConfig.services;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user