mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-14 10:57:19 +08:00
refactor: 优化角色管理相关 API,角色编码不允许修改
This commit is contained in:
@@ -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;
|
||||
|
||||
/**
|
||||
|
@@ -82,15 +82,12 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
||||
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());
|
||||
}
|
||||
// 更新信息
|
||||
@@ -101,9 +98,8 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user