Skip to content

Commit e10630f

Browse files
Added functionality to disable COAR notify support link in footer
Also fixed error that showed a blank page instead of a 404 when disabling EULA/Privacy Policy pages
1 parent 2ef2e9b commit e10630f

15 files changed

Lines changed: 83 additions & 59 deletions

config/config.example.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,11 @@ mediaViewer:
407407

408408
# Whether the end user agreement is required before users use the repository.
409409
# If enabled, the user will be required to accept the agreement before they can use the repository.
410-
# And whether the privacy statement should exist or not.
410+
# And whether the privacy statement/COAR notify support page should exist or not.
411411
info:
412412
enableEndUserAgreement: true
413413
enablePrivacyStatement: true
414+
enableCOARNotifySupport: true
414415

415416
# Whether to enable Markdown (https://commonmark.org/) and MathJax (https://www.mathjax.org/)
416417
# display in supported metadata fields. By default, only dc.description.abstract is supported.

src/app/app-routing-paths.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: st
3434
},
3535
};
3636
}
37-
export const COAR_NOTIFY_SUPPORT = 'coar-notify-support';
3837

3938
export const HOME_PAGE_PATH = 'home';
4039

src/app/footer/footer.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ <h5 class="text-uppercase">Footer Content</h5>
8282
</li>
8383
</ul>
8484
</div>
85-
<div class="notify-enabled text-white" [hidden]="!coarLdnEnabled">
85+
<div *ngIf="coarLdnEnabled$ | async" class="notify-enabled text-white">
8686
<a class="coar-notify-support-route" routerLink="info/coar-notify-support">
8787
<img class="n-coar" src="assets/images/n-coar.png" [attr.alt]="'menu.header.image.logo' | translate" />
88-
COAR Notify
88+
{{ 'footer.link.coar-notify-support' | translate }}
8989
</a>
9090
</div>
9191
</div>

