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 8552eec83b..3596acfc67 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 @@ -4,19 +4,13 @@ {{ 'coar-notify-support.title' | translate }} - -

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

-

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

-

+

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

+

-

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

-

+

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

+

-

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

-

-
- -

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

-
+

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

+

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 c8ed861738..9c8f48218d 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,7 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { NotifyInfoService } from './notify-info.service'; - @Component({ selector: 'ds-notify-info', templateUrl: './notify-info.component.html', @@ -16,9 +15,9 @@ export class NotifyInfoComponent implements OnInit { ) { } ngOnInit() { - this.coarLdnEnabled = this.notifyInfoService.isCoarConfigEnabled(); - console.log(this.coarLdnEnabled); - } + this.notifyInfoService.isCoarConfigEnabled().subscribe(value => { + this.coarLdnEnabled = value; + }); + } } - 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 index 6a920a090b..4da9a42f21 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.guard.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.guard.ts @@ -1,15 +1,30 @@ import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; import { Observable } from 'rxjs'; +import { NotifyInfoService } from './notify-info.service'; +import { map } from 'rxjs/operators'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class NotifyInfoGuard implements CanActivate { - canActivate( - route: ActivatedRouteSnapshot, - state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { - return true; - } + constructor( + private notifyInfoService: NotifyInfoService, + private router: Router + ) {} + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot + ): Observable | Promise | boolean | UrlTree { + return this.notifyInfoService.isCoarConfigEnabled().pipe( + map(coarLdnEnabled => { + if (coarLdnEnabled) { + return true; + } else { + return this.router.parseUrl('/404'); + } + }) + ); + } } 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 index 3651c04e93..6183a1fb30 100644 --- a/src/app/core/coar-notify/notify-info/notify-info.service.ts +++ b/src/app/core/coar-notify/notify-info/notify-info.service.ts @@ -1,24 +1,25 @@ import { Injectable } from '@angular/core'; import { getFirstSucceededRemoteData } from '../../shared/operators'; import { ConfigurationDataService } from '../../data/configuration-data.service'; - +import { map, Observable } from 'rxjs'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class NotifyInfoService { - constructor( - private configService: ConfigurationDataService, - ) { - } + constructor( + private configService: ConfigurationDataService, + ) {} - isCoarConfigEnabled(): boolean { - this.configService.findByPropertyName('coar-notify.enabled').pipe( - getFirstSucceededRemoteData() - ); - if (!getFirstSucceededRemoteData()) { - return true; + isCoarConfigEnabled(): Observable { + return this.configService.findByPropertyName('coar-notify.enabled').pipe( + getFirstSucceededRemoteData(), + map(response => { + const booleanArrayValue = response.payload.values; + const coarConfigEnabled = booleanArrayValue.length > 0 ? booleanArrayValue[0] === 'true' : false; + return coarConfigEnabled; + }) + ); } - } } diff --git a/src/app/footer/footer.component.html b/src/app/footer/footer.component.html index 5a77d98269..1c4b95c557 100644 --- a/src/app/footer/footer.component.html +++ b/src/app/footer/footer.component.html @@ -81,10 +81,10 @@ - diff --git a/src/app/footer/footer.component.ts b/src/app/footer/footer.component.ts index c4195c8eb3..4b04a8f5dc 100644 --- a/src/app/footer/footer.component.ts +++ b/src/app/footer/footer.component.ts @@ -2,6 +2,7 @@ import { Component, Optional } from '@angular/core'; import { hasValue } from '../shared/empty.util'; import { KlaroService } from '../shared/cookies/klaro.service'; import { environment } from '../../environments/environment'; +import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service'; @Component({ selector: 'ds-footer', @@ -17,8 +18,15 @@ export class FooterComponent { showTopFooter = false; showPrivacyPolicy = environment.info.enablePrivacyStatement; showEndUserAgreement = environment.info.enableEndUserAgreement; + coarLdnEnabled: boolean; // Add this line - constructor(@Optional() private cookies: KlaroService) { + constructor( + @Optional() private cookies: KlaroService, + private notifyInfoService: NotifyInfoService + ) { + this.notifyInfoService.isCoarConfigEnabled().subscribe(coarLdnEnabled => { + this.coarLdnEnabled = coarLdnEnabled; + }); } showCookieSettings() { diff --git a/src/app/info/info-routing.module.ts b/src/app/info/info-routing.module.ts index 9734fa4627..4085924567 100644 --- a/src/app/info/info-routing.module.ts +++ b/src/app/info/info-routing.module.ts @@ -9,6 +9,7 @@ import { FeedbackGuard } from '../core/feedback/feedback.guard'; import { environment } from '../../environments/environment'; import { COAR_NOTIFY_SUPPORT } from '../app-routing-paths'; import { NotifyInfoComponent } from '../core/coar-notify/notify-info/notify-info.component'; +import { NotifyInfoGuard } from '../core/coar-notify/notify-info/notify-info.guard'; const imports = [ @@ -27,8 +28,7 @@ const imports = [ component: NotifyInfoComponent, resolve: { breadcrumb: I18nBreadcrumbResolver }, data: { title: 'info.coar-notify-support.title', breadcrumbKey: 'info.coar-notify-support' }, - // TODO: create authGuard for COAR_NOTIFY - // canActivate: [FeedbackGuard] + canActivate: [NotifyInfoGuard] } ]) ]; diff --git a/src/modules/app/browser-init.service.ts b/src/modules/app/browser-init.service.ts index 3d03e015c5..9e8da43557 100644 --- a/src/modules/app/browser-init.service.ts +++ b/src/modules/app/browser-init.service.ts @@ -32,8 +32,6 @@ 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. */ @@ -51,7 +49,6 @@ 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, @@ -97,7 +94,6 @@ export class BrowserInitService extends InitService { this.initI18n(); this.initAngulartics(); this.initGoogleAnalytics(); - this.retrieveCoarConfig(); this.initRouteListeners(); this.themeService.listenForThemeChanges(true); this.trackAuthTokenExpiration(); @@ -145,10 +141,6 @@ 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.