CST-11012 Notify info component has been completed with working guard and service

This commit is contained in:
Sondissimo
2023-08-17 15:57:34 +02:00
parent 2f9089d013
commit 8271803f0a
8 changed files with 60 additions and 51 deletions

View File

@@ -4,19 +4,13 @@
<title>{{ 'coar-notify-support.title' | translate }}</title> <title>{{ 'coar-notify-support.title' | translate }}</title>
</head> </head>
<body> <body>
<ng-container *ngIf="coarLdnEnabled; else notAllowed"> <h1>{{ 'coar-notify-support.title' | translate }}</h1>
<p>{{coarLdnEnabled}}{{coarLdnEnabled | json}}</p> <p [innerHTML]="('coar-notify-support-title.content' | translate)"></p>
<h1>{{ 'coar-notify-support.title' | translate }}</h1>
<p [innerHTML]="('coar-notify-support-title.content' | translate)"></p>
<h2>{{ 'coar-notify-support.ldn-inbox.title' | translate }}</h2> <h2>{{ 'coar-notify-support.ldn-inbox.title' | translate }}</h2>
<p [innerHTML]="('coar-notify-support.ldn-inbox.content' | translate)"></p> <p [innerHTML]="('coar-notify-support.ldn-inbox.content' | translate)"></p>
<h2>{{ 'coar-notify-support.message-moderation.title' | translate }}</h2> <h2>{{ 'coar-notify-support.message-moderation.title' | translate }}</h2>
<p [innerHTML]="('coar-notify-support.message-moderation.content' | translate)"></p> <p [innerHTML]="('coar-notify-support.message-moderation.content' | translate)"></p>
</ng-container>
<ng-template #notAllowed>
<p>Disabled {{coarLdnEnabled}}{{coarLdnEnabled | json}}</p>
</ng-template>
</body> </body>
</html> </html>

View File

@@ -1,7 +1,6 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { NotifyInfoService } from './notify-info.service'; import { NotifyInfoService } from './notify-info.service';
@Component({ @Component({
selector: 'ds-notify-info', selector: 'ds-notify-info',
templateUrl: './notify-info.component.html', templateUrl: './notify-info.component.html',
@@ -16,9 +15,9 @@ export class NotifyInfoComponent implements OnInit {
) { } ) { }
ngOnInit() { ngOnInit() {
this.coarLdnEnabled = this.notifyInfoService.isCoarConfigEnabled(); this.notifyInfoService.isCoarConfigEnabled().subscribe(value => {
console.log(this.coarLdnEnabled); this.coarLdnEnabled = value;
});
} }
} }

View File

@@ -1,15 +1,30 @@
import { Injectable } from '@angular/core'; 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 { Observable } from 'rxjs';
import { NotifyInfoService } from './notify-info.service';
import { map } from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class NotifyInfoGuard implements CanActivate { export class NotifyInfoGuard implements CanActivate {
constructor(
private notifyInfoService: NotifyInfoService,
private router: Router
) {}
canActivate( canActivate(
route: ActivatedRouteSnapshot, route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return this.notifyInfoService.isCoarConfigEnabled().pipe(
map(coarLdnEnabled => {
if (coarLdnEnabled) {
return true; return true;
} else {
return this.router.parseUrl('/404');
}
})
);
} }
} }

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { getFirstSucceededRemoteData } from '../../shared/operators'; import { getFirstSucceededRemoteData } from '../../shared/operators';
import { ConfigurationDataService } from '../../data/configuration-data.service'; import { ConfigurationDataService } from '../../data/configuration-data.service';
import { map, Observable } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -10,15 +10,16 @@ export class NotifyInfoService {
constructor( constructor(
private configService: ConfigurationDataService, private configService: ConfigurationDataService,
) { ) {}
}
isCoarConfigEnabled(): boolean { isCoarConfigEnabled(): Observable<boolean> {
this.configService.findByPropertyName('coar-notify.enabled').pipe( return this.configService.findByPropertyName('coar-notify.enabled').pipe(
getFirstSucceededRemoteData() getFirstSucceededRemoteData(),
map(response => {
const booleanArrayValue = response.payload.values;
const coarConfigEnabled = booleanArrayValue.length > 0 ? booleanArrayValue[0] === 'true' : false;
return coarConfigEnabled;
})
); );
if (!getFirstSucceededRemoteData()) {
return true;
}
} }
} }

View File

@@ -81,10 +81,10 @@
</li> </li>
</ul> </ul>
</div> </div>
<div class="notify-enabled"> <div class="notify-enabled" [hidden]="!coarLdnEnabled">
<a class="coar-notify-support-route" routerLink="info/coar-notify-support"> <a class="coar-notify-support-route" routerLink="info/coar-notify-support">
<img class="n-coar" src="assets/images/n-coar.png" [attr.alt]="'menu.header.image.logo' | translate" /> <img class="n-coar" src="assets/images/n-coar.png" [attr.alt]="'menu.header.image.logo' | translate" />
This site support the COAR Notify protocol This site supports the COAR Notify protocol
</a> </a>
</div> </div>
</div> </div>

