Merge remote-tracking branch 'remotes/origin/main' into upgrade_angular10

# Conflicts:
#	package.json
#	server.ts
#	src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts
#	src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.ts
#	src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts
#	src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts
#	src/app/+collection-page/collection-page.component.ts
#	src/app/+item-page/edit-item-page/item-page-reinstate.guard.ts
#	src/app/+item-page/edit-item-page/item-page-withdraw.guard.ts
#	src/app/+item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts
#	src/app/+item-page/edit-item-page/item-relationships/item-relationships.component.ts
#	src/app/+item-page/item-page-administrator.guard.ts
#	src/app/app-routing.module.ts
#	src/app/community-list-page/community-list-service.ts
#	src/app/core/data/entity-type.service.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/dso-page-feature.guard.spec.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/feature-authorization.guard.spec.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/feature-authorization.guard.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/site-administrator.guard.ts
#	src/app/core/data/feature-authorization/feature-authorization-guard/site-register.guard.ts
#	src/app/core/data/object-updates/object-updates.reducer.ts
#	src/app/core/shared/operators.ts
#	src/app/process-page/detail/process-detail.component.ts
#	src/app/shared/comcol-forms/delete-comcol-page/delete-comcol-page.component.ts
#	src/app/shared/dso-selector/dso-selector/dso-selector.component.ts
#	src/app/shared/input-suggestions/filter-suggestions/filter-input-suggestions.component.ts
#	src/app/shared/object-grid/grid-thumbnail/grid-thumbnail.component.ts
#	src/app/shared/shared.module.ts
#	yarn.lock
This commit is contained in:
Giuseppe Digilio
2020-12-04 11:36:48 +01:00
254 changed files with 4580 additions and 1029 deletions

View File

