@@ -19,7 +19,9 @@ import {
1919 combineLatest ,
2020 map ,
2121 Observable ,
22+ of ,
2223} from 'rxjs' ;
24+ import { switchMap } from 'rxjs/operators' ;
2325
2426import { LinkMenuItemModel } from '../menu-item/models/link.model' ;
2527import { MenuItemType } from '../menu-item-type.model' ;
@@ -39,26 +41,38 @@ export class AuditLogsMenuProvider extends DSpaceObjectPageMenuProvider {
3941 }
4042
4143 public getSectionsForContext ( dso : DSpaceObject ) : Observable < PartialMenuSection [ ] > {
42- return combineLatest ( [
43- this . authorizationDataService . isAuthorized ( FeatureID . AdministratorOf ) ,
44- this . configurationDataService . findByPropertyName ( 'audit.context-menu-entry.enabled' ) . pipe (
45- getFirstCompletedRemoteData ( ) ,
46- map ( ( response : RemoteData < ConfigurationProperty > ) => {
47- return response . hasSucceeded ? ( response . payload . values . length > 0 && response . payload . values [ 0 ] === 'true' ) : false ;
48- } ) ,
49- ) ,
50- ] ) . pipe (
51- map ( ( [ isAdmin , isAuditEnabled ] : [ boolean , boolean ] ) => {
52- return [ {
53- model : {
54- type : MenuItemType . LINK ,
55- text : 'context-menu.actions.audit-item.btn' ,
56- link : new URLCombiner ( getDSORoute ( dso ) , 'auditlogs' ) . toString ( ) ,
57- } as LinkMenuItemModel ,
58- icon : 'clipboard-check' ,
59- visible : true ,
60- } ] as PartialMenuSection [ ] ;
44+ return this . configurationDataService . findByPropertyName ( 'audit.enabled' ) . pipe (
45+ getFirstCompletedRemoteData ( ) ,
46+ map ( ( response : RemoteData < ConfigurationProperty > ) => this . isPropertyEnabled ( response ) ) ,
47+ switchMap ( ( isAuditEnabled : boolean ) => {
48+ if ( isAuditEnabled ) {
49+ return combineLatest ( [
50+ this . authorizationDataService . isAuthorized ( FeatureID . AdministratorOf ) ,
51+ this . configurationDataService . findByPropertyName ( 'audit.context-menu-entry.enabled' ) . pipe (
52+ getFirstCompletedRemoteData ( ) ,
53+ map ( ( response : RemoteData < ConfigurationProperty > ) => this . isPropertyEnabled ( response ) ) ,
54+ ) ,
55+ ] ) . pipe (
56+ map ( ( [ isAdmin , isAuditMenuEnabled ] : [ boolean , boolean ] ) => {
57+ return [ {
58+ model : {
59+ type : MenuItemType . LINK ,
60+ text : 'context-menu.actions.audit-item.btn' ,
61+ link : new URLCombiner ( getDSORoute ( dso ) , 'auditlogs' ) . toString ( ) ,
62+ } as LinkMenuItemModel ,
63+ icon : 'clipboard-check' ,
64+ visible : isAdmin && isAuditMenuEnabled ,
65+ } ] as PartialMenuSection [ ] ;
66+ } ) ,
67+ ) ;
68+ } else {
69+ return of ( [ ] ) ;
70+ }
6171 } ) ,
6272 ) ;
6373 }
74+
75+ private isPropertyEnabled ( property : RemoteData < ConfigurationProperty > ) : boolean {
76+ return property . hasSucceeded ? ( property . payload . values . length > 0 && property . payload . values [ 0 ] === 'true' ) : false ;
77+ }
6478}
0 commit comments