Skip to content

Commit 72e1262

Browse files
author
Andrea Barbasso
committed
[CST-2709] fix comcol menu
1 parent f6d1b82 commit 72e1262

4 files changed

Lines changed: 111 additions & 1 deletion

File tree

src/app/app.menus.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { SystemWideAlertMenuProvider } from './shared/menu/providers/system-wide
3535
import { UserAgreementMenuProvider } from './shared/menu/providers/user-agreement.menu';
3636
import { WithdrawnReinstateItemMenuProvider } from './shared/menu/providers/withdrawn-reinstate-item.menu';
3737
import { WorkflowMenuProvider } from './shared/menu/providers/workflow.menu';
38+
import { AdminCommunityListMenuProvider } from './shared/menu/providers/admin-community-list.menu';
3839

3940
/**
4041
* Represents and builds the menu structure for the three available menus (public navbar, admin sidebar and the dso edit
@@ -59,6 +60,7 @@ export const MENUS = buildMenuStructure({
5960
StatisticsMenuProvider,
6061
],
6162
[MenuID.ADMIN]: [
63+
AdminCommunityListMenuProvider,
6264
NewMenuProvider,
6365
EditMenuProvider,
6466
ImportMenuProvider,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
11+
import { MenuItemType } from '../menu-item-type.model';
12+
import { PartialMenuSection } from '../menu-provider.model';
13+
import { AdminCommunityListMenuProvider } from './admin-community-list.menu';
14+
15+
describe('AdminCommunityListMenuProvider', () => {
16+
const expectedSections: PartialMenuSection[] = [
17+
{
18+
visible: true,
19+
model: {
20+
type: MenuItemType.LINK,
21+
text: `menu.section.communities_and_collections`,
22+
link: `/community-list`,
23+
},
24+
icon: 'diagram-project',
25+
},
26+
];
27+
28+
let provider: AdminCommunityListMenuProvider;
29+
30+
beforeEach(() => {
31+
TestBed.configureTestingModule({
32+
providers: [
33+
AdminCommunityListMenuProvider,
34+
],
35+
});
36+
provider = TestBed.inject(AdminCommunityListMenuProvider);
37+
});
38+
39+
it('should be created', () => {
40+
expect(provider).toBeTruthy();
41+
});
42+
43+
it('getSections should return expected menu sections', (done) => {
44+
provider.getSections().subscribe((sections) => {
45+
expect(sections).toEqual(expectedSections);
46+
done();
47+
});
48+
});
49+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { inject, Injectable } from '@angular/core';
10+
import {
11+
map,
12+
Observable,
13+
of,
14+
} from 'rxjs';
15+
16+
import { MenuItemType } from '../menu-item-type.model';
17+
import {
18+
AbstractMenuProvider,
19+
PartialMenuSection,
20+
} from '../menu-provider.model';
21+
import { APP_CONFIG } from '../../../../config/app-config.interface';
22+
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
23+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
24+
25+
/**
26+
* Menu provider to create the "Communities & Collections" menu section in the admin navbar
27+
*/
28+
@Injectable()
29+
export class AdminCommunityListMenuProvider extends AbstractMenuProvider {
30+
31+
protected appConfig = inject(APP_CONFIG);
32+
protected authorizationService = inject(AuthorizationDataService);
33+
34+
public getSections(): Observable<PartialMenuSection[]> {
35+
if (this.appConfig.layout.navbar.showCommunityCollection) {
36+
return of([]);
37+
}
38+
return this.authorizationService.isAuthorized(FeatureID.IsComColAdmin).pipe(
39+
map(isComColAdmin => {
40+
return [{
41+
visible: isComColAdmin,
42+
model: {
43+
type: MenuItemType.LINK,
44+
text: `menu.section.communities_and_collections`,
45+
link: `/community-list`,
46+
},
47+
icon: 'users',
48+
},
49+
] as PartialMenuSection[];
50+
}));
51+
}
52+
}

src/app/shared/menu/providers/community-list.menu.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* http://www.dspace.org/license/
77
*/
88

9-
import { Injectable } from '@angular/core';
9+
import { inject, Injectable } from '@angular/core';
1010
import {
1111
Observable,
1212
of,
@@ -17,13 +17,20 @@ import {
1717
AbstractMenuProvider,
1818
PartialMenuSection,
1919
} from '../menu-provider.model';
20+
import { APP_CONFIG } from '../../../../config/app-config.interface';
2021

2122
/**
2223
* Menu provider to create the "Communities & Collections" menu section in the public navbar
2324
*/
2425
@Injectable()
2526
export class CommunityListMenuProvider extends AbstractMenuProvider {
27+
28+
protected appConfig = inject(APP_CONFIG);
2629
public getSections(): Observable<PartialMenuSection[]> {
30+
if (!this.appConfig.layout.navbar.showCommunityCollection) {
31+
return of([]);
32+
}
33+
2734
return of([
2835
{
2936
visible: true,

0 commit comments

Comments
 (0)