mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
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:
@@ -13,6 +13,8 @@ import { RouterTestingModule } from '@angular/router/testing';
|
|||||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { ComcolModule } from '../../../shared/comcol/comcol.module';
|
import { ComcolModule } from '../../../shared/comcol/comcol.module';
|
||||||
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||||
|
|
||||||
describe('CollectionRolesComponent', () => {
|
describe('CollectionRolesComponent', () => {
|
||||||
|
|
||||||
@@ -79,6 +81,7 @@ describe('CollectionRolesComponent', () => {
|
|||||||
{ provide: ActivatedRoute, useValue: route },
|
{ provide: ActivatedRoute, useValue: route },
|
||||||
{ provide: RequestService, useValue: requestService },
|
{ provide: RequestService, useValue: requestService },
|
||||||
{ provide: GroupDataService, useValue: groupDataService },
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
|
{ provide: NotificationsService, useClass: NotificationsServiceStub }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -13,6 +13,8 @@ import { RouterTestingModule } from '@angular/router/testing';
|
|||||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { ComcolModule } from '../../../shared/comcol/comcol.module';
|
import { ComcolModule } from '../../../shared/comcol/comcol.module';
|
||||||
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||||
|
|
||||||
describe('CommunityRolesComponent', () => {
|
describe('CommunityRolesComponent', () => {
|
||||||
|
|
||||||
@@ -64,6 +66,7 @@ describe('CommunityRolesComponent', () => {
|
|||||||
{ provide: ActivatedRoute, useValue: route },
|
{ provide: ActivatedRoute, useValue: route },
|
||||||
{ provide: RequestService, useValue: requestService },
|
{ provide: RequestService, useValue: requestService },
|
||||||
{ provide: GroupDataService, useValue: groupDataService },
|
{ provide: GroupDataService, useValue: groupDataService },
|
||||||
|
{ provide: NotificationsService, useClass: NotificationsServiceStub }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
*ngVar="group$ | async as group">
|
*ngVar="group$ | async as group">
|
||||||
|
|
||||||
<h5 class="w-100">
|
<h5 class="w-100">
|
||||||
{{'comcol-role.edit.' + (comcolRole$ | async)?.name + '.name' | translate}}
|
{{ roleName$ | async }}
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
<div class="mt-2 mb-2">
|
<div class="mt-2 mb-2">
|
||||||
|
@@ -10,6 +10,8 @@ import { RouterTestingModule } from '@angular/router/testing';
|
|||||||
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils';
|
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../../../remote-data.utils';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { ComcolModule } from '../../../comcol.module';
|
import { ComcolModule } from '../../../comcol.module';
|
||||||
|
import { NotificationsService } from '../../../../notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../../../testing/notifications-service.stub';
|
||||||
|
|
||||||
describe('ComcolRoleComponent', () => {
|
describe('ComcolRoleComponent', () => {
|
||||||
|
|
||||||
@@ -20,6 +22,7 @@ describe('ComcolRoleComponent', () => {
|
|||||||
let group;
|
let group;
|
||||||
let statusCode;
|
let statusCode;
|
||||||
let comcolRole;
|
let comcolRole;
|
||||||
|
let notificationsService;
|
||||||
|
|
||||||
const requestService = { hasByHref$: () => observableOf(true) };
|
const requestService = { hasByHref$: () => observableOf(true) };
|
||||||
|
|
||||||
@@ -40,6 +43,7 @@ describe('ComcolRoleComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{ provide: GroupDataService, useValue: groupService },
|
{ provide: GroupDataService, useValue: groupService },
|
||||||
{ provide: RequestService, useValue: requestService },
|
{ provide: RequestService, useValue: requestService },
|
||||||
|
{ provide: NotificationsService, useClass: NotificationsServiceStub }
|
||||||
], schemas: [
|
], schemas: [
|
||||||
NO_ERRORS_SCHEMA
|
NO_ERRORS_SCHEMA
|
||||||
]
|
]
|
||||||
@@ -59,12 +63,14 @@ describe('ComcolRoleComponent', () => {
|
|||||||
fixture = TestBed.createComponent(ComcolRoleComponent);
|
fixture = TestBed.createComponent(ComcolRoleComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
de = fixture.debugElement;
|
de = fixture.debugElement;
|
||||||
|
notificationsService = TestBed.inject(NotificationsService);
|
||||||
|
|
||||||
comcolRole = {
|
comcolRole = {
|
||||||
name: 'test role name',
|
name: 'test role name',
|
||||||
href: 'test role link',
|
href: 'test role link',
|
||||||
};
|
};
|
||||||
comp.comcolRole = comcolRole;
|
comp.comcolRole = comcolRole;
|
||||||
|
comp.roleName$ = observableOf(comcolRole.name);
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
@@ -101,6 +107,18 @@ describe('ComcolRoleComponent', () => {
|
|||||||
done();
|
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', () => {
|
describe('when the related group is the Anonymous group', () => {
|
||||||
@@ -169,5 +187,17 @@ describe('ComcolRoleComponent', () => {
|
|||||||
done();
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -12,6 +12,8 @@ import { HALLink } from '../../../../../core/shared/hal-link.model';
|
|||||||
import { getGroupEditRoute } from '../../../../../access-control/access-control-routing-paths';
|
import { getGroupEditRoute } from '../../../../../access-control/access-control-routing-paths';
|
||||||
import { hasNoValue, hasValue } from '../../../../empty.util';
|
import { hasNoValue, hasValue } from '../../../../empty.util';
|
||||||
import { NoContent } from '../../../../../core/shared/NoContent.model';
|
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.
|
* Component for managing a community or collection role.
|
||||||
@@ -64,9 +66,16 @@ export class ComcolRoleComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
hasCustomGroup$: Observable<boolean>;
|
hasCustomGroup$: Observable<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The human-readable name of this role
|
||||||
|
*/
|
||||||
|
roleName$: Observable<string>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected requestService: RequestService,
|
protected requestService: RequestService,
|
||||||
protected groupService: GroupDataService,
|
protected groupService: GroupDataService,
|
||||||
|
protected notificationsService: NotificationsService,
|
||||||
|
protected translateService: TranslateService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +110,12 @@ export class ComcolRoleComponent implements OnInit {
|
|||||||
this.groupService.clearGroupsRequests();
|
this.groupService.clearGroupsRequests();
|
||||||
this.requestService.setStaleByHrefSubstring(this.comcolRole.href);
|
this.requestService.setStaleByHrefSubstring(this.comcolRole.href);
|
||||||
} else {
|
} 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.groupService.clearGroupsRequests();
|
||||||
this.requestService.setStaleByHrefSubstring(this.comcolRole.href);
|
this.requestService.setStaleByHrefSubstring(this.comcolRole.href);
|
||||||
} else {
|
} 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(
|
this.hasCustomGroup$ = this.group$.pipe(
|
||||||
map((group: Group) => hasValue(group) && group.name !== 'Anonymous'),
|
map((group: Group) => hasValue(group) && group.name !== 'Anonymous'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.roleName$ = this.translateService.get(`comcol-role.edit.${this.comcolRole.name}.name`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1105,10 +1105,14 @@
|
|||||||
|
|
||||||
"comcol-role.edit.create": "Create",
|
"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.restrict": "Restrict",
|
||||||
|
|
||||||
"comcol-role.edit.delete": "Delete",
|
"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",
|
"comcol-role.edit.community-admin.name": "Administrators",
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user