Skip to content

Commit 2f94d77

Browse files
authored
Merge pull request DSpace#5483 from guillermo-escire/feature/5435
Fix DSpace#5435: show permission denied message when 403 on collection mapper
2 parents f93c623 + 8d7b56d commit 2f94d77

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

src/app/item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ describe('ItemCollectionMapperComponent', () => {
180180
expect(notificationsService.success).not.toHaveBeenCalled();
181181
expect(notificationsService.error).toHaveBeenCalled();
182182
});
183+
184+
it('should display a permission error message if mapping returns 403', () => {
185+
spyOn(itemDataService, 'mapToCollection').and.returnValue(createFailedRemoteDataObject$('Forbidden', 403));
186+
comp.mapCollections(ids);
187+
expect(notificationsService.success).not.toHaveBeenCalled();
188+
expect(notificationsService.error).toHaveBeenCalled();
189+
});
183190
});
184191

185192
describe('removeMappings', () => {
@@ -197,6 +204,13 @@ describe('ItemCollectionMapperComponent', () => {
197204
expect(notificationsService.success).not.toHaveBeenCalled();
198205
expect(notificationsService.error).toHaveBeenCalled();
199206
});
207+
208+
it('should display a permission error message if removal returns 403', () => {
209+
spyOn(itemDataService, 'removeMappingFromCollection').and.returnValue(createFailedRemoteDataObject$('Forbidden', 403));
210+
comp.removeMappings(ids);
211+
expect(notificationsService.success).not.toHaveBeenCalled();
212+
expect(notificationsService.error).toHaveBeenCalled();
213+
});
200214
});
201215

202216
describe('tabChange', () => {

src/app/item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,28 @@ export class ItemCollectionMapperComponent implements OnInit {
287287
this.shouldUpdate$.next(true);
288288
}
289289
if (unsuccessful.length > 0) {
290-
const unsuccessMessages = observableCombineLatest([
291-
this.translateService.get(`${messagePrefix}.error.head`),
292-
this.translateService.get(`${messagePrefix}.error.content`, { amount: unsuccessful.length }),
293-
]);
290+
const forbidden = unsuccessful.filter((response: RemoteData<NoContent>) => response.statusCode === 403);
291+
const otherErrors = unsuccessful.filter((response: RemoteData<NoContent>) => response.statusCode !== 403);
294292

295-
unsuccessMessages.subscribe(([head, content]) => {
296-
this.notificationsService.error(head, content);
297-
});
293+
if (forbidden.length > 0) {
294+
const forbiddenMessages = observableCombineLatest([
295+
this.translateService.get(`${messagePrefix}.error.forbidden.head`),
296+
this.translateService.get(`${messagePrefix}.error.forbidden.content`),
297+
]);
298+
forbiddenMessages.subscribe(([head, content]) => {
299+
this.notificationsService.error(head, content);
300+
});
301+
}
302+
303+
if (otherErrors.length > 0) {
304+
const unsuccessMessages = observableCombineLatest([
305+
this.translateService.get(`${messagePrefix}.error.head`),
306+
this.translateService.get(`${messagePrefix}.error.content`, { amount: otherErrors.length }),
307+
]);
308+
unsuccessMessages.subscribe(([head, content]) => {
309+
this.notificationsService.error(head, content);
310+
});
311+
}
298312
}
299313
this.switchToFirstTab();
300314
});

src/assets/i18n/en.json5

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,6 +2643,10 @@
26432643

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

2646+
"item.edit.item-mapper.notifications.add.error.forbidden.head": "Permission denied",
2647+
2648+
"item.edit.item-mapper.notifications.add.error.forbidden.content": "You do not have permission to map this item to a collection.",
2649+
26462650
"item.edit.item-mapper.notifications.add.error.head": "Mapping errors",
26472651

26482652
"item.edit.item-mapper.notifications.add.success.content": "Successfully mapped item to {{amount}} collections.",
@@ -2651,6 +2655,10 @@
26512655

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

2658+
"item.edit.item-mapper.notifications.remove.error.forbidden.head": "Permission denied",
2659+
2660+
"item.edit.item-mapper.notifications.remove.error.forbidden.content": "You do not have permission to remove this item from a collection.",
2661+
26542662
"item.edit.item-mapper.notifications.remove.error.head": "Removal of mapping errors",
26552663

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

0 commit comments

Comments
 (0)