diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 04c5996740..7178cf97f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,6 +29,8 @@ jobs: DSPACE_CACHE_SERVERSIDE_ANONYMOUSCACHE_MAX: 0 # Tell Cypress to run e2e tests using the same UI URL CYPRESS_BASE_URL: http://127.0.0.1:4000 + # Disable the cookie consent banner in e2e tests to avoid errors because of elements hidden by it + DSPACE_INFO_ENABLECOOKIECONSENTPOPUP: false # When Chrome version is specified, we pin to a specific version of Chrome # Comment this out to use the latest release #CHROME_VERSION: "90.0.4430.212-1" diff --git a/angular.json b/angular.json index 37e53376b1..4b95be5512 100644 --- a/angular.json +++ b/angular.json @@ -105,37 +105,6 @@ "maximumError": "300kb" } ] - }, - "production-e2e": { - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.production-e2e.ts" - }, - { - "replace": "src/config/store/devtools.ts", - "with": "src/config/store/devtools.prod.ts" - } - ], - "optimization": true, - "outputHashing": "all", - "namedChunks": false, - "aot": true, - "extractLicenses": true, - "vendorChunk": false, - "buildOptimizer": true, - "budgets": [ - { - "type": "initial", - "maximumWarning": "3mb", - "maximumError": "5mb" - }, - { - "type": "anyComponentStyle", - "maximumWarning": "200kb", - "maximumError": "300kb" - } - ] } } }, @@ -151,9 +120,6 @@ }, "production": { "buildTarget": "dspace-angular:build:production" - }, - "production-e2e": { - "buildTarget": "dspace-angular:build:production-e2e" } } }, @@ -215,9 +181,6 @@ "configurations": { "production": { "devServerTarget": "dspace-angular:serve:production" - }, - "production-e2e": { - "devServerTarget": "dspace-angular:serve:production-e2e" } } }, @@ -252,20 +215,6 @@ "with": "src/config/store/devtools.prod.ts" } ] - }, - "production-e2e": { - "sourceMap": false, - "optimization": true, - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.production-e2e.ts" - }, - { - "replace": "src/config/store/devtools.ts", - "with": "src/config/store/devtools.prod.ts" - } - ] } } }, @@ -280,10 +229,6 @@ "production": { "buildTarget": "dspace-angular:build:production", "serverTarget": "dspace-angular:server:production" - }, - "production-e2e": { - "buildTarget": "dspace-angular:build:production-e2e", - "serverTarget": "dspace-angular:server:production-e2e" } } }, @@ -297,8 +242,7 @@ ] }, "configurations": { - "production": {}, - "production-e2e": {} + "production": {} } }, "cypress-run": { @@ -309,9 +253,6 @@ "configurations": { "production": { "devServerTarget": "dspace-angular:serve:production" - }, - "production-e2e": { - "devServerTarget": "dspace-angular:serve:production-e2e" } } }, diff --git a/package.json b/package.json index a9a6206afc..13ba71ee88 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,7 @@ "build": "ng build --configuration development", "build:stats": "ng build --stats-json", "build:prod": "cross-env NODE_ENV=production npm run build:ssr", - "build:prod-e2e": "cross-env NODE_ENV=production npm run build:ssr-e2e", "build:ssr": "ng build --configuration production && ng run dspace-angular:server:production", - "build:ssr-e2e": "ng build --configuration production-e2e && ng run dspace-angular:server:production-e2e", "build:lint": "rimraf 'lint/dist/**/*.js' 'lint/dist/**/*.js.map' && tsc -b lint/tsconfig.json", "test": "ng test --source-map=true --watch=false --configuration test", "test:watch": "nodemon --exec \"ng test --source-map=true --watch=true --configuration test\"", diff --git a/src/app/core/log/log.interceptor.spec.ts b/src/app/core/log/log.interceptor.spec.ts index e784dc1f8c..0a9e861970 100644 --- a/src/app/core/log/log.interceptor.spec.ts +++ b/src/app/core/log/log.interceptor.spec.ts @@ -16,7 +16,10 @@ import { appReducers, storeModuleConfig, } from '../../app.reducer'; -import { CorrelationIdService } from '../../correlation-id/correlation-id.service'; +import { + CORRELATION_ID_COOKIE, + CorrelationIdService, +} from '../../correlation-id/correlation-id.service'; import { OrejimeService } from '../../shared/cookies/orejime.service'; import { CORRELATION_ID_OREJIME_KEY } from '../../shared/cookies/orejime-configuration'; import { CookieServiceMock } from '../../shared/mocks/cookie.service.mock'; @@ -72,8 +75,8 @@ describe('LogInterceptor', () => { cookieService = TestBed.inject(CookieService); correlationIdService = TestBed.inject(CorrelationIdService); - cookieService.set('CORRELATION-ID','123455'); - correlationIdService.initCorrelationId(); + cookieService.set(CORRELATION_ID_COOKIE,'123455'); + correlationIdService.setCorrelationId(); }); diff --git a/src/app/correlation-id/correlation-id.service.spec.ts b/src/app/correlation-id/correlation-id.service.spec.ts index 5108ee1713..9a458644fc 100644 --- a/src/app/correlation-id/correlation-id.service.spec.ts +++ b/src/app/correlation-id/correlation-id.service.spec.ts @@ -4,6 +4,7 @@ import { StoreModule, } from '@ngrx/store'; import { MockStore } from '@ngrx/store/testing'; +import { of } from 'rxjs'; import { appReducers, @@ -13,7 +14,10 @@ import { import { UUIDService } from '../core/shared/uuid.service'; import { CookieServiceMock } from '../shared/mocks/cookie.service.mock'; import { SetCorrelationIdAction } from './correlation-id.actions'; -import { CorrelationIdService } from './correlation-id.service'; +import { + CORRELATION_ID_COOKIE, + CorrelationIdService, +} from './correlation-id.service'; describe('CorrelationIdService', () => { let service: CorrelationIdService; @@ -34,7 +38,13 @@ describe('CorrelationIdService', () => { cookieService = new CookieServiceMock(); uuidService = new UUIDService(); store = TestBed.inject(Store) as MockStore; - service = new CorrelationIdService(cookieService, uuidService, store); + const mockOrejimeService = { + getSavedPreferences: () => of({ CORRELATION_ID_OREJIME_KEY: true }), + initialize: jasmine.createSpy('initialize'), + showSettings: jasmine.createSpy('showSettings'), + }; + + service = new CorrelationIdService(cookieService, uuidService, store, mockOrejimeService, { nativeWindow: undefined }); }); describe('getCorrelationId', () => { @@ -46,45 +56,45 @@ describe('CorrelationIdService', () => { }); - describe('initCorrelationId', () => { + describe('setCorrelationId', () => { const cookieCID = 'cookie CID'; const storeCID = 'store CID'; it('should set cookie and store values to a newly generated value if neither ex', () => { - service.initCorrelationId(); + service.setCorrelationId(); - expect(cookieService.get('CORRELATION-ID')).toBeTruthy(); + expect(cookieService.get(CORRELATION_ID_COOKIE)).toBeTruthy(); expect(service.getCorrelationId()).toBeTruthy(); - expect(cookieService.get('CORRELATION-ID')).toEqual(service.getCorrelationId()); + expect(cookieService.get(CORRELATION_ID_COOKIE)).toEqual(service.getCorrelationId()); }); it('should set store value to cookie value if present', () => { expect(service.getCorrelationId()).toBe(null); - cookieService.set('CORRELATION-ID', cookieCID); + cookieService.set(CORRELATION_ID_COOKIE, cookieCID); - service.initCorrelationId(); + service.setCorrelationId(); - expect(cookieService.get('CORRELATION-ID')).toBe(cookieCID); + expect(cookieService.get(CORRELATION_ID_COOKIE)).toBe(cookieCID); expect(service.getCorrelationId()).toBe(cookieCID); }); it('should set cookie value to store value if present', () => { store.dispatch(new SetCorrelationIdAction(storeCID)); - service.initCorrelationId(); + service.setCorrelationId(); - expect(cookieService.get('CORRELATION-ID')).toBe(storeCID); + expect(cookieService.get(CORRELATION_ID_COOKIE)).toBe(storeCID); expect(service.getCorrelationId()).toBe(storeCID); }); it('should set store value to cookie value if both are present', () => { - cookieService.set('CORRELATION-ID', cookieCID); + cookieService.set(CORRELATION_ID_COOKIE, cookieCID); store.dispatch(new SetCorrelationIdAction(storeCID)); - service.initCorrelationId(); + service.setCorrelationId(); - expect(cookieService.get('CORRELATION-ID')).toBe(cookieCID); + expect(cookieService.get(CORRELATION_ID_COOKIE)).toBe(cookieCID); expect(service.getCorrelationId()).toBe(cookieCID); }); }); diff --git a/src/app/correlation-id/correlation-id.service.ts b/src/app/correlation-id/correlation-id.service.ts index d9ea39ec87..bb8b19d708 100644 --- a/src/app/correlation-id/correlation-id.service.ts +++ b/src/app/correlation-id/correlation-id.service.ts @@ -1,4 +1,7 @@ -import { Injectable } from '@angular/core'; +import { + Inject, + Injectable, +} from '@angular/core'; import { select, Store, @@ -7,12 +10,18 @@ import { take } from 'rxjs/operators'; import { AppState } from '../app.reducer'; import { CookieService } from '../core/services/cookie.service'; +import { + NativeWindowRef, + NativeWindowService, +} from '../core/services/window.service'; import { UUIDService } from '../core/shared/uuid.service'; +import { OrejimeService } from '../shared/cookies/orejime.service'; +import { CORRELATION_ID_OREJIME_KEY } from '../shared/cookies/orejime-configuration'; import { isEmpty } from '../shared/empty.util'; import { SetCorrelationIdAction } from './correlation-id.actions'; import { correlationIdSelector } from './correlation-id.selector'; -export const CORRELATION_ID_COOKIE = 'dsCorrelationId'; +export const CORRELATION_ID_COOKIE = 'CORRELATION-ID'; /** * Service to manage the correlation id, an id used to give context to server side logs @@ -26,15 +35,32 @@ export class CorrelationIdService { protected cookieService: CookieService, protected uuidService: UUIDService, protected store: Store, + protected orejimeService: OrejimeService, + @Inject(NativeWindowService) protected _window: NativeWindowRef, ) { + if (this._window?.nativeWindow) { + this._window.nativeWindow.initCorrelationId = () => this.initCorrelationId(); + } + } + + /** + * Check if the correlation id is allowed to be set, then set it + */ + initCorrelationId(): void { + this.orejimeService?.getSavedPreferences().subscribe(preferences => { + if (preferences[CORRELATION_ID_OREJIME_KEY]) { + this.setCorrelationId(); + } + }, + ); } /** * Initialize the correlation id based on the cookie or the ngrx store */ - initCorrelationId(): void { + setCorrelationId(): void { // first see of there's a cookie with a correlation-id - let correlationId = this.cookieService.get('CORRELATION-ID'); + let correlationId = this.cookieService.get(CORRELATION_ID_COOKIE); // if there isn't see if there's an ID in the store if (isEmpty(correlationId)) { @@ -48,7 +74,7 @@ export class CorrelationIdService { // Store the correct id both in the store and as a cookie to ensure they're in sync this.store.dispatch(new SetCorrelationIdAction(correlationId)); - this.cookieService.set('CORRELATION-ID', correlationId); + this.cookieService.set(CORRELATION_ID_COOKIE, correlationId); } /** diff --git a/src/app/shared/cookies/browser-orejime.service.ts b/src/app/shared/cookies/browser-orejime.service.ts index 895624cf79..632eb897ea 100644 --- a/src/app/shared/cookies/browser-orejime.service.ts +++ b/src/app/shared/cookies/browser-orejime.service.ts @@ -191,7 +191,7 @@ export class BrowserOrejimeService extends OrejimeService { */ this.translateConfiguration(); - if (environment.isE2E) { + if (!environment.info?.enableCookieConsentPopup) { this.orejimeConfig.apps = []; } else { this.orejimeConfig.apps = this.filterConfigApps(appsToHide); diff --git a/src/app/shared/cookies/orejime-configuration.ts b/src/app/shared/cookies/orejime-configuration.ts index 8ddd22f6c2..5e8f961087 100644 --- a/src/app/shared/cookies/orejime-configuration.ts +++ b/src/app/shared/cookies/orejime-configuration.ts @@ -151,6 +151,9 @@ export function getOrejimeConfiguration(_window: NativeWindowRef): any { cookies: [ CORRELATION_ID_COOKIE, ], + callback: () => { + _window?.nativeWindow.initCorrelationId(); + }, }, { name: MATOMO_OREJIME_KEY, diff --git a/src/config/build-config.interface.ts b/src/config/build-config.interface.ts index 712f0f673b..9501ae5e28 100644 --- a/src/config/build-config.interface.ts +++ b/src/config/build-config.interface.ts @@ -3,5 +3,4 @@ import { SSRConfig } from './ssr-config.interface'; export interface BuildConfig extends AppConfig { ssr: SSRConfig; - isE2E?: boolean; } diff --git a/src/config/info-config.interface.ts b/src/config/info-config.interface.ts index 445936ff0a..a51e04934a 100644 --- a/src/config/info-config.interface.ts +++ b/src/config/info-config.interface.ts @@ -1,7 +1,8 @@ import { Config } from './config.interface'; export interface InfoConfig extends Config { - enableEndUserAgreement: boolean; - enablePrivacyStatement: boolean; - enableCOARNotifySupport: boolean; + enableEndUserAgreement?: boolean; + enablePrivacyStatement?: boolean; + enableCOARNotifySupport?: boolean; + enableCookieConsentPopup?: boolean; } diff --git a/src/environments/.gitignore b/src/environments/.gitignore index a44fe84c68..03f1bde6f9 100644 --- a/src/environments/.gitignore +++ b/src/environments/.gitignore @@ -1,6 +1,5 @@ environment.*.ts !environment.production.ts -!environment.production-e2e.ts !environment.test.ts !environment.ts diff --git a/src/environments/environment.production-e2e.ts b/src/environments/environment.production-e2e.ts deleted file mode 100644 index 71952570c6..0000000000 --- a/src/environments/environment.production-e2e.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { BuildConfig } from '../config/build-config.interface'; -import { environment as prodEnvironment } from './environment.production'; - -export const environment: Partial = Object.assign( - {}, - prodEnvironment, - { - isE2E: true, - }, -); diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 9bd663922c..ca7d16894e 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -14,4 +14,7 @@ export const environment: Partial = { enableSearchComponent: false, enableBrowseComponent: false, }, + info: { + enableCookieConsentPopup: true, + }, }; diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index b6348f949d..2ffd1e83b1 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -324,6 +324,7 @@ export const environment: BuildConfig = { enableEndUserAgreement: true, enablePrivacyStatement: true, enableCOARNotifySupport: true, + enableCookieConsentPopup: true, }, markdown: { enabled: false, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 39ab31de03..f2f1e6da9a 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -19,6 +19,9 @@ export const environment: Partial = { enableSearchComponent: false, enableBrowseComponent: false, }, + info: { + enableCookieConsentPopup: true, + }, }; /*