diff --git a/src/main/java/edu/hawaii/its/api/controller/GroupingsRestController.java b/src/main/java/edu/hawaii/its/api/controller/GroupingsRestController.java index 350add233..962813dfa 100644 --- a/src/main/java/edu/hawaii/its/api/controller/GroupingsRestController.java +++ b/src/main/java/edu/hawaii/its/api/controller/GroupingsRestController.java @@ -569,33 +569,22 @@ public ResponseEntity updateDescription( return httpRequestService.makeApiRequestWithBody(currentUid, uri, description, HttpMethod.PUT); } - /** - * Allow an owner of a Grouping to enable that a Grouping connected to a given sync destination. - */ - @PostMapping(value = "/groupings/{path}/syncDests/{syncDestId}/enable") - public ResponseEntity enableSyncDest( - @PathVariable String path, - @PathVariable String syncDestId) { - logger.info("Entered REST enableSyncDest..."); - String currentUid = policy.sanitize(userContextService.getCurrentUid()); - String safeGrouping = policy.sanitize(path); - String safeSyncDestId = policy.sanitize(syncDestId); - return changeSyncDest(safeGrouping, currentUid, safeSyncDestId, true); - } /** - * This allows an owner of a Grouping to disable that a Grouping connected to a given sync + * This allows an owner of a Grouping to enable/disable that a Grouping connected to a given sync * destination. */ - @PostMapping(value = "/groupings/{path}/syncDests/{syncDestId}/disable") - public ResponseEntity disableSyncDest( + @PostMapping(value = "/groupings/{path}/syncDests/{syncDestId}/{status}") + public ResponseEntity updateSyncDest( @PathVariable String path, - @PathVariable String syncDestId) { - logger.info("Entered REST disableSyncDest..."); + @PathVariable String syncDestId, + @PathVariable boolean status) { + logger.info("Entered REST updateSyncDest..."); String currentUid = policy.sanitize(userContextService.getCurrentUid()); String safeGrouping = policy.sanitize(path); String safeSyncDestId = policy.sanitize(syncDestId); - return changeSyncDest(safeGrouping, currentUid, safeSyncDestId, false); + String uri = String.format(API_2_1_BASE + "/groupings/%s/sync-destination/%s/%s", safeGrouping, safeSyncDestId, status); + return httpRequestService.makeApiRequest(currentUid, uri, HttpMethod.PUT); } /** @@ -708,15 +697,6 @@ private ResponseEntity changePreference(String grouping, String uhIdenti return httpRequestService.makeApiRequest(uhIdentifier, uri, HttpMethod.PUT); } - private ResponseEntity changeSyncDest(String grouping, String uhIdentifier, String syncDest, Boolean isOn) { - String ending = "disable"; - if (isOn) { - ending = "enable"; - } - String uri = String.format(API_2_1_BASE + "/groupings/%s/sync-destination/%s/%s", grouping, syncDest, ending); - return httpRequestService.makeApiRequest(uhIdentifier, uri, HttpMethod.PUT); - } - protected Boolean shouldDoApiHandshake() { if (!API_HANDSHAKE_ENABLED) { logger.info("API handshake disabled."); diff --git a/src/main/resources/static/javascript/mainApp/grouping.controller.js b/src/main/resources/static/javascript/mainApp/grouping.controller.js index fc701238c..755ecbab2 100644 --- a/src/main/resources/static/javascript/mainApp/grouping.controller.js +++ b/src/main/resources/static/javascript/mainApp/grouping.controller.js @@ -1604,7 +1604,7 @@ $scope.updateSingleSyncDest = (syncDestName) => { const groupingPath = $scope.selectedGrouping.path; const syncDestOn = $scope.getSyncDestValueInArray(syncDestName); - groupingsService.setSyncDest(groupingPath, syncDestName, syncDestOn, handleSuccessfulPreferenceToggle, handleUnsuccessfulRequest); + groupingsService.updateSyncDest(groupingPath, syncDestName, syncDestOn, handleSuccessfulPreferenceToggle, handleUnsuccessfulRequest); }; /** diff --git a/src/main/resources/static/javascript/mainApp/groupings.service.js b/src/main/resources/static/javascript/mainApp/groupings.service.js index 46161be13..75e7c49f6 100644 --- a/src/main/resources/static/javascript/mainApp/groupings.service.js +++ b/src/main/resources/static/javascript/mainApp/groupings.service.js @@ -391,9 +391,8 @@ /** * Toggle the given sync destination. */ - setSyncDest(path, syncDestId, turnOn, onSuccess, onError) { - let endpoint = BASE_URL + "groupings/" + path + "/syncDests/" + syncDestId; - endpoint = (turnOn) ? endpoint.concat("/enable") : endpoint.concat("/disable"); + updateSyncDest(path, syncDestId, status, onSuccess, onError) { + let endpoint = `${BASE_URL}groupings/${path}/syncDests/${syncDestId}/${status}`; dataProvider.updateData(endpoint, onSuccess, onError); }, diff --git a/src/test/java/edu/hawaii/its/api/controller/GroupingsRestControllerTest.java b/src/test/java/edu/hawaii/its/api/controller/GroupingsRestControllerTest.java index 414b00cd9..b101d5f7a 100644 --- a/src/test/java/edu/hawaii/its/api/controller/GroupingsRestControllerTest.java +++ b/src/test/java/edu/hawaii/its/api/controller/GroupingsRestControllerTest.java @@ -669,36 +669,30 @@ public void updateDescriptionTest() throws Exception { @Test @WithMockUhUser - public void enableSyncDestTest() throws Exception { - String uri = REST_CONTROLLER_BASE + "groupings/" + GROUPING + "/syncDests/listserv/enable"; + public void updateSyncDestTest() throws Exception { + String uri = REST_CONTROLLER_BASE + "groupings/" + GROUPING + "/syncDests/listserv/"; + String enableUri = uri + "true"; given(httpRequestService.makeApiRequest(eq(UID), anyString(), eq(HttpMethod.PUT))) - .willReturn(new ResponseEntity(HttpStatus.OK)); + .willReturn(new ResponseEntity<>(HttpStatus.OK)); - assertNotNull(mockMvc.perform(post(uri).with(csrf())) + assertNotNull(mockMvc.perform(post(enableUri).with(csrf())) .andExpect(status().isOk()) .andReturn()); verify(httpRequestService, times(1)) .makeApiRequest(eq(UID), anyString(), eq(HttpMethod.PUT)); - } - - @Test - @WithMockUhUser - public void disableSyncDestTest() throws Exception { - String uri = REST_CONTROLLER_BASE + "groupings/" + GROUPING + "/syncDests/listserv/disable"; - + String disableUri = uri + "false"; given(httpRequestService.makeApiRequest(eq(UID), anyString(), eq(HttpMethod.PUT))) - .willReturn(new ResponseEntity(HttpStatus.OK)); + .willReturn(new ResponseEntity<>(HttpStatus.OK)); - assertNotNull(mockMvc.perform(post(uri).with(csrf())) + assertNotNull(mockMvc.perform(post(disableUri).with(csrf())) .andExpect(status().isOk()) .andReturn()); - verify(httpRequestService, times(1)) + verify(httpRequestService, times(2)) .makeApiRequest(eq(UID), anyString(), eq(HttpMethod.PUT)); } - @Test @WithMockUhUser public void setOptInTrueTest() throws Exception { diff --git a/src/test/javascript/grouping.controller.test.js b/src/test/javascript/grouping.controller.test.js index 8da843f8d..ebae4fd9f 100644 --- a/src/test/javascript/grouping.controller.test.js +++ b/src/test/javascript/grouping.controller.test.js @@ -2508,11 +2508,11 @@ describe("GroupingController", () => { }; }); - it("should call the setSyncDest", () => { - spyOn(gs, "setSyncDest"); + it("should call the updateSyncDest", () => { + spyOn(gs, "updateSyncDest"); scope.syncDestArray.push(testSync); scope.updateSingleSyncDest(testSync.name); - expect(gs.setSyncDest).toHaveBeenCalled(); + expect(gs.updateSyncDest).toHaveBeenCalled(); }); it("should call getSyncDestValueInArray", () => { diff --git a/src/test/javascript/groupings.service.test.js b/src/test/javascript/groupings.service.test.js index f46417aac..c9ebc9b97 100644 --- a/src/test/javascript/groupings.service.test.js +++ b/src/test/javascript/groupings.service.test.js @@ -574,24 +574,24 @@ describe("GroupingsService", () => { }); }); - describe("setSyncDest", () => { + describe("updateSyncDest", () => { let syncDestId; let turnOn; it("should call dataProvider.updateData", () => { spyOn(dp, "updateData"); - gs.setSyncDest(groupingPath, syncDestId, turnOn, onSuccess, onError); + gs.updateSyncDest(groupingPath, syncDestId, turnOn, onSuccess, onError); expect(dp.updateData).toHaveBeenCalled(); }); - + it("should use the correct path for enable", () => { - gs.setSyncDest(groupingPath, syncDestId, true, onSuccess, onError); - httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/enable").respond(200); + gs.updateSyncDest(groupingPath, syncDestId, true, onSuccess, onError); + httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/true").respond(200); expect(httpBackend.flush).not.toThrow(); }); it("should use the correct path for disable", () => { - gs.setSyncDest(groupingPath, syncDestId, false, onSuccess, onError); - httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/disable").respond(200); + gs.updateSyncDest(groupingPath, syncDestId, false, onSuccess, onError); + httpBackend.expectPOST(BASE_URL + "groupings/" + groupingPath + "/syncDests/" + syncDestId + "/false").respond(200); expect(httpBackend.flush).not.toThrow(); }); });