11import { Component , OnInit } from '@angular/core' ;
22
3- import { combineLatest , Observable } from 'rxjs' ;
4- import { mergeMap } from 'rxjs/operators' ;
3+ import { combineLatest , Observable , of , switchMap } from 'rxjs' ;
4+ import { map , mergeMap , take } from 'rxjs/operators' ;
55
66import { RemoteData } from '../../core/data/remote-data' ;
77import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model' ;
@@ -18,6 +18,10 @@ import { AuthService } from '../../core/auth/auth.service';
1818import { PaginatedList } from '../../core/data/paginated-list.model' ;
1919import { PaginationService } from '../../core/pagination/pagination.service' ;
2020import { redirectOn4xx } from '../../core/shared/authorized.operators' ;
21+ import { CollectionDataService } from '../../core/data/collection-data.service' ;
22+ import { Collection } from '../../core/shared/collection.model' ;
23+ import { Item } from '../../core/shared/item.model' ;
24+ import { COLLECTION_PAGE_LINKS_TO_FOLLOW } from '../../collection-page/collection-page.resolver' ;
2125
2226/**
2327 * Component displaying a list of all audit about a object in a paginated table
@@ -31,7 +35,7 @@ export class ObjectAuditOverviewComponent implements OnInit {
3135 /**
3236 * The object extracted from the route.
3337 */
34- object ;
38+ object : Item ;
3539
3640 /**
3741 * List of all audits
@@ -62,14 +66,17 @@ export class ObjectAuditOverviewComponent implements OnInit {
6266 */
6367 dateFormat = 'yyyy-MM-dd HH:mm:ss' ;
6468
69+ owningCollection$ : Observable < Collection > ;
70+
6571 constructor ( protected authService : AuthService ,
6672 protected route : ActivatedRoute ,
6773 protected router : Router ,
6874 protected auditService : AuditDataService ,
6975 protected itemService : ItemDataService ,
7076 protected authorizationService : AuthorizationDataService ,
71- protected paginationService : PaginationService ) {
72- }
77+ protected paginationService : PaginationService ,
78+ protected collectionDataService : CollectionDataService
79+ ) { }
7380
7481 ngOnInit ( ) : void {
7582 this . route . paramMap . pipe (
@@ -78,6 +85,15 @@ export class ObjectAuditOverviewComponent implements OnInit {
7885 redirectOn4xx ( this . router , this . authService )
7986 ) . subscribe ( ( rd ) => {
8087 this . object = rd . payload ;
88+ this . owningCollection$ = this . collectionDataService . findOwningCollectionFor (
89+ this . object ,
90+ true ,
91+ false ,
92+ ...COLLECTION_PAGE_LINKS_TO_FOLLOW
93+ ) . pipe (
94+ getFirstCompletedRemoteData ( ) ,
95+ map ( data => data ?. payload )
96+ ) ;
8197 this . setAudits ( ) ;
8298 } ) ;
8399 }
@@ -88,17 +104,35 @@ export class ObjectAuditOverviewComponent implements OnInit {
88104 setAudits ( ) {
89105 const config$ = this . paginationService . getFindListOptions ( this . pageConfig . id , this . config , this . pageConfig ) ;
90106 const isAdmin$ = this . isCurrentUserAdmin ( ) ;
91- this . auditsRD$ = combineLatest ( [ isAdmin$ , config$ ] ) . pipe (
92- mergeMap ( ( [ isAdmin , config ] ) => {
107+ const parentCommunity$ = this . owningCollection$ . pipe (
108+ switchMap ( collection => collection . parentCommunity ) ,
109+ getFirstCompletedRemoteData ( ) ,
110+ map ( data => data ?. payload )
111+ ) ;
112+
113+
114+ this . auditsRD$ = combineLatest ( [ isAdmin$ , config$ , this . owningCollection$ , parentCommunity$ ] ) . pipe (
115+ mergeMap ( ( [ isAdmin , config , owningCollection , parentCommunity ] ) => {
93116 if ( isAdmin ) {
94- return this . auditService . findByObject ( this . object . id , config ) ;
117+ return this . auditService . findByObject ( this . object . id , config , owningCollection . id , parentCommunity . id ) ;
95118 }
119+
120+ return of ( null ) ;
96121 } )
97122 ) ;
98123 }
99124
100125 isCurrentUserAdmin ( ) : Observable < boolean > {
101- return this . authorizationService . isAuthorized ( FeatureID . AdministratorOf , undefined , undefined ) ;
126+ return combineLatest ( [
127+ this . authorizationService . isAuthorized ( FeatureID . IsCollectionAdmin ) ,
128+ this . authorizationService . isAuthorized ( FeatureID . IsCommunityAdmin ) ,
129+ this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) ,
130+ ] ) . pipe (
131+ map ( ( [ isCollectionAdmin , isCommunityAdmin , isSiteAdmin ] ) => {
132+ return isCollectionAdmin || isCommunityAdmin || isSiteAdmin ;
133+ } ) ,
134+ take ( 1 ) ,
135+ ) ;
102136 }
103137
104138 /**
0 commit comments