diff --git a/src/app/admin/admin-sidebar/admin-sidebar.component.spec.ts b/src/app/admin/admin-sidebar/admin-sidebar.component.spec.ts index 65026c1504..2a5a544a40 100644 --- a/src/app/admin/admin-sidebar/admin-sidebar.component.spec.ts +++ b/src/app/admin/admin-sidebar/admin-sidebar.component.spec.ts @@ -237,7 +237,24 @@ describe('AdminSidebarComponent', () => { expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ parentID: 'access_control', visible: false, })); + }); + // We check that the menu section has not been called with visible set to true + // The reason why we don't check if it has been called with visible set to false + // Is because the function does not get called unless a user is authorised + it('should not show the import section', () => { + expect(menuService.addSection).not.toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'import', visible: true, + })); + }); + + // We check that the menu section has not been called with visible set to true + // The reason why we don't check if it has been called with visible set to false + // Is because the function does not get called unless a user is authorised + it('should not show the export section', () => { + expect(menuService.addSection).not.toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'export', visible: true, + })); }); }); @@ -268,6 +285,15 @@ describe('AdminSidebarComponent', () => { expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ id: 'workflow', visible: true, })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'workflow', visible: true, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'import', visible: true, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'export', visible: true, + })); }); }); diff --git a/src/app/admin/admin-sidebar/admin-sidebar.component.ts b/src/app/admin/admin-sidebar/admin-sidebar.component.ts index dc9d2a817f..cec0c13b7d 100644 --- a/src/app/admin/admin-sidebar/admin-sidebar.component.ts +++ b/src/app/admin/admin-sidebar/admin-sidebar.component.ts @@ -1,9 +1,13 @@ import { Component, HostListener, Injector, OnInit } from '@angular/core'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { combineLatest, combineLatest as observableCombineLatest, Observable, BehaviorSubject } from 'rxjs'; -import { debounceTime, first, map, take, distinctUntilChanged, withLatestFrom } from 'rxjs/operators'; +import { debounceTime, first, map, take, filter, distinctUntilChanged, withLatestFrom } from 'rxjs/operators'; import { AuthService } from '../../core/auth/auth.service'; -import { ScriptDataService } from '../../core/data/processes/script-data.service'; +import { + ScriptDataService, + METADATA_IMPORT_SCRIPT_NAME, + METADATA_EXPORT_SCRIPT_NAME +} from '../../core/data/processes/script-data.service'; import { slideHorizontal, slideSidebar } from '../../shared/animations/slide'; import { CreateCollectionParentSelectorComponent } from '../../shared/dso-selector/modal-wrappers/create-collection-parent-selector/create-collection-parent-selector.component'; import { CreateCommunityParentSelectorComponent } from '../../shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component'; @@ -321,19 +325,6 @@ export class AdminSidebarComponent extends MenuComponent implements OnInit { */ createExportMenuSections() { const menuList = [ - /* Export */ - { - id: 'export', - active: false, - visible: true, - model: { - type: MenuItemType.TEXT, - text: 'menu.section.export' - } as TextMenuItemModel, - icon: 'file-export', - index: 3, - shouldPersistOnRouteChange: true - }, // TODO: enable this menu item once the feature has been implemented // { // id: 'export_community', @@ -378,12 +369,26 @@ export class AdminSidebarComponent extends MenuComponent implements OnInit { observableCombineLatest( this.authorizationService.isAuthorized(FeatureID.AdministratorOf), - // this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_EXPORT_SCRIPT_NAME) + this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_EXPORT_SCRIPT_NAME) ).pipe( - // TODO uncomment when #635 (https://github.com/DSpace/dspace-angular/issues/635) is fixed; otherwise even in production mode, the metadata export button is only available after a refresh (and not in dev mode) - // filter(([authorized, metadataExportScriptExists]: boolean[]) => authorized && metadataExportScriptExists), + filter(([authorized, metadataExportScriptExists]: boolean[]) => authorized && metadataExportScriptExists), take(1) ).subscribe(() => { + // Hides the export menu for unauthorised people + // If in the future more sub-menus are added, + // it should be reviewed if they need to be in this subscribe + this.menuService.addSection(this.menuID, { + id: 'export', + active: false, + visible: true, + model: { + type: MenuItemType.TEXT, + text: 'menu.section.export' + } as TextMenuItemModel, + icon: 'file-export', + index: 3, + shouldPersistOnRouteChange: true + }); this.menuService.addSection(this.menuID, { id: 'export_metadata', parentID: 'export', @@ -407,18 +412,6 @@ export class AdminSidebarComponent extends MenuComponent implements OnInit { */ createImportMenuSections() { const menuList = [ - /* Import */ - { - id: 'import', - active: false, - visible: true, - model: { - type: MenuItemType.TEXT, - text: 'menu.section.import' - } as TextMenuItemModel, - icon: 'file-import', - index: 2 - }, // TODO: enable this menu item once the feature has been implemented // { // id: 'import_batch', @@ -438,12 +431,25 @@ export class AdminSidebarComponent extends MenuComponent implements OnInit { observableCombineLatest( this.authorizationService.isAuthorized(FeatureID.AdministratorOf), - // this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_IMPORT_SCRIPT_NAME) + this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_IMPORT_SCRIPT_NAME) ).pipe( - // TODO uncomment when #635 (https://github.com/DSpace/dspace-angular/issues/635) is fixed - // filter(([authorized, metadataImportScriptExists]: boolean[]) => authorized && metadataImportScriptExists), + filter(([authorized, metadataImportScriptExists]: boolean[]) => authorized && metadataImportScriptExists), take(1) ).subscribe(() => { + // Hides the import menu for unauthorised people + // If in the future more sub-menus are added, + // it should be reviewed if they need to be in this subscribe + this.menuService.addSection(this.menuID, { + id: 'import', + active: false, + visible: true, + model: { + type: MenuItemType.TEXT, + text: 'menu.section.import' + } as TextMenuItemModel, + icon: 'file-import', + index: 2 + }); this.menuService.addSection(this.menuID, { id: 'import_metadata', parentID: 'import', diff --git a/src/app/core/data/processes/script-data.service.ts b/src/app/core/data/processes/script-data.service.ts index 69b4270173..aa7417bddc 100644 --- a/src/app/core/data/processes/script-data.service.ts +++ b/src/app/core/data/processes/script-data.service.ts @@ -19,6 +19,8 @@ import { Observable } from 'rxjs'; import { dataService } from '../../cache/builders/build-decorators'; import { SCRIPT } from '../../../process-page/scripts/script.resource-type'; import { Process } from '../../../process-page/processes/process.model'; +import { hasValue } from '../../../shared/empty.util'; +import { getFirstCompletedRemoteData } from '../../shared/operators'; export const METADATA_IMPORT_SCRIPT_NAME = 'metadata-import'; export const METADATA_EXPORT_SCRIPT_NAME = 'metadata-export'; @@ -62,4 +64,16 @@ export class ScriptDataService extends DataService