feat(auth): role management — ancestor completion, CRUD, permission assignment, cascade delete (ADR-0012)
Implements ADR-0005 (backend ancestor completion) and ADR-0012 (role management
architecture) across 5 tracer-bullet tickets:
- ISysMenuService.getAncestorIds: batch query full table, in-memory parentId
traversal, returns complete ancestor set (ADR-0005)
- SysRole.builtin field + DataInitializer idempotent refactor + 5 button
permission seeds (crm:role:list/detail/save/delete/assign) bound to ADMIN
- RoleController (/api/roles/*): page, saveOrUpdate, detail, assign-resources,
delete — pure hasAuthority, POST + action suffix, form params
- SysRoleServiceImpl.saveRole: roleCode uniqueness, builtin protection,
dataScope 1-4 range, create can't set builtin=true
- assignResources: calls getAncestorIds for ancestor completion, then
full replacement (delete + insert) of sys_role_menu
- getRoleDetail: returns RoleDetailVO with basic info + resourceIds
- deleteRoleCascade: cleans sys_role_menu + sys_user_role, builtin rejection,
three-table transaction
- SystemController: all role endpoints removed, unused deps cleaned
- Dead code removed: assignMenus, getMenuIdsByRoleId (superseded by
assignResources, getRoleDetail)
- H2 test schemas updated with builtin column
- 150 tests pass (16 new in SysRoleServiceImplTest, 7 in SysMenuServiceImplTest)
1 month ago
|
|
|
package com.crm.auth.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.crm.auth.domain.dto.RoleDetailVO;
|
|
|
|
|
import com.crm.auth.domain.entity.SysRole;
|
|
|
|
|
import com.crm.auth.service.ISysRoleService;
|
|
|
|
|
import com.crm.base.domain.result.PageResult;
|
|
|
|
|
import com.crm.base.domain.result.Result;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 角色管理端接口(ADR-0012)
|
|
|
|
|
* <p>遵循全局接口契约:非严格 RESTful,写操作 POST + 动作后缀,表单字段收参</p>
|
|
|
|
|
* <p>权限控制:纯 hasAuthority,权限码由数据初始化器种子化到权限资源树</p>
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/roles")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class RoleController {
|
|
|
|
|
|
|
|
|
|
private final ISysRoleService sysRoleService;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/page")
|
|
|
|
|
@PreAuthorize("hasAuthority('crm:role:list')")
|
|
|
|
|
@Operation(summary = "分页查询角色", tags = {"系统管理/角色管理"})
|
feat(auth): role management — ancestor completion, CRUD, permission assignment, cascade delete (ADR-0012)
Implements ADR-0005 (backend ancestor completion) and ADR-0012 (role management
architecture) across 5 tracer-bullet tickets:
- ISysMenuService.getAncestorIds: batch query full table, in-memory parentId
traversal, returns complete ancestor set (ADR-0005)
- SysRole.builtin field + DataInitializer idempotent refactor + 5 button
permission seeds (crm:role:list/detail/save/delete/assign) bound to ADMIN
- RoleController (/api/roles/*): page, saveOrUpdate, detail, assign-resources,
delete — pure hasAuthority, POST + action suffix, form params
- SysRoleServiceImpl.saveRole: roleCode uniqueness, builtin protection,
dataScope 1-4 range, create can't set builtin=true
- assignResources: calls getAncestorIds for ancestor completion, then
full replacement (delete + insert) of sys_role_menu
- getRoleDetail: returns RoleDetailVO with basic info + resourceIds
- deleteRoleCascade: cleans sys_role_menu + sys_user_role, builtin rejection,
three-table transaction
- SystemController: all role endpoints removed, unused deps cleaned
- Dead code removed: assignMenus, getMenuIdsByRoleId (superseded by
assignResources, getRoleDetail)
- H2 test schemas updated with builtin column
- 150 tests pass (16 new in SysRoleServiceImplTest, 7 in SysMenuServiceImplTest)
1 month ago
|
|
|
public Result<PageResult<SysRole>> page(
|
|
|
|
|
@RequestParam(defaultValue = "1") Long current,
|
|
|
|
|
@RequestParam(defaultValue = "10") Long size,
|
|
|
|
|
@RequestParam(required = false) String keyword) {
|
|
|
|
|
Page<SysRole> page = new Page<>(current, size);
|
|
|
|
|
sysRoleService.lambdaQuery()
|
|
|
|
|
.like(StrUtil.isNotBlank(keyword), SysRole::getRoleName, keyword)
|
|
|
|
|
.page(page);
|
|
|
|
|
return Result.success(new PageResult<>(page));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/saveOrUpdate")
|
|
|
|
|
@PreAuthorize("hasAuthority('crm:role:save')")
|
|
|
|
|
@Operation(summary = "新增或编辑角色", tags = {"系统管理/角色管理"})
|
feat(auth): role management — ancestor completion, CRUD, permission assignment, cascade delete (ADR-0012)
Implements ADR-0005 (backend ancestor completion) and ADR-0012 (role management
architecture) across 5 tracer-bullet tickets:
- ISysMenuService.getAncestorIds: batch query full table, in-memory parentId
traversal, returns complete ancestor set (ADR-0005)
- SysRole.builtin field + DataInitializer idempotent refactor + 5 button
permission seeds (crm:role:list/detail/save/delete/assign) bound to ADMIN
- RoleController (/api/roles/*): page, saveOrUpdate, detail, assign-resources,
delete — pure hasAuthority, POST + action suffix, form params
- SysRoleServiceImpl.saveRole: roleCode uniqueness, builtin protection,
dataScope 1-4 range, create can't set builtin=true
- assignResources: calls getAncestorIds for ancestor completion, then
full replacement (delete + insert) of sys_role_menu
- getRoleDetail: returns RoleDetailVO with basic info + resourceIds
- deleteRoleCascade: cleans sys_role_menu + sys_user_role, builtin rejection,
three-table transaction
- SystemController: all role endpoints removed, unused deps cleaned
- Dead code removed: assignMenus, getMenuIdsByRoleId (superseded by
assignResources, getRoleDetail)
- H2 test schemas updated with builtin column
- 150 tests pass (16 new in SysRoleServiceImplTest, 7 in SysMenuServiceImplTest)
1 month ago
|
|
|
public Result<Void> saveOrUpdate(
|
|
|
|
|
@RequestParam(required = false) Long id,
|
|
|
|
|
@RequestParam String roleName,
|
|
|
|
|
@RequestParam String roleCode,
|
|
|
|
|
@RequestParam(defaultValue = "1") Integer dataScope,
|
|
|
|
|
@RequestParam(defaultValue = "0") Integer sort,
|
|
|
|
|
@RequestParam(required = false) String remark) {
|
|
|
|
|
SysRole role = new SysRole();
|
|
|
|
|
role.setId(id);
|
|
|
|
|
role.setRoleName(roleName);
|
|
|
|
|
role.setRoleCode(roleCode);
|
|
|
|
|
role.setDataScope(dataScope);
|
|
|
|
|
role.setSort(sort);
|
|
|
|
|
role.setRemark(remark);
|
|
|
|
|
sysRoleService.saveRole(role);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/detail")
|
|
|
|
|
@PreAuthorize("hasAuthority('crm:role:detail')")
|
|
|
|
|
@Operation(summary = "角色详情(含授权资源集合)", tags = {"系统管理/角色管理"})
|
feat(auth): role management — ancestor completion, CRUD, permission assignment, cascade delete (ADR-0012)
Implements ADR-0005 (backend ancestor completion) and ADR-0012 (role management
architecture) across 5 tracer-bullet tickets:
- ISysMenuService.getAncestorIds: batch query full table, in-memory parentId
traversal, returns complete ancestor set (ADR-0005)
- SysRole.builtin field + DataInitializer idempotent refactor + 5 button
permission seeds (crm:role:list/detail/save/delete/assign) bound to ADMIN
- RoleController (/api/roles/*): page, saveOrUpdate, detail, assign-resources,
delete — pure hasAuthority, POST + action suffix, form params
- SysRoleServiceImpl.saveRole: roleCode uniqueness, builtin protection,
dataScope 1-4 range, create can't set builtin=true
- assignResources: calls getAncestorIds for ancestor completion, then
full replacement (delete + insert) of sys_role_menu
- getRoleDetail: returns RoleDetailVO with basic info + resourceIds
- deleteRoleCascade: cleans sys_role_menu + sys_user_role, builtin rejection,
three-table transaction
- SystemController: all role endpoints removed, unused deps cleaned
- Dead code removed: assignMenus, getMenuIdsByRoleId (superseded by
assignResources, getRoleDetail)
- H2 test schemas updated with builtin column
- 150 tests pass (16 new in SysRoleServiceImplTest, 7 in SysMenuServiceImplTest)
1 month ago
|
|
|
public Result<RoleDetailVO> detail(@RequestParam Long roleId) {
|
|
|
|
|
return Result.success(sysRoleService.getRoleDetail(roleId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/assign-resources")
|
|
|
|
|
@PreAuthorize("hasAuthority('crm:role:assign')")
|
|
|
|
|
@Operation(summary = "分配角色权限资源(祖先补全+全量替换)", tags = {"系统管理/角色管理"})
|
feat(auth): role management — ancestor completion, CRUD, permission assignment, cascade delete (ADR-0012)
Implements ADR-0005 (backend ancestor completion) and ADR-0012 (role management
architecture) across 5 tracer-bullet tickets:
- ISysMenuService.getAncestorIds: batch query full table, in-memory parentId
traversal, returns complete ancestor set (ADR-0005)
- SysRole.builtin field + DataInitializer idempotent refactor + 5 button
permission seeds (crm:role:list/detail/save/delete/assign) bound to ADMIN
- RoleController (/api/roles/*): page, saveOrUpdate, detail, assign-resources,
delete — pure hasAuthority, POST + action suffix, form params
- SysRoleServiceImpl.saveRole: roleCode uniqueness, builtin protection,
dataScope 1-4 range, create can't set builtin=true
- assignResources: calls getAncestorIds for ancestor completion, then
full replacement (delete + insert) of sys_role_menu
- getRoleDetail: returns RoleDetailVO with basic info + resourceIds
- deleteRoleCascade: cleans sys_role_menu + sys_user_role, builtin rejection,
three-table transaction
- SystemController: all role endpoints removed, unused deps cleaned
- Dead code removed: assignMenus, getMenuIdsByRoleId (superseded by
assignResources, getRoleDetail)
- H2 test schemas updated with builtin column
- 150 tests pass (16 new in SysRoleServiceImplTest, 7 in SysMenuServiceImplTest)
1 month ago
|
|
|
public Result<Void> assignResources(
|
|
|
|
|
@RequestParam Long roleId,
|
|
|
|
|
@RequestParam String resourceIds) {
|
|
|
|
|
List<Long> menuIdList = StrUtil.isBlank(resourceIds)
|
|
|
|
|
? Collections.emptyList()
|
|
|
|
|
: Arrays.stream(resourceIds.split(","))
|
|
|
|
|
.filter(StrUtil::isNotBlank)
|
|
|
|
|
.map(idStr -> Long.valueOf(idStr.trim()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
sysRoleService.assignResources(roleId, menuIdList);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/delete")
|
|
|
|
|
@PreAuthorize("hasAuthority('crm:role:delete')")
|
|
|
|
|
@Operation(summary = "删除角色(级联清理关联表)", tags = {"系统管理/角色管理"})
|
feat(auth): role management — ancestor completion, CRUD, permission assignment, cascade delete (ADR-0012)
Implements ADR-0005 (backend ancestor completion) and ADR-0012 (role management
architecture) across 5 tracer-bullet tickets:
- ISysMenuService.getAncestorIds: batch query full table, in-memory parentId
traversal, returns complete ancestor set (ADR-0005)
- SysRole.builtin field + DataInitializer idempotent refactor + 5 button
permission seeds (crm:role:list/detail/save/delete/assign) bound to ADMIN
- RoleController (/api/roles/*): page, saveOrUpdate, detail, assign-resources,
delete — pure hasAuthority, POST + action suffix, form params
- SysRoleServiceImpl.saveRole: roleCode uniqueness, builtin protection,
dataScope 1-4 range, create can't set builtin=true
- assignResources: calls getAncestorIds for ancestor completion, then
full replacement (delete + insert) of sys_role_menu
- getRoleDetail: returns RoleDetailVO with basic info + resourceIds
- deleteRoleCascade: cleans sys_role_menu + sys_user_role, builtin rejection,
three-table transaction
- SystemController: all role endpoints removed, unused deps cleaned
- Dead code removed: assignMenus, getMenuIdsByRoleId (superseded by
assignResources, getRoleDetail)
- H2 test schemas updated with builtin column
- 150 tests pass (16 new in SysRoleServiceImplTest, 7 in SysMenuServiceImplTest)
1 month ago
|
|
|
public Result<Void> delete(@RequestParam Long id) {
|
|
|
|
|
sysRoleService.deleteRoleCascade(id);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
}
|