@@ -18,13 +18,21 @@ import { TranslateModule } from '@ngx-translate/core';
1818import {
1919 combineLatest ,
2020 Observable ,
21+ of ,
2122} from 'rxjs' ;
22- import { mergeMap } from 'rxjs/operators' ;
23+ import {
24+ map ,
25+ mergeMap ,
26+ switchMap ,
27+ take ,
28+ } from 'rxjs/operators' ;
2329
30+ import { COLLECTION_PAGE_LINKS_TO_FOLLOW } from '../../collection-page/collection-page.resolver' ;
2431import { AuditDataService } from '../../core/audit/audit-data.service' ;
2532import { Audit } from '../../core/audit/model/audit.model' ;
2633import { AuthService } from '../../core/auth/auth.service' ;
2734import { SortDirection } from '../../core/cache/models/sort-options.model' ;
35+ import { CollectionDataService } from '../../core/data/collection-data.service' ;
2836import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service' ;
2937import { FeatureID } from '../../core/data/feature-authorization/feature-id' ;
3038import { FindListOptions } from '../../core/data/find-list-options.model' ;
@@ -33,6 +41,8 @@ import { PaginatedList } from '../../core/data/paginated-list.model';
3341import { RemoteData } from '../../core/data/remote-data' ;
3442import { PaginationService } from '../../core/pagination/pagination.service' ;
3543import { redirectOn4xx } from '../../core/shared/authorized.operators' ;
44+ import { Collection } from '../../core/shared/collection.model' ;
45+ import { Item } from '../../core/shared/item.model' ;
3646import { getFirstCompletedRemoteData } from '../../core/shared/operators' ;
3747import { PaginationComponent } from '../../shared/pagination/pagination.component' ;
3848import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model' ;
@@ -61,7 +71,7 @@ export class ObjectAuditOverviewComponent implements OnInit {
6171 /**
6272 * The object extracted from the route.
6373 */
64- object ;
74+ object : Item ;
6575
6676 /**
6777 * List of all audits
@@ -92,14 +102,17 @@ export class ObjectAuditOverviewComponent implements OnInit {
92102 */
93103 dateFormat = 'yyyy-MM-dd HH:mm:ss' ;
94104
105+ owningCollection$ : Observable < Collection > ;
106+
95107 constructor ( protected authService : AuthService ,
96108 protected route : ActivatedRoute ,
97109 protected router : Router ,
98110 protected auditService : AuditDataService ,
99111 protected itemService : ItemDataService ,
100112 protected authorizationService : AuthorizationDataService ,
101- protected paginationService : PaginationService ) {
102- }
113+ protected paginationService : PaginationService ,
114+ protected collectionDataService : CollectionDataService ,
115+ ) { }
103116
104117 ngOnInit ( ) : void {
105118 this . route . paramMap . pipe (
@@ -108,6 +121,15 @@ export class ObjectAuditOverviewComponent implements OnInit {
108121 redirectOn4xx ( this . router , this . authService ) ,
109122 ) . subscribe ( ( rd ) => {
110123 this . object = rd . payload ;
124+ this . owningCollection$ = this . collectionDataService . findOwningCollectionFor (
125+ this . object ,
126+ true ,
127+ false ,
128+ ...COLLECTION_PAGE_LINKS_TO_FOLLOW ,
129+ ) . pipe (
130+ getFirstCompletedRemoteData ( ) ,
131+ map ( data => data ?. payload ) ,
132+ ) ;
111133 this . setAudits ( ) ;
112134 } ) ;
113135 }
@@ -118,17 +140,35 @@ export class ObjectAuditOverviewComponent implements OnInit {
118140 setAudits ( ) {
119141 const config$ = this . paginationService . getFindListOptions ( this . pageConfig . id , this . config , this . pageConfig ) ;
120142 const isAdmin$ = this . isCurrentUserAdmin ( ) ;
121- this . auditsRD$ = combineLatest ( [ isAdmin$ , config$ ] ) . pipe (
122- mergeMap ( ( [ isAdmin , config ] ) => {
143+ const parentCommunity$ = this . owningCollection$ . pipe (
144+ switchMap ( collection => collection . parentCommunity ) ,
145+ getFirstCompletedRemoteData ( ) ,
146+ map ( data => data ?. payload ) ,
147+ ) ;
148+
149+
150+ this . auditsRD$ = combineLatest ( [ isAdmin$ , config$ , this . owningCollection$ , parentCommunity$ ] ) . pipe (
151+ mergeMap ( ( [ isAdmin , config , owningCollection , parentCommunity ] ) => {
123152 if ( isAdmin ) {
124- return this . auditService . findByObject ( this . object . id , config ) ;
153+ return this . auditService . findByObject ( this . object . id , config , owningCollection . id , parentCommunity . id ) ;
125154 }
155+
156+ return of ( null ) ;
126157 } ) ,
127158 ) ;
128159 }
129160
130161 isCurrentUserAdmin ( ) : Observable < boolean > {
131- return this . authorizationService . isAuthorized ( FeatureID . AdministratorOf , undefined , undefined ) ;
162+ return combineLatest ( [
163+ this . authorizationService . isAuthorized ( FeatureID . IsCollectionAdmin ) ,
164+ this . authorizationService . isAuthorized ( FeatureID . IsCommunityAdmin ) ,
165+ this . authorizationService . isAuthorized ( FeatureID . AdministratorOf ) ,
166+ ] ) . pipe (
167+ map ( ( [ isCollectionAdmin , isCommunityAdmin , isSiteAdmin ] ) => {
168+ return isCollectionAdmin || isCommunityAdmin || isSiteAdmin ;
169+ } ) ,
170+ take ( 1 ) ,
171+ ) ;
132172 }
133173
134174 /**
0 commit comments