CST-11012 notify info component updated with guards and services (needs cleanup)

This commit is contained in:
Sondissimo
2023-08-11 15:26:20 +02:00
parent 36dfb69670
commit 2f9089d013
8 changed files with 90 additions and 11 deletions

View File

@@ -5,6 +5,7 @@
</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>
@@ -15,7 +16,7 @@
<p [innerHTML]="('coar-notify-support.message-moderation.content' | translate)"></p>
</ng-container>
<ng-template #notAllowed>
<p>Disabled</p>
<p>Disabled {{coarLdnEnabled}}{{coarLdnEnabled | json}}</p>
</ng-template>
</body>
</html>

View File

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

View File

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

View File

@@ -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<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
return true;
}
}

View File

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

View File

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

View File

@@ -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 <a href=\"/feedback\">here</a>.",
"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 <a href=\"info/feedback\">here</a>.",

View File

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