diff --git a/src/app/collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts b/src/app/collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts
index 985290a592..5a8ca5b7ab 100644
--- a/src/app/collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts
+++ b/src/app/collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts
@@ -13,6 +13,8 @@ import { RouterTestingModule } from '@angular/router/testing';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ComcolModule } from '../../../shared/comcol/comcol.module';
+import { NotificationsService } from '../../../shared/notifications/notifications.service';
+import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
describe('CollectionRolesComponent', () => {
@@ -79,6 +81,7 @@ describe('CollectionRolesComponent', () => {
{ provide: ActivatedRoute, useValue: route },
{ provide: RequestService, useValue: requestService },
{ provide: GroupDataService, useValue: groupDataService },
+ { provide: NotificationsService, useClass: NotificationsServiceStub }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
diff --git a/src/app/community-page/edit-community-page/community-roles/community-roles.component.spec.ts b/src/app/community-page/edit-community-page/community-roles/community-roles.component.spec.ts
index d1188df02d..baea5fb9d0 100644
--- a/src/app/community-page/edit-community-page/community-roles/community-roles.component.spec.ts
+++ b/src/app/community-page/edit-community-page/community-roles/community-roles.component.spec.ts
@@ -13,6 +13,8 @@ import { RouterTestingModule } from '@angular/router/testing';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ComcolModule } from '../../../shared/comcol/comcol.module';
+import { NotificationsService } from '../../../shared/notifications/notifications.service';
+import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
describe('CommunityRolesComponent', () => {
@@ -64,6 +66,7 @@ describe('CommunityRolesComponent', () => {
{ provide: ActivatedRoute, useValue: route },
{ provide: RequestService, useValue: requestService },
{ provide: GroupDataService, useValue: groupDataService },
+ { provide: NotificationsService, useClass: NotificationsServiceStub }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.html b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.html
index b0a319b4ff..905186a232 100644
--- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.html
+++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.html
@@ -4,7 +4,7 @@
*ngVar="group$ | async as group">
- {{'comcol-role.edit.' + (comcolRole$ | async)?.name + '.name' | translate}}
+ {{ roleName$ | async }}
diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts
index 175abe48e4..59fc95b67f 100644
--- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts
+++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts
@@ -10,6 +10,8 @@ import { RouterTestingModule } from '@angular/router/testing';
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ComcolModule } from '../../../comcol.module';
+import { NotificationsService } from '../../../../notifications/notifications.service';
+import { NotificationsServiceStub } from '../../../../testing/notifications-service.stub';
describe('ComcolRoleComponent', () => {
@@ -20,6 +22,7 @@ describe('ComcolRoleComponent', () => {
let group;
let statusCode;
let comcolRole;
+ let notificationsService;
const requestService = { hasByHref$: () => observableOf(true) };
@@ -40,6 +43,7 @@ describe('ComcolRoleComponent', () => {
providers: [
{ provide: GroupDataService, useValue: groupService },
{ provide: RequestService, useValue: requestService },
+ { provide: NotificationsService, useClass: NotificationsServiceStub }
], schemas: [
NO_ERRORS_SCHEMA
]
@@ -59,12 +63,14 @@ describe('ComcolRoleComponent', () => {
fixture = TestBed.createComponent(ComcolRoleComponent);
comp = fixture.componentInstance;
de = fixture.debugElement;
+ notificationsService = TestBed.inject(NotificationsService);
comcolRole = {
name: 'test role name',
href: 'test role link',
};
comp.comcolRole = comcolRole;
+ comp.roleName$ = observableOf(comcolRole.name);
fixture.detectChanges();
});
@@ -101,6 +107,18 @@ describe('ComcolRoleComponent', () => {
done();
});
});
+
+ describe('when a group cannot be created', () => {
+ beforeEach(() => {
+ groupService.createComcolGroup.and.returnValue(createFailedRemoteDataObject$());
+ de.query(By.css('.btn.create')).nativeElement.click();
+ });
+
+ it('should show an error notification', (done) => {
+ expect(notificationsService.error).toHaveBeenCalled();
+ done();
+ });
+ });
});
describe('when the related group is the Anonymous group', () => {
@@ -169,5 +187,17 @@ describe('ComcolRoleComponent', () => {
done();
});
});
+
+ describe('when a group cannot be deleted', () => {
+ beforeEach(() => {
+ groupService.deleteComcolGroup.and.returnValue(createFailedRemoteDataObject$());
+ de.query(By.css('.btn.delete')).nativeElement.click();
+ });
+
+ it('should show an error notification', (done) => {
+ expect(notificationsService.error).toHaveBeenCalled();
+ done();
+ });
+ });
});
});
diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts
index 7ed88fae1c..3091dd0cf0 100644
--- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts
+++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts
@@ -12,6 +12,8 @@ import { HALLink } from '../../../../../core/shared/hal-link.model';
import { getGroupEditRoute } from '../../../../../access-control/access-control-routing-paths';
import { hasNoValue, hasValue } from '../../../../empty.util';
import { NoContent } from '../../../../../core/shared/NoContent.model';
+import { NotificationsService } from '../../../../notifications/notifications.service';
+import { TranslateService } from '@ngx-translate/core';
/**
* Component for managing a community or collection role.
@@ -64,9 +66,16 @@ export class ComcolRoleComponent implements OnInit {
*/
hasCustomGroup$: Observable;
+ /**
+ * The human-readable name of this role
+ */
+ roleName$: Observable;
+
constructor(
protected requestService: RequestService,
protected groupService: GroupDataService,
+ protected notificationsService: NotificationsService,
+ protected translateService: TranslateService,
) {
}
@@ -101,7 +110,12 @@ export class ComcolRoleComponent implements OnInit {
this.groupService.clearGroupsRequests();
this.requestService.setStaleByHrefSubstring(this.comcolRole.href);
} else {
- // TODO show error notification
+ this.notificationsService.error(
+ this.roleName$.pipe(
+ switchMap(role => this.translateService.get('comcol-role.edit.create.error.title', { role }))
+ ),
+ `${rd.statusCode} ${rd.errorMessage}`
+ );
}
});
}
@@ -117,7 +131,12 @@ export class ComcolRoleComponent implements OnInit {
this.groupService.clearGroupsRequests();
this.requestService.setStaleByHrefSubstring(this.comcolRole.href);
} else {
- // TODO show error notification
+ this.notificationsService.error(
+ this.roleName$.pipe(
+ switchMap(role => this.translateService.get('comcol-role.edit.delete.error.title', { role }))
+ ),
+ rd.errorMessage
+ );
}
});
}
@@ -154,5 +173,7 @@ export class ComcolRoleComponent implements OnInit {
this.hasCustomGroup$ = this.group$.pipe(
map((group: Group) => hasValue(group) && group.name !== 'Anonymous'),
);
+
+ this.roleName$ = this.translateService.get(`comcol-role.edit.${this.comcolRole.name}.name`);
}
}
diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5
index f742273edb..9121be759b 100644
--- a/src/assets/i18n/en.json5
+++ b/src/assets/i18n/en.json5
@@ -1082,10 +1082,14 @@
"comcol-role.edit.create": "Create",
+ "comcol-role.edit.create.error.title": "Failed to create a group for the '{{ role }}' role",
+
"comcol-role.edit.restrict": "Restrict",
"comcol-role.edit.delete": "Delete",
+ "comcol-role.edit.delete.error.title": "Failed to delete the '{{ role }}' role's group",
+
"comcol-role.edit.community-admin.name": "Administrators",