View File

@@ -2,6 +2,7 @@ import { Component, Optional } from '@angular/core';
import { hasValue } from '../shared/empty.util'; import { hasValue } from '../shared/empty.util';
import { KlaroService } from '../shared/cookies/klaro.service'; import { KlaroService } from '../shared/cookies/klaro.service';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
@Component({ @Component({
selector: 'ds-footer', selector: 'ds-footer',
@@ -17,8 +18,15 @@ export class FooterComponent {
showTopFooter = false; showTopFooter = false;
showPrivacyPolicy = environment.info.enablePrivacyStatement; showPrivacyPolicy = environment.info.enablePrivacyStatement;
showEndUserAgreement = environment.info.enableEndUserAgreement; 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() { showCookieSettings() {

View File

@@ -9,6 +9,7 @@ import { FeedbackGuard } from '../core/feedback/feedback.guard';
import { environment } from '../../environments/environment'; import { environment } from '../../environments/environment';
import { COAR_NOTIFY_SUPPORT } from '../app-routing-paths'; import { COAR_NOTIFY_SUPPORT } from '../app-routing-paths';
import { NotifyInfoComponent } from '../core/coar-notify/notify-info/notify-info.component'; import { NotifyInfoComponent } from '../core/coar-notify/notify-info/notify-info.component';
import { NotifyInfoGuard } from '../core/coar-notify/notify-info/notify-info.guard';
const imports = [ const imports = [
@@ -27,8 +28,7 @@ const imports = [
component: NotifyInfoComponent, component: NotifyInfoComponent,
resolve: { breadcrumb: I18nBreadcrumbResolver }, resolve: { breadcrumb: I18nBreadcrumbResolver },
data: { title: 'info.coar-notify-support.title', breadcrumbKey: 'info.coar-notify-support' }, data: { title: 'info.coar-notify-support.title', breadcrumbKey: 'info.coar-notify-support' },
// TODO: create authGuard for COAR_NOTIFY canActivate: [NotifyInfoGuard]
// canActivate: [FeedbackGuard]
} }
]) ])
]; ];

View File

@@ -32,8 +32,6 @@ import { logStartupMessage } from '../../../startup-message';
import { MenuService } from '../../app/shared/menu/menu.service'; import { MenuService } from '../../app/shared/menu/menu.service';
import { RootDataService } from '../../app/core/data/root-data.service'; import { RootDataService } from '../../app/core/data/root-data.service';
import { firstValueFrom, Subscription } from 'rxjs'; import { firstValueFrom, Subscription } from 'rxjs';
import { NotifyInfoService } from '../../app/core/coar-notify/notify-info/notify-info.service';
/** /**
* Performs client-side initialization. * Performs client-side initialization.
*/ */
@@ -51,7 +49,6 @@ export class BrowserInitService extends InitService {
protected localeService: LocaleService, protected localeService: LocaleService,
protected angulartics2DSpace: Angulartics2DSpace, protected angulartics2DSpace: Angulartics2DSpace,
protected googleAnalyticsService: GoogleAnalyticsService, protected googleAnalyticsService: GoogleAnalyticsService,
protected notifyInfoService: NotifyInfoService,
protected metadata: MetadataService, protected metadata: MetadataService,
protected breadcrumbsService: BreadcrumbsService, protected breadcrumbsService: BreadcrumbsService,
protected klaroService: KlaroService, protected klaroService: KlaroService,
@@ -97,7 +94,6 @@ export class BrowserInitService extends InitService {
this.initI18n(); this.initI18n();
this.initAngulartics(); this.initAngulartics();
this.initGoogleAnalytics(); this.initGoogleAnalytics();
this.retrieveCoarConfig();
this.initRouteListeners(); this.initRouteListeners();
this.themeService.listenForThemeChanges(true); this.themeService.listenForThemeChanges(true);
this.trackAuthTokenExpiration(); this.trackAuthTokenExpiration();
@@ -145,10 +141,6 @@ export class BrowserInitService extends InitService {
this.googleAnalyticsService.addTrackingIdToPage(); this.googleAnalyticsService.addTrackingIdToPage();
} }
protected retrieveCoarConfig() {
this.notifyInfoService.isCoarConfigEnabled();
}
/** /**
* During an external authentication flow invalidate the SSR transferState * During an external authentication flow invalidate the SSR transferState
* data in the cache. This allows the app to fetch fresh content. * data in the cache. This allows the app to fetch fresh content.