diff --git a/src/app/core/resource-policy/resource-policy.service.ts b/src/app/core/resource-policy/resource-policy.service.ts index f4f70a73e2..ae77ca84d6 100644 --- a/src/app/core/resource-policy/resource-policy.service.ts +++ b/src/app/core/resource-policy/resource-policy.service.ts @@ -235,15 +235,16 @@ export class ResourcePolicyService { /** * Update the target of the resource policy + * @param resourcePolicyId the ID of the resource policy * @param resourcePolicyHref the link to the resource policy * @param uuid the UUID of the target to which the permission is being granted * @param type the type of the target (eperson or group) to which the permission is being granted */ - updateTarget(resourcePolicyHref: string, uuid: string, type: string): Observable> { + updateTarget(resourcePolicyId: string, resourcePolicyHref: string, uuid: string, type: string): Observable> { const targetService = type === 'eperson' ? this.ePersonService : this.groupService; - const ep$ = targetService.getBrowseEndpoint().pipe( + const targetEndpoint$ = targetService.getBrowseEndpoint().pipe( take(1), map((endpoint: string) =>`${endpoint}/${uuid}`), ); @@ -255,8 +256,11 @@ export class ResourcePolicyService { const requestId = this.requestService.generateRequestId(); - return ep$.pipe(switchMap((ep) => { - const request = new PostRequest(requestId, resourcePolicyHref, ep, options); + this.requestService.setStaleByHrefSubstring(`${this.dataService.getLinkPath()}/${resourcePolicyId}/${type}`); + + return targetEndpoint$.pipe(switchMap((targetEndpoint) => { + const resourceEndpoint = resourcePolicyHref + '/' + type + const request = new PostRequest(requestId, resourceEndpoint, targetEndpoint, options); Object.assign(request, { getResponseParser(): GenericConstructor { return StatusCodeOnlyResponseParsingService; diff --git a/src/app/shared/resource-policies/edit/resource-policy-edit.component.ts b/src/app/shared/resource-policies/edit/resource-policy-edit.component.ts index d2c1b6dd0d..1c5a0c4a5f 100644 --- a/src/app/shared/resource-policies/edit/resource-policy-edit.component.ts +++ b/src/app/shared/resource-policies/edit/resource-policy-edit.component.ts @@ -90,7 +90,7 @@ export class ResourcePolicyEditComponent implements OnInit { }); const updateTargetSucceeded$ = event.updateTarget ? this.resourcePolicyService.updateTarget( - this.resourcePolicy._links.self.href, event.target.uuid, event.target.type + this.resourcePolicy.id, this.resourcePolicy._links.self.href, event.target.uuid, event.target.type ).pipe( getFirstCompletedRemoteData(), map((responseRD) => responseRD && responseRD.hasSucceeded) @@ -107,7 +107,11 @@ export class ResourcePolicyEditComponent implements OnInit { if (updateTargetSucceeded && updateResourcePolicySucceeded) { this.notificationsService.success(null, this.translate.get('resource-policies.edit.page.success.content')); this.redirectToAuthorizationsPage(); - } else { + } else if (updateResourcePolicySucceeded) { // everything except target has been updated + this.notificationsService.error(null, this.translate.get('resource-policies.edit.page.target-failure.content')); + } else if (updateTargetSucceeded) { // only target has been updated + this.notificationsService.error(null, this.translate.get('resource-policies.edit.page.other-failure.content')); + } else { // nothing has been updated this.notificationsService.error(null, this.translate.get('resource-policies.edit.page.failure.content')); } } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 91d199061d..3fc6ebe0f7 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -3122,6 +3122,10 @@ "resource-policies.edit.page.failure.content": "An error occurred while editing the resource policy.", + "resource-policies.edit.page.target-failure.content": "An error occurred while editing the target (ePerson or group) of the resource policy.", + + "resource-policies.edit.page.other-failure.content": "An error occurred while editing the resource policy. The target (ePerson or group) has been successfully updated.", + "resource-policies.edit.page.success.content": "Operation successful", "resource-policies.edit.page.title": "Edit resource policy",