@Test public void shouldUpdateRoleAndRights() throws Exception { Role role = new Role("Role Name", "Desc", asList(new Right(CONFIGURE_RNR, ADMIN))); when(messageService.message("message.role.updated.success", "Role Name")).thenReturn("Role Name updated successfully"); OpenLmisResponse response = controller.updateRole(role.getId(), role, httpServletRequest).getBody(); assertThat(response.getSuccessMsg(), is("Role Name updated successfully")); verify(roleRightsService).updateRole(role); }
@RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request) { role.setModifiedBy(loggedInUserId(request)); try { role.setId(id); roleRightsService.updateRole(role); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } return success(messageService.message("message.role.updated.success", role.getName())); }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request) { role.setModifiedBy(loggedInUserId(request)); try { role.setId(id); roleRightsService.updateRole(role); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } return success(messageService.message("message.role.updated.success", role.getName())); } }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request) { role.setModifiedBy(loggedInUserId(request)); try { role.setId(id); roleRightsService.updateRole(role); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } return success(messageService.message("message.role.updated.success", role.getName())); }  }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request) { role.setModifiedBy(loggedInUserId(request)); try { role.setId(id); roleRightsService.updateRole(role); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } return success(messageService.message("message.role.updated.success", role.getName())); }  @RequestMapping(value = "/rights", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getAllRights(); @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "/roles", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAll(); @RequestMapping(value = "/roles/list", method = GET) ResponseEntity<OpenLmisResponse> getAllReadonly(); @RequestMapping(value = "/roles-flat", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAllRolesFlat(); @RequestMapping(value = "/roles/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> get(@PathVariable("id") Long id); @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "facility/{facilityId}/program/{programId}/rights", method = GET) ResponseEntity<OpenLmisResponse> getRightsForUserAndFacilityProgram(@PathVariable("facilityId") Long facilityId, @PathVariable("programId") Long programId, HttpServletRequest httpServletRequest); @RequestMapping(value="/roles/getList",method= RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getRoleList(HttpServletRequest request); }
RoleRightsController extends BaseController { @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") public ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request) { role.setModifiedBy(loggedInUserId(request)); try { role.setId(id); roleRightsService.updateRole(role); } catch (DataException e) { return error(e, HttpStatus.CONFLICT); } return success(messageService.message("message.role.updated.success", role.getName())); }  @RequestMapping(value = "/rights", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getAllRights(); @RequestMapping(value = "/roles", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> createRole(@RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "/roles", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAll(); @RequestMapping(value = "/roles/list", method = GET) ResponseEntity<OpenLmisResponse> getAllReadonly(); @RequestMapping(value = "/roles-flat", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE, MANAGE_USER')") ResponseEntity<OpenLmisResponse> getAllRolesFlat(); @RequestMapping(value = "/roles/{id}", method = GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> get(@PathVariable("id") Long id); @RequestMapping(value = "/roles/{id}", method = PUT, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> updateRole(@PathVariable("id") Long id, @RequestBody Role role, HttpServletRequest request); @RequestMapping(value = "facility/{facilityId}/program/{programId}/rights", method = GET) ResponseEntity<OpenLmisResponse> getRightsForUserAndFacilityProgram(@PathVariable("facilityId") Long facilityId, @PathVariable("programId") Long programId, HttpServletRequest httpServletRequest); @RequestMapping(value="/roles/getList",method= RequestMethod.GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_ROLE')") ResponseEntity<OpenLmisResponse> getRoleList(HttpServletRequest request); static final String ROLE; static final String ROLES_MAP; static final String RIGHTS; static final String RIGHT_TYPE; }