|
|
@@ -1,6 +1,5 @@
|
|
|
package cn.reghao.devops.mgr.admin.controller;
|
|
|
|
|
|
-import cn.reghao.devops.mgr.admin.model.dto.RoleDto;
|
|
|
import cn.reghao.devops.mgr.admin.model.po.Menu;
|
|
|
import cn.reghao.devops.mgr.admin.model.po.Role;
|
|
|
import cn.reghao.devops.mgr.admin.model.po.User;
|
|
|
@@ -18,7 +17,6 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
@@ -44,68 +42,42 @@ public class RolePageController {
|
|
|
@ApiOperation(value = "角色列表页面", notes = "N")
|
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
@GetMapping
|
|
|
- public String rolePage(@RequestParam(value = "name", required = false) String name, Model model) {
|
|
|
- Page<RoleVO> page;
|
|
|
- if (name != null) {
|
|
|
- page = roleService.getByPage(null, name);
|
|
|
- } else {
|
|
|
- PageRequest pageRequest = PageRequest.of(0, 100);
|
|
|
- page = roleService.getByPage(pageRequest, null);
|
|
|
- }
|
|
|
+ public String rolePage(Model model) {
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 100);
|
|
|
+ Page<RoleVO> page = roleService.getByPage(pageRequest, null);
|
|
|
|
|
|
model.addAttribute("page", page);
|
|
|
model.addAttribute("list", page.getContent());
|
|
|
return "/admin/role/index";
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "角色新增页面", notes = "N")
|
|
|
- @PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
- @GetMapping("/add")
|
|
|
- public String addRolePage() {
|
|
|
- return "/admin/role/add";
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "角色编辑页面", notes = "N")
|
|
|
- @PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
- @GetMapping("/edit/{id}")
|
|
|
- public String editRolePage(@PathVariable("id") int id, Model model) {
|
|
|
- RoleVO vo = roleService.getRoleVOById(id);
|
|
|
- model.addAttribute("role", vo);
|
|
|
- return "/admin/role/add";
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "角色详细信息页面", notes = "N")
|
|
|
+ @ApiOperation(value = "拥有角色的所有用户页面", notes = "N")
|
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
- @GetMapping("/detail/{id}")
|
|
|
- public String roleDetailPage(@PathVariable("id") int id, Model model) {
|
|
|
- RoleVO vo = roleService.getRoleVOById(id);
|
|
|
- model.addAttribute("role", vo);
|
|
|
- return "/admin/role/detail";
|
|
|
+ @GetMapping("/users/{id}")
|
|
|
+ public String userListWithRole(@PathVariable("id") Integer roleId, Model model) {
|
|
|
+ List<User> list = roleService.getRoleUsers(roleId);
|
|
|
+ model.addAttribute("list", list);
|
|
|
+ return "/admin/role/users";
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "设置角色可访问的资源页面", notes = "N")
|
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
- @GetMapping("/menus/{id}")
|
|
|
+ @GetMapping("/grant/{id}")
|
|
|
public String menusPage(@PathVariable(value = "id") Integer id, Model model){
|
|
|
model.addAttribute("roleId", id);
|
|
|
return "/admin/role/menus";
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "拥有角色的所有用户页面", notes = "N")
|
|
|
- @PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
- @GetMapping("/users/{id}")
|
|
|
- public String userListWithRole(@PathVariable("id") Integer roleId, Model model) {
|
|
|
- List<User> list = roleService.getRoleUsers(roleId);
|
|
|
- model.addAttribute("list", list);
|
|
|
- return "/admin/role/users";
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "添加或修改角色", notes = "N")
|
|
|
+ @ApiOperation(value = "设置角色可访问的资源", notes = "N")
|
|
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
- @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PostMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ResponseBody
|
|
|
- public String addOrModifyRole(@Validated RoleDto roleDto) {
|
|
|
- roleService.addOrUpdate(roleDto);
|
|
|
+ public String setRoleMenus(@RequestParam(value = "id") Integer roleId,
|
|
|
+ @RequestParam(value = "menuId", required = false) Set<Menu> menus) {
|
|
|
+ if (menus == null) {
|
|
|
+ menus = Collections.emptySet();
|
|
|
+ }
|
|
|
+ roleService.updateRoleMenus(roleId, menus);
|
|
|
return WebResult.success();
|
|
|
}
|
|
|
|
|
|
@@ -133,17 +105,4 @@ public class RolePageController {
|
|
|
List<MenuTree> allMenus = menuService.getMenusByRole(role);
|
|
|
return WebResult.success(allMenus);
|
|
|
}
|
|
|
-
|
|
|
- @ApiOperation(value = "设置角色可访问的资源", notes = "N")
|
|
|
- @PreAuthorize("hasRole('ROLE_ADMIN')")
|
|
|
- @PostMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- @ResponseBody
|
|
|
- public String setRoleMenus(@RequestParam(value = "id") Integer roleId,
|
|
|
- @RequestParam(value = "menuId", required = false) Set<Menu> menus) {
|
|
|
- if (menus == null) {
|
|
|
- menus = Collections.emptySet();
|
|
|
- }
|
|
|
- roleService.setRoleMenus(roleId, menus);
|
|
|
- return WebResult.success();
|
|
|
- }
|
|
|
}
|