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,8 +4,6 @@
<title>{{ 'coar-notify-support.title' | translate }}</title>
</head>
<body>
<ng-container *ngIf="coarLdnEnabled; else notAllowed">
<p>{{coarLdnEnabled}}{{coarLdnEnabled | json}}</p>
<h1>{{ 'coar-notify-support.title' | translate }}</h1>
<p [innerHTML]="('coar-notify-support-title.content' | translate)"></p>
@@ -14,9 +12,5 @@
<h2>{{ 'coar-notify-support.message-moderation.title' | translate }}</h2>
<p [innerHTML]="('coar-notify-support.message-moderation.content' | translate)"></p>
</ng-container>
<ng-template #notAllowed>
<p>Disabled {{coarLdnEnabled}}{{coarLdnEnabled | json}}</p>
</ng-template>
</body>
</html>

View File

@@ -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;
});
}
}

View File

@@ -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'
})
export class NotifyInfoGuard implements CanActivate {
constructor(
private notifyInfoService: NotifyInfoService,
private router: Router
) {}
canActivate(
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;
} else {
return this.router.parseUrl('/404');
}
})
);
}
}

View File

@@ -1,7 +1,7 @@
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'
@@ -10,15 +10,16 @@ export class NotifyInfoService {
constructor(
private configService: ConfigurationDataService,
) {
}
) {}
isCoarConfigEnabled(): boolean {
this.configService.findByPropertyName('coar-notify.enabled').pipe(
getFirstSucceededRemoteData()
isCoarConfigEnabled(): Observable<boolean> {
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;
})
);
if (!getFirstSucceededRemoteData()) {
return true;
}
}
}

View File

@@ -81,10 +81,10 @@
</li>
</ul>
</div>
<div class="notify-enabled">
<div class="notify-enabled" [hidden]="!coarLdnEnabled">
<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" />
This site support the COAR Notify protocol
This site supports the COAR Notify protocol
</a>
</div>
</div>

View File

@@ -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() {

View File

@@ -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]
}
])
];

View File

@@ -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.