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,20 @@ 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 ( this . object ) . pipe (
89+ getFirstCompletedRemoteData ( ) ,
90+ map ( data => data . payload ) ,
91+ switchMap ( ( collection ) => this . collectionDataService . findById (
92+ collection . id ,
93+ false ,
94+ false ,
95+ ...COLLECTION_PAGE_LINKS_TO_FOLLOW
96+ ) . pipe (
97+ getFirstCompletedRemoteData ( ) ,
98+ map ( data => data . payload ) ,
99+ )
100+ )
101+ ) ;
81102 this . setAudits ( ) ;
82103 } ) ;
83104 }
@@ -88,17 +109,35 @@ export class ObjectAuditOverviewComponent implements OnInit {
88109 setAudits ( ) {
89110 const config$ = this . paginationService . getFindListOptions ( this . pageConfig . id , this . config , this . pageConfig ) ;
90111 const isAdmin$ = this . isCurrentUserAdmin ( ) ;
91- this . auditsRD$ = combineLatest ( [ isAdmin$ , config$ ] ) . pipe (
92- mergeMap ( ( [ isAdmin , config ] ) => {
112+ const parentCommunity$ = this . owningCollection$ . pipe (
113+ switchMap ( collection => collection . parentCommunity ) ,
114+ getFirstCompletedRemoteData ( ) ,
115+ map ( data => data ?. payload )
116+ ) ;
117+
118+
119+ this . auditsRD$ = combineLatest ( [ isAdmin$ , config$ , parentCommunity$ , this . owningCollection$ ] ) . pipe (
120+ mergeMap ( ( [ isAdmin , config , owningCollection , parentCommunity ] ) => {
93121 if ( isAdmin ) {
94- return this . auditService . findByObject ( this . object . id , config ) ;
122+ return this . auditService . findByObject ( this . object . id , config , owningCollection . id , parentCommunity . id ) ;
95123 }
124+
125+ return of ( null ) ;
96126 } )
97127 ) ;
98128 }
99129
100130 isCurrentUserAdmin ( ) : Observable < boolean > {
101- return this . authorizationService . isAuthorized ( FeatureID . AdministratorOf , undefined , undefined ) ;
131+ return combineLatest ( [
132+ this . authorizationService . isAuthorized ( FeatureID . IsCollectionAdmin ) ,
133+ this . authorizationService . isAuthorized ( FeatureID . IsCommunityAdmin ) ,
134+ this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) ,
135+ ] ) . pipe (
136+ map ( ( [ isCollectionAdmin , isCommunityAdmin , isSiteAdmin ] ) => {
137+ return isCollectionAdmin || isCommunityAdmin || isSiteAdmin ;
138+ } ) ,
139+ take ( 1 ) ,
140+ ) ;
102141 }
103142
104143 /**
0 commit comments