Skip to content

Commit

Permalink
refactor: 优化角色管理相关 API,角色编码不允许修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Apr 13, 2024
1 parent 17c795f commit df59cee
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class RoleQuery implements Serializable {
private static final long serialVersionUID = 1L;

/**
* 名称
* 关键词
*/
@Schema(description = "名称", example = "测试人员")
@Query(columns = {"name", "code"}, type = QueryType.LIKE)
@Schema(description = "关键词", example = "测试人员")
@Query(columns = {"name", "code", "description"}, type = QueryType.LIKE)
private String name;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,12 @@ public Long add(RoleReq req) {
public void update(RoleReq req, Long id) {
String name = req.getName();
CheckUtils.throwIf(this.isNameExists(name, id), "修改失败,[{}] 已存在", name);
String code = req.getCode();
CheckUtils.throwIf(this.isCodeExists(code, id), "修改失败,[{}] 已存在", code);
RoleDO oldRole = super.getById(id);
CheckUtils.throwIfNotEqual(req.getCode(), oldRole.getCode(), "角色编码不允许修改", oldRole.getName());
DataScopeEnum oldDataScope = oldRole.getDataScope();
String oldCode = oldRole.getCode();
if (Boolean.TRUE.equals(oldRole.getIsSystem())) {
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, req.getStatus(), "[{}] 是系统内置角色,不允许禁用", oldRole
.getName());
CheckUtils.throwIfNotEqual(req.getCode(), oldCode, "[{}] 是系统内置角色,不允许修改角色编码", oldRole.getName());
CheckUtils.throwIfNotEqual(req.getDataScope(), oldDataScope, "[{}] 是系统内置角色,不允许修改角色数据权限", oldRole.getName());
}
// 更新信息
Expand All @@ -101,9 +98,8 @@ public void update(RoleReq req, Long id) {
boolean isSaveMenuSuccess = roleMenuService.add(req.getMenuIds(), id);
// 保存角色和部门关联
boolean isSaveDeptSuccess = roleDeptService.add(req.getDeptIds(), id);
// 如果角色编码、功能权限或数据权限有变更,则清除关联的在线用户(重新登录以获取最新角色权限)
if (ObjectUtil.notEqual(req.getCode(), oldCode) || ObjectUtil.notEqual(req
.getDataScope(), oldDataScope) || isSaveMenuSuccess || isSaveDeptSuccess) {
// 如果功能权限或数据权限有变更,则清除关联的在线用户(重新登录以获取最新角色权限)
if (ObjectUtil.notEqual(req.getDataScope(), oldDataScope) || isSaveMenuSuccess || isSaveDeptSuccess) {
onlineUserService.cleanByRoleId(id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import top.charles7c.continew.admin.system.service.RoleService;
import top.charles7c.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.charles7c.continew.starter.extension.crud.controller.BaseController;
import top.charles7c.continew.starter.extension.crud.enums.Api;

/**
* 角色管理 API
Expand All @@ -36,5 +37,5 @@
*/
@Tag(name = "角色管理 API")
@RestController
@CrudRequestMapping("/system/role")
@CrudRequestMapping(value = "/system/role", api = {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE})
public class RoleController extends BaseController<RoleService, RoleResp, RoleDetailResp, RoleQuery, RoleReq> {}
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ VALUES
INSERT INTO `sys_role`
(`id`, `name`, `code`, `data_scope`, `description`, `sort`, `status`, `is_system`, `create_user`, `create_time`, `update_user`, `update_time`)
VALUES
(1, '超级管理员', 'admin', 1, '系统初始角色', 1, 1, b'1', 1, NOW(), NULL, NULL),
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, 1, b'1', 1, NOW(), NULL, NULL),
(547888897925840928, '测试人员', 'test', 5, NULL, 2, 1, b'0', 1, NOW(), NULL, NULL);

-- 初始化默认用户:admin/admin123;test/123456
INSERT INTO `sys_user`
(`id`, `username`, `nickname`, `password`, `gender`, `email`, `phone`, `avatar`, `description`, `status`, `is_system`, `pwd_reset_time`, `dept_id`, `create_user`, `create_time`, `update_user`, `update_time`)
VALUES
(1, 'admin', '超级管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, b'1', NOW(), 1, 1, NOW(), NULL, NULL),
(1, 'admin', '系统管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, b'1', NOW(), 1, 1, NOW(), NULL, NULL),
(547889293968801831, 'test', '测试员', '{bcrypt}$2a$10$meMbyso06lupZjxT88fG8undZo6.DSNUmifRfnnre8r/s13ciq6M6', 2, NULL, NULL, NULL, NULL, 2, b'0', NOW(), 547888483713155087, 1, NOW(), NULL, NULL);

-- 初始化默认参数
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ VALUES
INSERT INTO "sys_role"
("id", "name", "code", "data_scope", "description", "sort", "status", "is_system", "create_user", "create_time", "update_user", "update_time")
VALUES
(1, '超级管理员', 'admin', 1, '系统初始角色', 1, 1, true, 1, NOW(), NULL, NULL),
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, 1, true, 1, NOW(), NULL, NULL),
(547888897925840928, '测试人员', 'test', 5, NULL, 2, 1, false, 1, NOW(), NULL, NULL);

-- 初始化默认用户:admin/admin123;test/123456
INSERT INTO "sys_user"
("id", "username", "nickname", "password", "gender", "email", "phone", "avatar", "description", "status", "is_system", "pwd_reset_time", "dept_id", "create_user", "create_time", "update_user", "update_time")
VALUES
(1, 'admin', '超级管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, true, NOW(), 1, 1, NOW(), NULL, NULL),
(1, 'admin', '系统管理员', '{bcrypt}$2a$10$4jGwK2BMJ7FgVR.mgwGodey8.xR8FLoU1XSXpxJ9nZQt.pufhasSa', 1, '42190c6c5639d2ca4edb4150a35e058559ccf8270361a23745a2fd285a273c28', '5bda89a4609a65546422ea56bfe5eab4', NULL, '系统初始用户', 1, true, NOW(), 1, 1, NOW(), NULL, NULL),
(547889293968801831, 'test', '测试员', '{bcrypt}$2a$10$meMbyso06lupZjxT88fG8undZo6.DSNUmifRfnnre8r/s13ciq6M6', 2, NULL, NULL, NULL, NULL, 2, false, NOW(), 547888483713155087, 1, NOW(), NULL, NULL);

-- 初始化默认参数
Expand Down

0 comments on commit df59cee

Please sign in to comment.