|
1 | 1 | package edu.hawaii.its.api.controller;
|
2 | 2 |
|
3 | 3 | import java.security.Principal;
|
| 4 | +import java.util.ArrayList; |
4 | 5 | import java.util.HashMap;
|
| 6 | +import java.util.List; |
5 | 7 | import java.util.Map;
|
6 | 8 |
|
7 | 9 | import javax.annotation.PostConstruct;
|
@@ -89,7 +91,7 @@ public class GroupingsRestController {
|
89 | 91 |
|
90 | 92 | // Constructor.
|
91 | 93 | public GroupingsRestController() {
|
92 |
| - policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); |
| 94 | + policy = Sanitizers.FORMATTING; |
93 | 95 | }
|
94 | 96 |
|
95 | 97 | /*
|
@@ -274,63 +276,59 @@ public ResponseEntity<String> optOut(Principal principal, @PathVariable String g
|
274 | 276 | /**
|
275 | 277 | * Add a list of usersToAdd to include group of grouping at path.
|
276 | 278 | */
|
277 |
| - @PostMapping(value = "/{groupingPath}/{usersToAdd}/addMembersToIncludeGroup") |
| 279 | + @PutMapping(value = "/{groupingPath}/addMembersToIncludeGroup") |
278 | 280 | public ResponseEntity<String> addMembersToIncludeGroup(Principal principal,
|
279 | 281 | @PathVariable String groupingPath,
|
280 |
| - @PathVariable String usersToAdd) { |
| 282 | + @RequestBody List<String> usersToAdd) { |
281 | 283 | logger.info("Entered REST addMembersToIncludeGroup...");
|
282 | 284 | String safeGroupingPath = policy.sanitize(groupingPath);
|
283 |
| - String safeUsersToAdd = policy.sanitize(usersToAdd); |
284 |
| - String uri = String.format(API_2_1_BASE + "/groupings/%s/include-members/%s", safeGroupingPath, |
285 |
| - safeUsersToAdd); |
286 |
| - return httpRequestService.makeApiRequest(principal.getName(), uri, HttpMethod.PUT); |
| 285 | + List<String> safeUsersToAdd = sanitizeList(usersToAdd); |
| 286 | + String uri = String.format(API_2_1_BASE + "/groupings/%s/include-members", safeGroupingPath); |
| 287 | + return httpRequestService.makeApiRequestWithBody(principal.getName(), uri, safeUsersToAdd, HttpMethod.PUT); |
287 | 288 | }
|
288 | 289 |
|
289 | 290 | /**
|
290 | 291 | * Add a list of usersToAdd to exclude group of grouping at path.
|
291 | 292 | */
|
292 |
| - @PostMapping(value = "/{groupingPath}/{usersToAdd}/addMembersToExcludeGroup") |
| 293 | + @PutMapping(value = "/{groupingPath}/addMembersToExcludeGroup") |
293 | 294 | public ResponseEntity<String> addMembersToExcludeGroup(Principal principal,
|
294 | 295 | @PathVariable String groupingPath,
|
295 |
| - @PathVariable String usersToAdd) { |
| 296 | + @RequestBody List<String> usersToAdd) { |
296 | 297 | logger.info("Entered REST addMembersToExcludeGroup...");
|
297 | 298 | String safeGroupingPath = policy.sanitize(groupingPath);
|
298 |
| - String safeUsersToAdd = policy.sanitize(usersToAdd); |
299 |
| - String uri = String.format(API_2_1_BASE + "/groupings/%s/exclude-members/%s", safeGroupingPath, |
300 |
| - safeUsersToAdd); |
301 |
| - return httpRequestService.makeApiRequest(principal.getName(), uri, HttpMethod.PUT); |
| 299 | + List<String> safeUsersToAdd = sanitizeList(usersToAdd); |
| 300 | + String uri = String.format(API_2_1_BASE + "/groupings/%s/exclude-members", safeGroupingPath); |
| 301 | + return httpRequestService.makeApiRequestWithBody(principal.getName(), uri, safeUsersToAdd, HttpMethod.PUT); |
302 | 302 | }
|
303 | 303 |
|
304 | 304 | /**
|
305 | 305 | * Remove a list of users from include group of grouping at path.
|
306 | 306 | */
|
307 |
| - @PostMapping(value = "/{groupingPath}/{usersToDelete}/removeMembersFromIncludeGroup") |
| 307 | + @PutMapping(value = "/{groupingPath}/removeMembersFromIncludeGroup") |
308 | 308 | public ResponseEntity<String> removeMembersFromIncludeGroup(Principal principal,
|
309 | 309 | @PathVariable String groupingPath,
|
310 |
| - @PathVariable String usersToDelete) { |
| 310 | + @RequestBody List<String> usersToDelete) { |
311 | 311 | logger.info("Entered REST deleteMembersFromIncludeGroup...");
|
312 | 312 | String safeGroupingPath = policy.sanitize(groupingPath);
|
313 |
| - String safeUserToDelete = policy.sanitize(usersToDelete); |
| 313 | + List<String> safeUsersToDelete = sanitizeList(usersToDelete); |
314 | 314 | String uri =
|
315 |
| - String.format(API_2_1_BASE + "/groupings/%s/include-members/%s", safeGroupingPath, |
316 |
| - safeUserToDelete); |
317 |
| - return httpRequestService.makeApiRequest(principal.getName(), uri, HttpMethod.DELETE); |
| 315 | + String.format(API_2_1_BASE + "/groupings/%s/include-members", safeGroupingPath); |
| 316 | + return httpRequestService.makeApiRequestWithBody(principal.getName(), uri, safeUsersToDelete, HttpMethod.DELETE); |
318 | 317 | }
|
319 | 318 |
|
320 | 319 | /**
|
321 | 320 | * Remove a list of users from exclude group of grouping at path.
|
322 | 321 | */
|
323 |
| - @PostMapping(value = "/{groupingPath}/{usersToDelete}/removeMembersFromExcludeGroup") |
| 322 | + @PutMapping(value = "/{groupingPath}/removeMembersFromExcludeGroup") |
324 | 323 | public ResponseEntity<String> removeMembersFromExcludeGroup(Principal principal,
|
325 | 324 | @PathVariable String groupingPath,
|
326 |
| - @PathVariable String usersToDelete) { |
| 325 | + @RequestBody List<String> usersToDelete) { |
327 | 326 | logger.info("Entered REST deleteMembersFromExcludeGroup...");
|
328 | 327 | String safeGroupingPath = policy.sanitize(groupingPath);
|
329 |
| - String safeUserToDelete = policy.sanitize(usersToDelete); |
| 328 | + List<String> safeUsersToDelete = sanitizeList(usersToDelete); |
330 | 329 | String uri =
|
331 |
| - String.format(API_2_1_BASE + "/groupings/%s/exclude-members/%s", safeGroupingPath, |
332 |
| - safeUserToDelete); |
333 |
| - return httpRequestService.makeApiRequest(principal.getName(), uri, HttpMethod.DELETE); |
| 330 | + String.format(API_2_1_BASE + "/groupings/%s/exclude-members", safeGroupingPath); |
| 331 | + return httpRequestService.makeApiRequestWithBody(principal.getName(), uri, safeUsersToDelete, HttpMethod.DELETE); |
334 | 332 | }
|
335 | 333 |
|
336 | 334 | /**
|
@@ -513,6 +511,21 @@ public ResponseEntity<String> allSyncDestinations(Principal principal, @PathVari
|
513 | 511 | // Helper Methods
|
514 | 512 | //////////////////////////////////////////////////////////////////////
|
515 | 513 |
|
| 514 | + public List<String> sanitizeList(List<String> data) { |
| 515 | + List<String> sanitizedList = new ArrayList<>(); |
| 516 | + String sanitizedString; |
| 517 | + |
| 518 | + for (int i = 0; i < data.size(); i++) { |
| 519 | + sanitizedString = policy.sanitize(data.get(i)); |
| 520 | + |
| 521 | + if (!(sanitizedString.isEmpty())) { |
| 522 | + sanitizedList.add(sanitizedString); |
| 523 | + } |
| 524 | + } |
| 525 | + |
| 526 | + return sanitizedList; |
| 527 | + } |
| 528 | + |
516 | 529 | public Map<String, String> mapGroupingParameters(Integer page, Integer size, String sortString,
|
517 | 530 | Boolean isAscending) {
|
518 | 531 | Map<String, String> params = new HashMap<>();
|
|
0 commit comments