@@ -7,16 +7,23 @@ import {
77import { RouterLink } from '@angular/router' ;
88import { TranslateModule } from '@ngx-translate/core' ;
99import {
10- BehaviorSubject ,
1110 combineLatest ,
11+ Observable ,
1212} from 'rxjs' ;
13- import { take } from 'rxjs/operators' ;
13+ import {
14+ map ,
15+ startWith ,
16+ } from 'rxjs/operators' ;
1417
1518import { getDSORoute } from '../../../app-routing-paths' ;
19+ import { ConfigurationDataService } from '../../../core/data/configuration-data.service' ;
1620import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service' ;
1721import { FeatureID } from '../../../core/data/feature-authorization/feature-id' ;
22+ import { RemoteData } from '../../../core/data/remote-data' ;
23+ import { ConfigurationProperty } from '../../../core/shared/configuration-property.model' ;
1824import { DSpaceObject } from '../../../core/shared/dspace-object.model' ;
1925import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model' ;
26+ import { getFirstCompletedRemoteData } from '../../../core/shared/operators' ;
2027import { URLCombiner } from '../../../core/url-combiner/url-combiner' ;
2128import { ContextMenuEntryComponent } from '../context-menu-entry.component' ;
2229import { ContextMenuEntryType } from '../context-menu-entry-type' ;
@@ -35,31 +42,46 @@ import { ContextMenuEntryType } from '../context-menu-entry-type';
3542} )
3643export class AuditItemMenuComponent extends ContextMenuEntryComponent implements OnInit {
3744
38- public isAuthorized $ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( false ) ;
45+ public showMenuItem $ : Observable < boolean > ;
3946
4047 constructor (
4148 @Inject ( 'contextMenuObjectProvider' ) protected injectedContextMenuObject : DSpaceObject ,
4249 @Inject ( 'contextMenuObjectTypeProvider' ) protected injectedContextMenuObjectType : DSpaceObjectType ,
4350 private authorizationService : AuthorizationDataService ,
51+ private configurationDataService : ConfigurationDataService ,
4452 ) {
4553 super ( injectedContextMenuObject , injectedContextMenuObjectType , ContextMenuEntryType . Audit ) ;
4654 }
4755
4856 ngOnInit ( ) : void {
49- combineLatest (
57+
58+ const isEnabled$ = this . configurationDataService . findByPropertyName ( 'audit.enabled' ) . pipe (
59+ getFirstCompletedRemoteData ( ) ,
60+ map ( ( response : RemoteData < ConfigurationProperty > ) => this . isPropertyEnabled ( response ) ) ,
61+ ) ;
62+
63+ const isAuthorized$ = combineLatest (
5064 [
5165 this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) ,
5266 this . authorizationService . isAuthorized ( FeatureID . IsCollectionAdmin ) ,
5367 this . authorizationService . isAuthorized ( FeatureID . IsCommunityAdmin ) ,
5468 ] ,
5569 ) . pipe (
56- take ( 1 ) ,
57- ) . subscribe ( ( [ isAdmin , isCollectionAdmin , isCommunityAdmin ] ) => {
58- this . isAuthorized$ . next ( isAdmin || isCommunityAdmin || isCollectionAdmin ) ;
59- } ) ;
70+ map ( ( [ isAdmin , isCollectionAdmin , isCommunityAdmin ] ) => isAdmin || isCollectionAdmin || isCommunityAdmin ) ,
71+ ) ;
72+
73+ this . showMenuItem$ = combineLatest ( [ isEnabled$ , isAuthorized$ ] ) . pipe (
74+ map ( ( [ isEnabled , isAuthorized ] ) => isAuthorized && isEnabled ) ,
75+ startWith ( false ) ,
76+ ) ;
6077 }
6178
6279 get link ( ) {
6380 return new URLCombiner ( getDSORoute ( this . contextMenuObject ) , 'auditlogs' ) . toString ( ) ;
6481 }
82+
83+ private isPropertyEnabled ( property : RemoteData < ConfigurationProperty > ) : boolean {
84+ return property . hasSucceeded ? ( property . payload . values . length > 0 && property . payload . values [ 0 ] === 'true' ) : false ;
85+ }
86+
6587}
0 commit comments