+ {{groupDto.group.id}} |
+ {{groupDto.group.name}} |
+ {{(getMembers(groupDto.group) | async)?.payload?.totalElements + (getSubgroups(groupDto.group) | async)?.payload?.totalElements}} |
-
-
@@ -75,7 +75,7 @@
-
+
{{messagePrefix + 'no-items' | translate}}
diff --git a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts
index deca1b951b..e09a49d870 100644
--- a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts
+++ b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.spec.ts
@@ -6,7 +6,8 @@ import { BrowserModule, By } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
-import { Observable } from 'rxjs/internal/Observable';
+import { Observable, of as observableOf } from 'rxjs';
+import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
import { PaginatedList } from '../../../core/data/paginated-list';
import { RemoteData } from '../../../core/data/remote-data';
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
@@ -30,6 +31,7 @@ describe('GroupRegistryComponent', () => {
let fixture: ComponentFixture ;
let ePersonDataServiceStub: any;
let groupsDataServiceStub: any;
+ let authorizationService: AuthorizationDataService;
let mockGroups;
let mockEPeople;
@@ -77,6 +79,9 @@ describe('GroupRegistryComponent', () => {
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [result]));
}
};
+ authorizationService = jasmine.createSpyObj('authorizationService', {
+ isAuthorized: observableOf(true)
+ });
TestBed.configureTestingModule({
imports: [CommonModule, NgbModule, FormsModule, ReactiveFormsModule, BrowserModule,
TranslateModule.forRoot({
@@ -93,6 +98,7 @@ describe('GroupRegistryComponent', () => {
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: RouteService, useValue: routeServiceStub },
{ provide: Router, useValue: new RouterMock() },
+ { provide: AuthorizationDataService, useValue: authorizationService },
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
diff --git a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts
index 6f606b6801..3c780f5e29 100644
--- a/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts
+++ b/src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts
@@ -1,16 +1,22 @@
-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, Observable } from 'rxjs';
+import { Subscription } from 'rxjs/internal/Subscription';
+import { map, switchMap, take } from 'rxjs/operators';
+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 { 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 { 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 +29,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 +43,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>>;
+ groups$: BehaviorSubject>> = new BehaviorSubject>>({} 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> = new BehaviorSubject>({} as any);
+
+ /**
+ * An observable for the pageInfo, needed to pass to the pagination component
+ */
+ pageInfoState$: BehaviorSubject = new BehaviorSubject(undefined);
// The search form
searchForm;
@@ -47,13 +63,19 @@ 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 translateService: TranslateService,
private notificationsService: NotificationsService,
private formBuilder: FormBuilder,
protected routeService: RouteService,
- private router: Router) {
+ private router: Router,
+ private authorizationService: AuthorizationDataService) {
this.currentSearchQuery = '';
this.searchForm = this.formBuilder.group(({
query: this.currentSearchQuery,
@@ -84,28 +106,51 @@ 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>) => {
+ this.groups$.next(groupsRD)
+ }
+ ));
+
+ this.subs.push(this.groups$.pipe(
+ getAllSucceededRemoteDataPayload(),
+ switchMap((groups) => {
+ return combineLatest(...groups.page.map((group) => {
+ return this.authorizationService.isAuthorized(FeatureID.CanDelete, hasValue(group) ? group.self : undefined).pipe(
+ map((authorized: boolean) => {
+ const groupDtoModel: GroupDtoModel = new GroupDtoModel();
+ groupDtoModel.ableToDelete = authorized;
+ groupDtoModel.group = group;
+ return groupDtoModel;
+ })
+ );
+ })).pipe(map((dtos: GroupDtoModel[]) => {
+ return new PaginatedList(groups.pageInfo, dtos);
+ }))
+ })).subscribe((value: PaginatedList) => {
+ 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.forceUpdateGroup();
+ } 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 }));
+ }
+ })
}
}
@@ -151,4 +196,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());
+ }
}
diff --git a/src/app/core/eperson/group-data.service.ts b/src/app/core/eperson/group-data.service.ts
index d42ba392f3..4543f33cf0 100644
--- a/src/app/core/eperson/group-data.service.ts
+++ b/src/app/core/eperson/group-data.service.ts
@@ -16,7 +16,7 @@ import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { RequestParam } from '../cache/models/request-param.model';
import { ObjectCacheService } from '../cache/object-cache.service';
-import { RestResponse } from '../cache/response.models';
+import { ErrorResponse, RestResponse } from '../cache/response.models';
import { DataService } from '../data/data.service';
import { DSOChangeAnalyzer } from '../data/dso-change-analyzer.service';
import { PaginatedList } from '../data/paginated-list';
@@ -125,10 +125,13 @@ export class GroupDataService extends DataService {
/**
* Method to delete a group
- * @param id The group id to delete
+ * @param group The group to delete
*/
- public deleteGroup(group: Group): Observable {
- return this.delete(group.id).pipe(map((response: RestResponse) => response.isSuccessful));
+ public deleteGroup(group: Group): Observable<[boolean, string]> {
+ return this.delete(group.id).pipe(map((response: RestResponse) => {
+ const errorMessage = response.isSuccessful === false ? (response as ErrorResponse).errorMessage : undefined;
+ return [response.isSuccessful, errorMessage];
+ }));
}
/**
diff --git a/src/app/core/eperson/models/group-dto.model.ts b/src/app/core/eperson/models/group-dto.model.ts
new file mode 100644
index 0000000000..db167dc6b2
--- /dev/null
+++ b/src/app/core/eperson/models/group-dto.model.ts
@@ -0,0 +1,17 @@
+import { Group } from './group.model';
+
+/**
+ * This class serves as a Data Transfer Model that contains the Group and whether or not it's able to be deleted
+ */
+export class GroupDtoModel {
+
+ /**
+ * The Group linked to this object
+ */
+ public group: Group;
+ /**
+ * Whether or not the linked Group is able to be deleted
+ */
+ public ableToDelete: boolean;
+
+}
diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5
index c0c2293e10..90efbe3546 100644
--- a/src/assets/i18n/en.json5
+++ b/src/assets/i18n/en.json5
@@ -308,7 +308,9 @@
"admin.access-control.groups.notification.deleted.success": "Successfully deleted group \"{{name}}\"",
- "admin.access-control.groups.notification.deleted.failure": "Failed to delete group \"{{name}}\"",
+ "admin.access-control.groups.notification.deleted.failure.title": "Failed to delete group \"{{name}}\"",
+
+ "admin.access-control.groups.notification.deleted.failure.content": "Cause: \"{{cause}}\"",
"admin.access-control.groups.form.head.create": "Create group",
@@ -325,6 +327,22 @@
"admin.access-control.groups.form.notification.created.failure.groupNameInUse": "Failed to create Group with name: \"{{name}}\", make sure the name is not already in use.",
+ "admin.access-control.groups.form.actions.delete": "Delete Group",
+
+ "admin.access-control.groups.form.delete-group.modal.header": "Delete Group \"{{ dsoName }}\"",
+
+ "admin.access-control.groups.form.delete-group.modal.info": "Are you sure you want to delete Group \"{{ dsoName }}\"",
+
+ "admin.access-control.groups.form.delete-group.modal.cancel": "Cancel",
+
+ "admin.access-control.groups.form.delete-group.modal.confirm": "Delete",
+
+ "admin.access-control.groups.form.notification.deleted.success": "Successfully deleted group \"{{ name }}\"",
+
+ "admin.access-control.groups.form.notification.deleted.failure.title": "Failed to delete group \"{{ name }}\"",
+
+ "admin.access-control.groups.form.notification.deleted.failure.content": "Cause: \"{{ cause }}\"",
+
"admin.access-control.groups.form.members-list.head": "EPeople",
"admin.access-control.groups.form.members-list.search.head": "Add EPeople",
|