@@ -1,16 +1,26 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { BehaviorSubject, combineLatest as observableCombineLatest, Subscription, Observable, of as observableOf } from 'rxjs';
import { filter } from 'rxjs/internal/operators/filter';
import { ObservedValueOf } from 'rxjs/internal/types';
import { catchError, map, switchMap, take } from 'rxjs/operators';
import { DSpaceObjectDataService } from '../../../core/data/dspace-object-data.service';
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
import { PaginatedList } from '../../../core/data/paginated-list';
import { RemoteData } from '../../../core/data/remote-data';
import { RequestService } from '../../../core/data/request.service';
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
import { GroupDataService } from '../../../core/eperson/group-data.service';
import { EPerson } from '../../../core/eperson/models/eperson.model';
import { GroupDtoModel } from '../../../core/eperson/models/group-dto.model';
import { Group } from '../../../core/eperson/models/group.model';
import { RouteService } from '../../../core/services/route.service';
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
import { getAllSucceededRemoteDataPayload } from '../../../core/shared/operators';
import { PageInfo } from '../../../core/shared/page-info.model';
import { hasValue } from '../../../shared/empty.util';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
@@ -23,7 +33,7 @@ import { PaginationComponentOptions } from '../../../shared/pagination/paginatio
* A component used for managing all existing groups within the repository.
* The admin can create, edit or delete groups here.
*/
export class GroupsRegistryComponent implements OnInit {
export class GroupsRegistryComponent implements OnInit, OnDestroy {
messagePrefix = 'admin.access-control.groups.';
@@ -37,9 +47,19 @@ export class GroupsRegistryComponent implements OnInit {
});
/**
* A list of all the current groups within the repository or the result of the search
* A list of all the current Groups within the repository or the result of the search
*/
groups: Observable<RemoteData<PaginatedList<Group>>>;
groups$: BehaviorSubject<RemoteData<PaginatedList<Group>>> = new BehaviorSubject<RemoteData<PaginatedList<Group>>>({} as any);
/**
* A BehaviorSubject with the list of GroupDtoModel objects made from the Groups in the repository or
* as the result of the search
*/
groupsDto$: BehaviorSubject<PaginatedList<GroupDtoModel>> = new BehaviorSubject<PaginatedList<GroupDtoModel>>({} as any);
/**
* An observable for the pageInfo, needed to pass to the pagination component
*/
pageInfoState$: BehaviorSubject<PageInfo> = new BehaviorSubject<PageInfo>(undefined);
// The search form
searchForm;
@@ -47,13 +67,21 @@ export class GroupsRegistryComponent implements OnInit {
// Current search in groups registry
currentSearchQuery: string;
/**
* List of subscriptions
*/
subs: Subscription[] = [];
constructor(public groupService: GroupDataService,
private ePersonDataService: EPersonDataService,
private dSpaceObjectDataService: DSpaceObjectDataService,
private translateService: TranslateService,
private notificationsService: NotificationsService,
private formBuilder: FormBuilder,
protected routeService: RouteService,
private router: Router) {
private router: Router,
private authorizationService: AuthorizationDataService,
public requestService: RequestService) {
this.currentSearchQuery = '';
this.searchForm = this.formBuilder.group(({
query: this.currentSearchQuery,
@@ -84,37 +112,69 @@ export class GroupsRegistryComponent implements OnInit {
this.currentSearchQuery = query;
this.config.currentPage = 1;
}
this.groups = this.groupService.searchGroups(this.currentSearchQuery.trim(), {
this.subs.push(this.groupService.searchGroups(this.currentSearchQuery.trim(), {
currentPage: this.config.currentPage,
elementsPerPage: this.config.pageSize
});
}).subscribe((groupsRD: RemoteData<PaginatedList<Group>>) => {
this.groups$.next(groupsRD);
this.pageInfoState$.next(groupsRD.payload.pageInfo);
}
));
this.subs.push(this.groups$.pipe(
getAllSucceededRemoteDataPayload(),
switchMap((groups: PaginatedList<Group>) => {
return observableCombineLatest(...groups.page.map((group: Group) => {
return observableCombineLatest(
this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined),
this.hasLinkedDSO(group),
(isAuthorized: ObservedValueOf<Observable<boolean>>, hasLinkedDSO: ObservedValueOf<Observable<boolean>>) => {
const groupDtoModel: GroupDtoModel = new GroupDtoModel();
groupDtoModel.ableToDelete = isAuthorized && !hasLinkedDSO;
groupDtoModel.group = group;
return groupDtoModel;
}
)
})).pipe(map((dtos: GroupDtoModel[]) => {
return new PaginatedList(groups.pageInfo, dtos);
}))
})).subscribe((value: PaginatedList<GroupDtoModel>) => {
this.groupsDto$.next(value);
this.pageInfoState$.next(value.pageInfo);
}));
}
/**
* Delete Group
*/
deleteGroup(group: Group) {
// TODO (backend)
console.log('TODO implement editGroup', group);
this.notificationsService.error('TODO implement deleteGroup (not yet implemented in backend)');
if (hasValue(group.id)) {
this.groupService.deleteGroup(group).pipe(take(1)).subscribe((success: boolean) => {
if (success) {
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.name }));
this.forceUpdateGroup();
} else {
this.notificationsService.error(this.translateService.get(this.messagePrefix + 'notification.deleted.failure', { name: group.name }));
}
this.groupService.deleteGroup(group).pipe(take(1))
.subscribe(([success, optionalErrorMessage]: [boolean, string]) => {
if (success) {
this.notificationsService.success(this.translateService.get(this.messagePrefix + 'notification.deleted.success', { name: group.name }));
this.reset();
} else {
this.notificationsService.error(
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.title', { name: group.name }),
this.translateService.get(this.messagePrefix + 'notification.deleted.failure.content', { cause: optionalErrorMessage }));
}
});
}
}
/**
* Force-update the list of groups by first clearing the cache related to groups, then performing a new REST call
* This method will ensure that the page gets reset and that the cache is cleared
*/
public forceUpdateGroup() {
this.groupService.clearGroupsRequests();
this.search({ query: this.currentSearchQuery });
reset() {
this.groupService.getBrowseEndpoint().pipe(
switchMap((href) => this.requestService.removeByHrefSubstring(href)),
filter((isCached) => isCached),
take(1)
).subscribe(() => {
this.cleanupSubscribes();
this.search({ query: this.currentSearchQuery });
});
}
/**
@@ -133,6 +193,23 @@ export class GroupsRegistryComponent implements OnInit {
return this.groupService.findAllByHref(group._links.subgroups.href);
}
/**
* Check if group has a linked object (community or collection linked to a workflow group)
* @param group
*/
hasLinkedDSO(group: Group): Observable<boolean> {
return this.dSpaceObjectDataService.findByHref(group._links.object.href).pipe(
map((rd: RemoteData<DSpaceObject>) => {
if (hasValue(rd) && hasValue(rd.payload)) {
return true;
} else {
return false
}
}),
catchError(() => observableOf(false)),
);
}
/**
* Reset all input-fields to be empty and search all search
*/
@@ -151,4 +228,15 @@ export class GroupsRegistryComponent implements OnInit {
getOptionalComColFromName(groupName: string): string {
return this.groupService.getUUIDFromString(groupName);
}
/**
* Unsub all subscriptions
*/
ngOnDestroy(): void {
this.cleanupSubscribes();
}
cleanupSubscribes() {
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
}
}