src/app/footer/footer.component.spec.ts

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// ... test imports
2-
import { CommonModule } from '@angular/common';
3-
import {
4-
CUSTOM_ELEMENTS_SCHEMA,
5-
DebugElement,
6-
} from '@angular/core';
71
import {
82
ComponentFixture,
93
fakeAsync,
@@ -13,28 +7,19 @@ import {
137
} from '@angular/core/testing';
148
import { By } from '@angular/platform-browser';
159
import { ActivatedRoute } from '@angular/router';
16-
import { StoreModule } from '@ngrx/store';
17-
import {
18-
TranslateLoader,
19-
TranslateModule,
20-
} from '@ngx-translate/core';
10+
import { TranslateModule } from '@ngx-translate/core';
2111
import { of } from 'rxjs';
22-
import { environment } from 'src/environments/environment';
2312

24-
import { storeModuleConfig } from '../app.reducer';
13+
import { APP_CONFIG } from '../../config/app-config.interface';
14+
import { environment } from '../../environments/environment.test';
2515
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
2616
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
27-
import { TranslateLoaderMock } from '../shared/mocks/translate-loader.mock';
2817
import { ActivatedRouteStub } from '../shared/testing/active-router.stub';
2918
import { AuthorizationDataServiceStub } from '../shared/testing/authorization-service.stub';
30-
// Load the implementations that should be tested
3119
import { FooterComponent } from './footer.component';
3220

3321
let comp: FooterComponent;
34-
let compAny: any;
3522
let fixture: ComponentFixture<FooterComponent>;
36-
let de: DebugElement;
37-
let el: HTMLElement;
3823

3924
let notifyInfoService = {
4025
isCoarConfigEnabled: () => of(true),
@@ -43,30 +28,23 @@ let notifyInfoService = {
4328
describe('Footer component', () => {
4429
beforeEach(waitForAsync(() => {
4530
return TestBed.configureTestingModule({
46-
imports: [CommonModule, StoreModule.forRoot({}, storeModuleConfig), TranslateModule.forRoot({
47-
loader: {
48-
provide: TranslateLoader,
49-
useClass: TranslateLoaderMock,
50-
},
51-
}), FooterComponent],
31+
imports: [
32+
TranslateModule.forRoot(),
33+
],
5234
providers: [
5335
FooterComponent,
5436
{ provide: AuthorizationDataService, useClass: AuthorizationDataServiceStub },
5537
{ provide: NotifyInfoService, useValue: notifyInfoService },
5638
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
39+
{ provide: APP_CONFIG, useValue: environment },
5740
],
58-
schemas: [CUSTOM_ELEMENTS_SCHEMA],
5941
});
6042
}));
6143

6244
// synchronous beforeEach
6345
beforeEach(() => {
6446
fixture = TestBed.createComponent(FooterComponent);
6547
comp = fixture.componentInstance;
66-
compAny = comp as any;
67-
// query for the title <p> by CSS element selector
68-
de = fixture.debugElement.query(By.css('p'));
69-
el = de.nativeElement;
7048
});
7149

7250
it('should create footer', inject([FooterComponent], (app: FooterComponent) => {
@@ -76,23 +54,25 @@ describe('Footer component', () => {
7654

7755

7856
it('should set showPrivacyPolicy to the value of environment.info.enablePrivacyStatement', () => {
57+
comp.ngOnInit();
7958
expect(comp.showPrivacyPolicy).toBe(environment.info.enablePrivacyStatement);
8059
});
8160

8261
it('should set showEndUserAgreement to the value of environment.info.enableEndUserAgreement', () => {
62+
comp.ngOnInit();
8363
expect(comp.showEndUserAgreement).toBe(environment.info.enableEndUserAgreement);
8464
});
8565

8666
describe('showCookieSettings', () => {
8767
it('should call cookies.showSettings() if cookies is defined', () => {
8868
const cookies = jasmine.createSpyObj('cookies', ['showSettings']);
89-
compAny.cookies = cookies;
69+
comp.cookies = cookies;
9070
comp.showCookieSettings();
9171
expect(cookies.showSettings).toHaveBeenCalled();
9272
});
9373

9474
it('should not call cookies.showSettings() if cookies is undefined', () => {
95-
compAny.cookies = undefined;
75+
comp.cookies = undefined;
9676
expect(() => comp.showCookieSettings()).not.toThrow();
9777
});
9878

@@ -107,9 +87,7 @@ describe('Footer component', () => {
10787
fixture.detectChanges();
10888
});
10989

110-
it('should set coarLdnEnabled based on notifyInfoService', () => {
111-
expect(comp.coarLdnEnabled).toBeTruthy();
112-
// Check if COAR Notify section is rendered
90+
it('should render COAR notify support link', () => {
11391
const notifySection = fixture.debugElement.query(By.css('.notify-enabled'));
11492
expect(notifySection).toBeTruthy();
11593
});

src/app/footer/footer.component.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ import {
55
} from '@angular/common';
66
import {
77
Component,
8+
Inject,
9+
OnInit,
810
Optional,
911
} from '@angular/core';
1012
import { RouterLink } from '@angular/router';
1113
import { TranslateModule } from '@ngx-translate/core';
12-
import { Observable } from 'rxjs';
14+
import {
15+
Observable,
16+
of as observableOf,
17+
} from 'rxjs';
1318

14-
import { environment } from '../../environments/environment';
19+
import {
20+
APP_CONFIG,
21+
AppConfig,
22+
} from '../../config/app-config.interface';
1523
import { NotifyInfoService } from '../core/coar-notify/notify-info/notify-info.service';
1624
import { AuthorizationDataService } from '../core/data/feature-authorization/authorization-data.service';
1725
import { FeatureID } from '../core/data/feature-authorization/feature-id';
@@ -25,27 +33,31 @@ import { hasValue } from '../shared/empty.util';
2533
standalone: true,
2634
imports: [NgIf, RouterLink, AsyncPipe, DatePipe, TranslateModule],
2735
})
28-
export class FooterComponent {
36+
export class FooterComponent implements OnInit {
2937
dateObj: number = Date.now();
3038

3139
/**
3240
* A boolean representing if to show or not the top footer container
3341
*/
3442
showTopFooter = false;
35-
showPrivacyPolicy = environment.info.enablePrivacyStatement;
36-
showEndUserAgreement = environment.info.enableEndUserAgreement;
43+
showPrivacyPolicy: boolean;
44+
showEndUserAgreement: boolean;
3745
showSendFeedback$: Observable<boolean>;
38-
coarLdnEnabled: boolean;
46+
coarLdnEnabled$: Observable<boolean>;
3947

4048
constructor(
41-
@Optional() private cookies: KlaroService,
42-
private authorizationService: AuthorizationDataService,
43-
private notifyInfoService: NotifyInfoService,
49+
@Optional() public cookies: KlaroService,
50+
protected authorizationService: AuthorizationDataService,
51+
protected notifyInfoService: NotifyInfoService,
52+
@Inject(APP_CONFIG) protected appConfig: AppConfig,
4453
) {
54+
}
55+
56+
ngOnInit(): void {
57+
this.showPrivacyPolicy = this.appConfig.info.enablePrivacyStatement;
58+
this.showEndUserAgreement = this.appConfig.info.enableEndUserAgreement;
59+
this.coarLdnEnabled$ = this.appConfig.info.enableCOARNotifySupport ? this.notifyInfoService.isCoarConfigEnabled() : observableOf(false);
4560
this.showSendFeedback$ = this.authorizationService.isAuthorized(FeatureID.CanSendFeedback);
46-
this.notifyInfoService.isCoarConfigEnabled().subscribe(coarLdnEnabled => {
47-
this.coarLdnEnabled = coarLdnEnabled;
48-
});
4961
}
5062

5163
showCookieSettings() {

src/app/info/info-routes.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
import {
2+
Route,
3+
Routes,
4+
} from '@angular/router';
5+
16
import { environment } from '../../environments/environment';
27
import { i18nBreadcrumbResolver } from '../core/breadcrumbs/i18n-breadcrumb.resolver';
8+
import { notifyInfoGuard } from '../core/coar-notify/notify-info/notify-info.guard';
39
import { feedbackGuard } from '../core/feedback/feedback.guard';
10+
import { hasValue } from '../shared/empty.util';
411
import { ThemedEndUserAgreementComponent } from './end-user-agreement/themed-end-user-agreement.component';
512
import { ThemedFeedbackComponent } from './feedback/themed-feedback.component';
613
import {
14+
COAR_NOTIFY_SUPPORT,
715
END_USER_AGREEMENT_PATH,
816
FEEDBACK_PATH,
917
PRIVACY_PATH,
1018
} from './info-routing-paths';
19+
import { NotifyInfoComponent } from './notify-info/notify-info.component';
1120
import { ThemedPrivacyComponent } from './privacy/themed-privacy.component';
1221

1322

14-
export const ROUTES = [
23+
export const ROUTES: Routes = [
1524
{
1625
path: FEEDBACK_PATH,
1726
component: ThemedFeedbackComponent,
@@ -31,4 +40,16 @@ export const ROUTES = [
3140
resolve: { breadcrumb: i18nBreadcrumbResolver },
3241
data: { title: 'info.privacy.title', breadcrumbKey: 'info.privacy' },
3342
} : undefined,
34-
];
43+
environment.info.enableCOARNotifySupport ? {
44+
path: COAR_NOTIFY_SUPPORT,
45+
component: NotifyInfoComponent,
46+
canActivate: [notifyInfoGuard],
47+
resolve: {
48+
breadcrumb: i18nBreadcrumbResolver,
49+
},
50+
data: {
51+
title: 'info.coar-notify-support.title',
52+
breadcrumbKey: 'info.coar-notify-support',
53+
},
54+
} : undefined,
55+
].filter((route: Route) => hasValue(route));

src/app/info/info-routing-paths.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getInfoModulePath } from '../app-routing-paths';
33
export const END_USER_AGREEMENT_PATH = 'end-user-agreement';
44
export const PRIVACY_PATH = 'privacy';
55
export const FEEDBACK_PATH = 'feedback';
6+
export const COAR_NOTIFY_SUPPORT = 'coar-notify-support';
67

78
export function getEndUserAgreementPath() {
89
return getSubPath(END_USER_AGREEMENT_PATH);
@@ -16,6 +17,10 @@ export function getFeedbackPath() {
1617
return getSubPath(FEEDBACK_PATH);
1718
}
1819

20+
export function getCOARNotifySupportPath(): string {
21+
return getSubPath(COAR_NOTIFY_SUPPORT);
22+
}
23+
1924
function getSubPath(path: string) {
2025
return `${getInfoModulePath()}/${path}`;
2126
}

src/app/core/coar-notify/notify-info/notify-info.component.html renamed to src/app/info/notify-info/notify-info.component.html

File renamed without changes.

src/app/core/coar-notify/notify-info/notify-info.component.scss renamed to src/app/info/notify-info/notify-info.component.scss

File renamed without changes.

src/app/core/coar-notify/notify-info/notify-info.component.spec.ts renamed to src/app/info/notify-info/notify-info.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { ActivatedRoute } from '@angular/router';
66
import { TranslateModule } from '@ngx-translate/core';
77
import { of } from 'rxjs';
88

9-
import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub';
9+
import { NotifyInfoService } from '../../core/coar-notify/notify-info/notify-info.service';
10+
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
1011
import { NotifyInfoComponent } from './notify-info.component';
11-
import { NotifyInfoService } from './notify-info.service';
1212

1313
describe('NotifyInfoComponent', () => {
1414
let component: NotifyInfoComponent;

0 commit comments

Comments
 (0)