Skip to content

Commit

Permalink
Enhance Flexibility of the IsSoleOwner API Endpoint (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitCarrot authored Nov 14, 2024
1 parent 5a7dcbc commit 198fb9e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,14 @@ public ResponseEntity<String> setOptOut(
}

/**
* Checks if the owner of a grouping is the sole owner
* Get the number of owners of the group path that contains the owner with uhIdentifier
*/
@GetMapping(value = "/{path:.+}/owners/{uidToCheck}")
public ResponseEntity<String> isSoleOwner(@PathVariable String path,
@PathVariable String uidToCheck) {
logger.info("Entered REST isSoleOwner...");
@GetMapping(value = "/{path:.+}/owners/{uhIdentifier}/count")
public ResponseEntity<String> getNumberOfOwners(@PathVariable String path,
@PathVariable String uhIdentifier) {
logger.info("Entered REST getNumberOfOwners...");
String currentUid = policy.sanitize(userContextService.getCurrentUid());
String baseUri = String.format(API_2_1_BASE + "/groupings/%s/owners/%s", path, uidToCheck);

String baseUri = String.format(API_2_1_BASE + "/members/%s/owners/%s/count", path, uhIdentifier);
return httpRequestService.makeApiRequest(currentUid, baseUri, HttpMethod.GET);
}

Expand Down
15 changes: 8 additions & 7 deletions src/main/resources/static/javascript/mainApp/admin.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$scope.adminsList = _.sortBy(res.members, "name");
$scope.pagedItemsAdmins = $scope.objToPageArray($scope.adminsList, PAGE_SIZE);
$scope.loading = false;
}
};

/**
* Callback which takes the admin tab data and moves it into groupingsList, the object
Expand All @@ -51,7 +51,7 @@
$scope.groupingsList = _.sortBy(res.groupingPaths, "name");
$scope.pagedItemsGroupings = $scope.objToPageArray($scope.groupingsList, PAGE_SIZE);
$scope.allGroupingsLoading = false;
}
};

/**
* Complete initialization by fetching a list of admins and list of all groupings.
Expand Down Expand Up @@ -79,7 +79,7 @@
$scope.subjectList = _.sortBy(res.results, "name");
$scope.filter($scope.subjectList, "pagedItemsSubject", "currentPageSubject", $scope.subjectQuery, true);
$scope.user = $scope.subjectToLookup;
$scope.userGroupingInformationLoading = false
$scope.userGroupingInformationLoading = false;
};
$scope.searchForUserGroupingInformationOnErrorCallback = (res) => {
$scope.subjectList = [];
Expand Down Expand Up @@ -151,8 +151,8 @@
$scope.removeFromGroupsCallbackOnSuccess(memberToRemove);
}
_.forEach($scope.selectedOwnedGroupings, (grouping) => {
groupingsService.isSoleOwner(grouping.path, memberToRemove.uid, (res) => {
if (res) {
groupingsService.getNumberOfOwners(grouping.path, memberToRemove.uid, (res) => {
if (res === 1) {
$scope.soleOwnerGroupingNames.push(grouping.name);
}
if (grouping === $scope.selectedOwnedGroupings[$scope.selectedOwnedGroupings.length - 1]) {
Expand Down Expand Up @@ -471,10 +471,11 @@
};

$scope.throwException = () => {
groupingsService.throwException(() => {}, () => {
groupingsService.throwException(() => {
}, () => {
$scope.displayApiErrorModal();
});
}
};
}

UHGroupingsApp.controller("AdminJsController", AdminJsController);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@
/**
* Checks if the owner of a grouping is the sole owner
*/
isSoleOwner(path, uidToCheck, onSuccess, onError) {
let endpoint = BASE_URL + path + "/owners/" + uidToCheck;
getNumberOfOwners(path, uidToCheck, onSuccess, onError) {
let endpoint = BASE_URL + path + "/owners/" + uidToCheck + "/count";
dataProvider.loadData(endpoint, onSuccess, onError);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ public void setOptOut() throws Exception {

@Test
@WithMockUhUser
public void isSoleOwner() throws Exception {
String uri = REST_CONTROLLER_BASE + GROUPING + "/owners/" + UID;
public void getNumberOfOwners() throws Exception {
String uri = REST_CONTROLLER_BASE + GROUPING + "/owners/" + UID + "/count";

given(httpRequestService.makeApiRequest(eq(UID), anyString(), eq(HttpMethod.GET)))
.willReturn(new ResponseEntity(HttpStatus.OK));
Expand Down

0 comments on commit 198fb9e

Please sign in to comment.