Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ describe('ItemCollectionMapperComponent', () => {
expect(notificationsService.success).not.toHaveBeenCalled();
expect(notificationsService.error).toHaveBeenCalled();
});

it('should display a permission error message if mapping returns 403', () => {
spyOn(itemDataService, 'mapToCollection').and.returnValue(createFailedRemoteDataObject$('Forbidden', 403));
comp.mapCollections(ids);
expect(notificationsService.success).not.toHaveBeenCalled();
expect(notificationsService.error).toHaveBeenCalled();
});
});

describe('removeMappings', () => {
Expand All @@ -197,6 +204,13 @@ describe('ItemCollectionMapperComponent', () => {
expect(notificationsService.success).not.toHaveBeenCalled();
expect(notificationsService.error).toHaveBeenCalled();
});

it('should display a permission error message if removal returns 403', () => {
spyOn(itemDataService, 'removeMappingFromCollection').and.returnValue(createFailedRemoteDataObject$('Forbidden', 403));
comp.removeMappings(ids);
expect(notificationsService.success).not.toHaveBeenCalled();
expect(notificationsService.error).toHaveBeenCalled();
});
});

describe('tabChange', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,28 @@ export class ItemCollectionMapperComponent implements OnInit {
this.shouldUpdate$.next(true);
}
if (unsuccessful.length > 0) {
const unsuccessMessages = observableCombineLatest([
this.translateService.get(`${messagePrefix}.error.head`),
this.translateService.get(`${messagePrefix}.error.content`, { amount: unsuccessful.length }),
]);
const forbidden = unsuccessful.filter((response: RemoteData<NoContent>) => response.statusCode === 403);
const otherErrors = unsuccessful.filter((response: RemoteData<NoContent>) => response.statusCode !== 403);

unsuccessMessages.subscribe(([head, content]) => {
this.notificationsService.error(head, content);
});
if (forbidden.length > 0) {
const forbiddenMessages = observableCombineLatest([
this.translateService.get(`${messagePrefix}.error.forbidden.head`),
this.translateService.get(`${messagePrefix}.error.forbidden.content`),
]);
forbiddenMessages.subscribe(([head, content]) => {
this.notificationsService.error(head, content);
});
}

if (otherErrors.length > 0) {
const unsuccessMessages = observableCombineLatest([
this.translateService.get(`${messagePrefix}.error.head`),
this.translateService.get(`${messagePrefix}.error.content`, { amount: otherErrors.length }),
]);
unsuccessMessages.subscribe(([head, content]) => {
this.notificationsService.error(head, content);
});
}
}
this.switchToFirstTab();
});
Expand Down
8 changes: 8 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,10 @@

"item.edit.item-mapper.notifications.add.error.content": "Errors occurred for mapping of item to {{amount}} collections.",

"item.edit.item-mapper.notifications.add.error.forbidden.head": "Permission denied",

"item.edit.item-mapper.notifications.add.error.forbidden.content": "You do not have permission to map this item to a collection.",

"item.edit.item-mapper.notifications.add.error.head": "Mapping errors",

"item.edit.item-mapper.notifications.add.success.content": "Successfully mapped item to {{amount}} collections.",
Expand All @@ -2521,6 +2525,10 @@

"item.edit.item-mapper.notifications.remove.error.content": "Errors occurred for the removal of the mapping to {{amount}} collections.",

"item.edit.item-mapper.notifications.remove.error.forbidden.head": "Permission denied",

"item.edit.item-mapper.notifications.remove.error.forbidden.content": "You do not have permission to remove this item from a collection.",

"item.edit.item-mapper.notifications.remove.error.head": "Removal of mapping errors",

"item.edit.item-mapper.notifications.remove.success.content": "Successfully removed mapping of item to {{amount}} collections.",
Expand Down
Loading