Skip to content

Commit cc54e40

Browse files
[DSC-1940] fix audit errors, enable audits for comm and coll admins
1 parent f3c3b8f commit cc54e40

3 files changed

Lines changed: 63 additions & 12 deletions

File tree

src/app/audit-page/object-audit-overview/object-audit-overview.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h4 class="mt-4 mb-4">{{ object.name }} (<em>{{object.type}}</em>)</h4>
6161

6262
</ng-container>
6363

64-
<h4 class="mt-4 mb-4" *ngIf="(auditsRD$ | async).statusCode === 404">{{'audit.object.overview.disabled.message' | translate}}</h4>
64+
<h4 class="mt-4 mb-4" *ngIf="(auditsRD$ | async)?.statusCode === 404">{{'audit.object.overview.disabled.message' | translate}}</h4>
6565

6666
</ng-container>
6767

src/app/audit-page/object-audit-overview/object-audit-overview.component.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { 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

66
import { RemoteData } from '../../core/data/remote-data';
77
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
@@ -18,6 +18,10 @@ import { AuthService } from '../../core/auth/auth.service';
1818
import { PaginatedList } from '../../core/data/paginated-list.model';
1919
import { PaginationService } from '../../core/pagination/pagination.service';
2020
import { 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
/**

src/app/core/audit/audit-data.service.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { SearchDataImpl } from '../data/base/search-data';
2727
import { DeleteDataImpl } from '../data/base/delete-data';
2828
import { FindAllData, FindAllDataImpl } from '../data/base/find-all-data';
2929
import { DSONameService } from '../breadcrumbs/dso-name.service';
30+
import { hasValue } from '../../shared/empty.util';
3031

3132
export const AUDIT_PERSON_NOT_AVAILABLE = 'n/a';
3233

@@ -60,12 +61,23 @@ export class AuditDataService extends IdentifiableDataService<Audit>{
6061
*
6162
* @param objectId The objectId id
6263
* @param options The [[FindListOptions]] object
64+
* @param collUuid The Uuid of the collection
65+
* @param commUuid The Uuid of the community
6366
* @return Observable<RemoteData<PaginatedList<Audit>>>
6467
*/
65-
findByObject(objectId: string, options: FindListOptions = {}): Observable<RemoteData<PaginatedList<Audit>>> {
68+
findByObject(objectId: string, options: FindListOptions = {}, collUuid?: string, commUuid?: string): Observable<RemoteData<PaginatedList<Audit>>> {
6669
const searchMethod = AUDIT_FIND_BY_OBJECT_SEARCH_METHOD;
70+
const searchParams = [new RequestParam('object', objectId)];
71+
72+
if (hasValue(commUuid)) {
73+
searchParams.push(new RequestParam('commUuid', commUuid));
74+
}
75+
76+
if (hasValue(collUuid)) {
77+
searchParams.push(new RequestParam('collUuid', collUuid));
78+
}
6779
const optionsWithObject = Object.assign(new FindListOptions(), options, {
68-
searchParams: [new RequestParam('object', objectId)]
80+
searchParams
6981
});
7082
return this.searchData.searchBy(searchMethod, optionsWithObject, true, true, followLink('eperson'));
7183
}

0 commit comments

Comments
 (0)