@RequiresPermissions("User:assign") @RequestMapping( value = "/lookup2create/userRole/{userId}", method = {RequestMethod.GET, RequestMethod.POST}) public String listUnassignRole(Map<String, Object> map, @PathVariable Long userId) { Page page = new Page(); page.setNumPerPage(Integer.MAX_VALUE); List<UserRole> userRoles = userRoleService.find(userId); List<Role> roles = roleService.findAll(page); List<Role> rentList = Lists.newArrayList(); // 删除已分配roles for (Role role : roles) { boolean isHas = false; for (UserRole or : userRoles) { if (or.getRole().getId().equals(role.getId())) { isHas = true; break; } } if (isHas == false) { rentList.add(role); } } map.put("userRoles", userRoles); map.put("roles", rentList); map.put("userId", userId); return LOOK_UP_ROLE; }
@Log(message = "向{0}用户分配了{1}的角色。") @RequiresPermissions("User:assign") @RequestMapping( value = "/create/userRole", method = {RequestMethod.POST}) public @ResponseBody void assignRole(UserRole userRole) { userRoleService.save(userRole); User user = userService.get(userRole.getUser().getId()); Role role = roleService.get(userRole.getRole().getId()); LogUitl.putArgs( LogMessageObject.newWrite().setObjects(new Object[] {user.getUsername(), role.getName()})); }
@Log(message = "撤销了{0}用户的{1}角色。") @RequiresPermissions("User:assign") @RequestMapping( value = "/delete/userRole/{userRoleId}", method = {RequestMethod.POST}) public @ResponseBody void deleteUserRole(@PathVariable Long userRoleId) { UserRole userRole = userRoleService.get(userRoleId); LogUitl.putArgs( LogMessageObject.newWrite() .setObjects( new Object[] {userRole.getUser().getUsername(), userRole.getRole().getName()})); userRoleService.delete(userRoleId); }