From 2f9089d01328762d244879fe176a1d92986aacfb Mon Sep 17 00:00:00 2001 From: Sondissimo Date: Fri, 11 Aug 2023 15:26:20 +0200 Subject: [PATCH] CST-11012 notify info component updated with guards and services (needs cleanup) --- .../notify-info/notify-info.component.html | 3 ++- .../notify-info/notify-info.component.ts | 18 +++++++------- .../notify-info/notify-info.guard.spec.ts | 16 +++++++++++++ .../notify-info/notify-info.guard.ts | 15 ++++++++++++ .../notify-info/notify-info.service.spec.ts | 16 +++++++++++++ .../notify-info/notify-info.service.ts | 24 +++++++++++++++++++ src/assets/i18n/en.json5 | 2 +- src/modules/app/browser-init.service.ts | 7 ++++++ 8 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts create mode 100644 src/app/core/coar-notify/notify-info/notify-info.guard.ts create mode 100644 src/app/core/coar-notify/notify-info/notify-info.service.spec.ts create mode 100644 src/app/core/coar-notify/notify-info/notify-info.service.ts diff --git a/src/app/core/coar-notify/notify-info/notify-info.component.html b/src/app/core/coar-notify/notify-info/notify-info.component.html index fcd362562e..8552eec83b 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.component.html +++ b/src/app/core/coar-notify/notify-info/notify-info.component.html @@ -5,6 +5,7 @@ +

{{coarLdnEnabled}}{{coarLdnEnabled | json}}

{{ 'coar-notify-support.title' | translate }}

@@ -15,7 +16,7 @@

-

Disabled

+

Disabled {{coarLdnEnabled}}{{coarLdnEnabled | json}}

diff --git a/src/app/core/coar-notify/notify-info/notify-info.component.ts b/src/app/core/coar-notify/notify-info/notify-info.component.ts index 1ec6dfedb4..c8ed861738 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.component.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { AuthorizationDataService } from '../../data/feature-authorization/authorization-data.service'; -import { FeatureID } from '../../data/feature-authorization/feature-id'; +import { NotifyInfoService } from './notify-info.service'; + @Component({ selector: 'ds-notify-info', @@ -12,13 +12,13 @@ export class NotifyInfoComponent implements OnInit { coarLdnEnabled: boolean; constructor( - private authorizationService: AuthorizationDataService, - ) { - } + public notifyInfoService: NotifyInfoService, + ) { } ngOnInit() { - this.authorizationService.isAuthorized(FeatureID.CoarLdnEnabled).subscribe(enabled => { - this.coarLdnEnabled = enabled; - }); - } + this.coarLdnEnabled = this.notifyInfoService.isCoarConfigEnabled(); + console.log(this.coarLdnEnabled); + } + } + diff --git a/src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts b/src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts new file mode 100644 index 0000000000..789140ebe4 --- /dev/null +++ b/src/app/core/coar-notify/notify-info/notify-info.guard.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { NotifyInfoGuard } from './notify-info.guard'; + +describe('NotifyInfoGuard', () => { + let guard: NotifyInfoGuard; + + beforeEach(() => { + TestBed.configureTestingModule({}); + guard = TestBed.inject(NotifyInfoGuard); + }); + + it('should be created', () => { + expect(guard).toBeTruthy(); + }); +}); diff --git a/src/app/core/coar-notify/notify-info/notify-info.guard.ts b/src/app/core/coar-notify/notify-info/notify-info.guard.ts new file mode 100644 index 0000000000..6a920a090b --- /dev/null +++ b/src/app/core/coar-notify/notify-info/notify-info.guard.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@angular/core'; +import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { Observable } from 'rxjs'; + +@Injectable({ + providedIn: 'root' +}) +export class NotifyInfoGuard implements CanActivate { + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { + return true; + } + +} diff --git a/src/app/core/coar-notify/notify-info/notify-info.service.spec.ts b/src/app/core/coar-notify/notify-info/notify-info.service.spec.ts new file mode 100644 index 0000000000..b32d590cd6 --- /dev/null +++ b/src/app/core/coar-notify/notify-info/notify-info.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { NotifyInfoService } from './notify-info.service'; + +describe('NotifyInfoService', () => { + let service: NotifyInfoService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(NotifyInfoService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/core/coar-notify/notify-info/notify-info.service.ts b/src/app/core/coar-notify/notify-info/notify-info.service.ts new file mode 100644 index 0000000000..3651c04e93 --- /dev/null +++ b/src/app/core/coar-notify/notify-info/notify-info.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { getFirstSucceededRemoteData } from '../../shared/operators'; +import { ConfigurationDataService } from '../../data/configuration-data.service'; + + +@Injectable({ + providedIn: 'root' +}) +export class NotifyInfoService { + + constructor( + private configService: ConfigurationDataService, + ) { + } + + isCoarConfigEnabled(): boolean { + this.configService.findByPropertyName('coar-notify.enabled').pipe( + getFirstSucceededRemoteData() + ); + if (!getFirstSucceededRemoteData()) { + return true; + } + } +} diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 9d72aec64f..9cd1519363 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -877,7 +877,7 @@ "coar-notify-support.message-moderation.title": "Message Moderation", - "coar-notify-support.message-moderation.content": "To ensure a secure and productive environment, all incoming LDN messages are moderated. If you are planning to exchange information with us, kindly reach out via our dedicated Feedback form. You can access the Feedback form by clicking here.", + "coar-notify-support.message-moderation.content": "To ensure a secure and productive environment, all incoming LDN messages are moderated. If you are planning to exchange information with us, kindly reach out via our dedicated Feedback form. You can access the Feedback form by clicking here.", diff --git a/src/modules/app/browser-init.service.ts b/src/modules/app/browser-init.service.ts index 61d57f10f9..3d03e015c5 100644 --- a/src/modules/app/browser-init.service.ts +++ b/src/modules/app/browser-init.service.ts @@ -32,6 +32,7 @@ import { logStartupMessage } from '../../../startup-message'; import { MenuService } from '../../app/shared/menu/menu.service'; import { RootDataService } from '../../app/core/data/root-data.service'; import { firstValueFrom, Subscription } from 'rxjs'; +import { NotifyInfoService } from '../../app/core/coar-notify/notify-info/notify-info.service'; /** * Performs client-side initialization. @@ -50,6 +51,7 @@ export class BrowserInitService extends InitService { protected localeService: LocaleService, protected angulartics2DSpace: Angulartics2DSpace, protected googleAnalyticsService: GoogleAnalyticsService, + protected notifyInfoService: NotifyInfoService, protected metadata: MetadataService, protected breadcrumbsService: BreadcrumbsService, protected klaroService: KlaroService, @@ -95,6 +97,7 @@ export class BrowserInitService extends InitService { this.initI18n(); this.initAngulartics(); this.initGoogleAnalytics(); + this.retrieveCoarConfig(); this.initRouteListeners(); this.themeService.listenForThemeChanges(true); this.trackAuthTokenExpiration(); @@ -142,6 +145,10 @@ export class BrowserInitService extends InitService { this.googleAnalyticsService.addTrackingIdToPage(); } + protected retrieveCoarConfig() { + this.notifyInfoService.isCoarConfigEnabled(); + } + /** * During an external authentication flow invalidate the SSR transferState * data in the cache. This allows the app to fetch fresh content.