Merge pull request #1640 from atmire/w2p-90948_More-informative-error-for-Workflow-group-delete

Show notifications when failing to create/delete role Groups
This commit is contained in:
Tim Donohue
2022-05-24 16:46:30 -05:00
committed by GitHub
6 changed files with 64 additions and 3 deletions

View File

@@ -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();

View File

@@ -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();

View File

@@ -4,7 +4,7 @@
*ngVar="group$ | async as group">
<h5 class="w-100">
{{'comcol-role.edit.' + (comcolRole$ | async)?.name + '.name' | translate}}
{{ roleName$ | async }}
</h5>
<div class="mt-2 mb-2">

View File

@@ -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();
});
});
});
});

View File

@@ -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<boolean>;
/**
* The human-readable name of this role
*/
roleName$: Observable<string>;
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`);
}
}

View File

@@ -1105,10 +1105,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",