mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
97183 Hide sidebar items w/o appropriate permissions.
See https://github.com/DSpace/dspace-angular/issues/1643 Sidebar now omits "New" and/or "Edit" options in the sidebar if the user does not have permissions to respectively create new Items or edit Items. If this results in an empty sidebar, the sidebar is hidden in its entirety.
This commit is contained in:
@@ -100,6 +100,7 @@ export class AdminSidebarComponent extends MenuComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.menuVisible = this.menuService.isMenuVisibleWithVisibleSections(this.menuID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('focusin')
|
@HostListener('focusin')
|
||||||
|
@@ -29,5 +29,7 @@ export enum FeatureID {
|
|||||||
CanViewUsageStatistics = 'canViewUsageStatistics',
|
CanViewUsageStatistics = 'canViewUsageStatistics',
|
||||||
CanSendFeedback = 'canSendFeedback',
|
CanSendFeedback = 'canSendFeedback',
|
||||||
CanClaimItem = 'canClaimItem',
|
CanClaimItem = 'canClaimItem',
|
||||||
CanSynchronizeWithORCID = 'canSynchronizeWithORCID'
|
CanSynchronizeWithORCID = 'canSynchronizeWithORCID',
|
||||||
|
CanSubmit = 'canSubmit',
|
||||||
|
CanEditItem = 'canEditItem',
|
||||||
}
|
}
|
||||||
|
@@ -167,10 +167,11 @@ export class MenuResolver implements Resolve<boolean> {
|
|||||||
combineLatest([
|
combineLatest([
|
||||||
this.authorizationService.isAuthorized(FeatureID.IsCollectionAdmin),
|
this.authorizationService.isAuthorized(FeatureID.IsCollectionAdmin),
|
||||||
this.authorizationService.isAuthorized(FeatureID.IsCommunityAdmin),
|
this.authorizationService.isAuthorized(FeatureID.IsCommunityAdmin),
|
||||||
this.authorizationService.isAuthorized(FeatureID.AdministratorOf)
|
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
|
||||||
]).subscribe(([isCollectionAdmin, isCommunityAdmin, isSiteAdmin]) => {
|
this.authorizationService.isAuthorized(FeatureID.CanSubmit),
|
||||||
const menuList = [
|
this.authorizationService.isAuthorized(FeatureID.CanEditItem),
|
||||||
/* News */
|
]).subscribe(([isCollectionAdmin, isCommunityAdmin, isSiteAdmin, canSubmit, canEditItem]) => {
|
||||||
|
const newSubMenuList = [
|
||||||
{
|
{
|
||||||
id: 'new_community',
|
id: 'new_community',
|
||||||
parentID: 'new',
|
parentID: 'new',
|
||||||
@@ -201,7 +202,7 @@ export class MenuResolver implements Resolve<boolean> {
|
|||||||
id: 'new_item',
|
id: 'new_item',
|
||||||
parentID: 'new',
|
parentID: 'new',
|
||||||
active: false,
|
active: false,
|
||||||
visible: true,
|
visible: canSubmit,
|
||||||
model: {
|
model: {
|
||||||
type: MenuItemType.ONCLICK,
|
type: MenuItemType.ONCLICK,
|
||||||
text: 'menu.section.new_item',
|
text: 'menu.section.new_item',
|
||||||
@@ -221,30 +222,8 @@ export class MenuResolver implements Resolve<boolean> {
|
|||||||
link: '/processes/new'
|
link: '/processes/new'
|
||||||
} as LinkMenuItemModel,
|
} as LinkMenuItemModel,
|
||||||
},
|
},
|
||||||
{
|
];
|
||||||
id: 'new',
|
const editSubMenuList = [
|
||||||
active: false,
|
|
||||||
visible: true,
|
|
||||||
model: {
|
|
||||||
type: MenuItemType.TEXT,
|
|
||||||
text: 'menu.section.new'
|
|
||||||
} as TextMenuItemModel,
|
|
||||||
icon: 'plus',
|
|
||||||
index: 0
|
|
||||||
},
|
|
||||||
// TODO: enable this menu item once the feature has been implemented
|
|
||||||
// {
|
|
||||||
// id: 'new_item_version',
|
|
||||||
// parentID: 'new',
|
|
||||||
// active: false,
|
|
||||||
// visible: true,
|
|
||||||
// model: {
|
|
||||||
// type: MenuItemType.LINK,
|
|
||||||
// text: 'menu.section.new_item_version',
|
|
||||||
// link: ''
|
|
||||||
// } as LinkMenuItemModel,
|
|
||||||
// },
|
|
||||||
|
|
||||||
/* Edit */
|
/* Edit */
|
||||||
{
|
{
|
||||||
id: 'edit_community',
|
id: 'edit_community',
|
||||||
@@ -276,7 +255,7 @@ export class MenuResolver implements Resolve<boolean> {
|
|||||||
id: 'edit_item',
|
id: 'edit_item',
|
||||||
parentID: 'edit',
|
parentID: 'edit',
|
||||||
active: false,
|
active: false,
|
||||||
visible: true,
|
visible: canEditItem,
|
||||||
model: {
|
model: {
|
||||||
type: MenuItemType.ONCLICK,
|
type: MenuItemType.ONCLICK,
|
||||||
text: 'menu.section.edit_item',
|
text: 'menu.section.edit_item',
|
||||||
@@ -285,17 +264,47 @@ export class MenuResolver implements Resolve<boolean> {
|
|||||||
}
|
}
|
||||||
} as OnClickMenuItemModel,
|
} as OnClickMenuItemModel,
|
||||||
},
|
},
|
||||||
{
|
];
|
||||||
id: 'edit',
|
const newSubMenu = {
|
||||||
active: false,
|
id: 'new',
|
||||||
visible: true,
|
active: false,
|
||||||
model: {
|
visible: newSubMenuList.map(subMenu => subMenu.visible).reduce((x,y) => x || y),
|
||||||
type: MenuItemType.TEXT,
|
model: {
|
||||||
text: 'menu.section.edit'
|
type: MenuItemType.TEXT,
|
||||||
} as TextMenuItemModel,
|
text: 'menu.section.new'
|
||||||
icon: 'pencil-alt',
|
} as TextMenuItemModel,
|
||||||
index: 1
|
icon: 'plus',
|
||||||
},
|
index: 0
|
||||||
|
}
|
||||||
|
const editSubMenu = {
|
||||||
|
id: 'edit',
|
||||||
|
active: false,
|
||||||
|
visible: editSubMenuList.map(subMenu => subMenu.visible).reduce((x,y) => x || y),
|
||||||
|
model: {
|
||||||
|
type: MenuItemType.TEXT,
|
||||||
|
text: 'menu.section.edit'
|
||||||
|
} as TextMenuItemModel,
|
||||||
|
icon: 'pencil-alt',
|
||||||
|
index: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const menuList = [
|
||||||
|
...newSubMenuList,
|
||||||
|
newSubMenu,
|
||||||
|
...editSubMenuList,
|
||||||
|
editSubMenu,
|
||||||
|
// TODO: enable this menu item once the feature has been implemented
|
||||||
|
// {
|
||||||
|
// id: 'new_item_version',
|
||||||
|
// parentID: 'new',
|
||||||
|
// active: false,
|
||||||
|
// visible: true,
|
||||||
|
// model: {
|
||||||
|
// type: MenuItemType.LINK,
|
||||||
|
// text: 'menu.section.new_item_version',
|
||||||
|
// link: ''
|
||||||
|
// } as LinkMenuItemModel,
|
||||||
|
// },
|
||||||
|
|
||||||
/* Statistics */
|
/* Statistics */
|
||||||
// TODO: enable this menu item once the feature has been implemented
|
// TODO: enable this menu item once the feature has been implemented
|
||||||
|
@@ -61,7 +61,7 @@ export class RootComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.sidebarVisible = this.menuService.isMenuVisible(MenuID.ADMIN);
|
this.sidebarVisible = this.menuService.isMenuVisibleWithVisibleSections(MenuID.ADMIN);
|
||||||
|
|
||||||
this.collapsedSidebarWidth = this.cssService.getVariable('collapsedSidebarWidth');
|
this.collapsedSidebarWidth = this.cssService.getVariable('collapsedSidebarWidth');
|
||||||
this.totalSidebarWidth = this.cssService.getVariable('totalSidebarWidth');
|
this.totalSidebarWidth = this.cssService.getVariable('totalSidebarWidth');
|
||||||
|
@@ -181,6 +181,18 @@ export class MenuService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given menu is visible and has visible sections
|
||||||
|
* @param {MenuID} menuID The ID of the menu that is to be checked
|
||||||
|
* @returns {Observable<boolean>} Emits true if the given menu is
|
||||||
|
* visible and has visible sections, emits false when it's hidden
|
||||||
|
*/
|
||||||
|
isMenuVisibleWithVisibleSections(menuID: MenuID): Observable<boolean> {
|
||||||
|
return observableCombineLatest([this.isMenuVisible(menuID), this.menuHasVisibleSections(menuID)]).pipe(
|
||||||
|
map(([menuVisible, visibleSections]) => menuVisible && visibleSections)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given menu is visible
|
* Check if a given menu is visible
|
||||||
* @param {MenuID} menuID The ID of the menu that is to be checked
|
* @param {MenuID} menuID The ID of the menu that is to be checked
|
||||||
@@ -192,6 +204,19 @@ export class MenuService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a menu has at least one section that is visible.
|
||||||
|
* @param {MenuID} menuID The ID of the menu that is to be checked
|
||||||
|
* @returns {Observable<boolean>} Emits true if the given menu has visible sections, emits false otherwise
|
||||||
|
*/
|
||||||
|
menuHasVisibleSections(menuID: MenuID): Observable<boolean> {
|
||||||
|
return this.getMenu(menuID).pipe(
|
||||||
|
map((state: MenuState) => hasValue(state)
|
||||||
|
? Object.values(state.sections).map(section => section.visible).reduce((x,y) => x || y, false)
|
||||||
|
: undefined)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expands a given menu
|
* Expands a given menu
|
||||||
* @param {MenuID} menuID The ID of the menu
|
* @param {MenuID} menuID The ID of the menu
|
||||||
|
Reference in New Issue
Block a user