mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-09-13 08:25:00 +00:00
feat(register): 新用户注册成功后绑定默认角色并补齐缺失菜单权限
- SysRegisterService: 注册成功后读取 sys.register.defaultRoleId 配置, 为新用户绑定默认角色;未配置则静默跳过,不影响注册流程 - SysUserServiceImpl.registerUser: insert 后回写 userId 主键, 供调用方绑定默认角色或登录使用 - SQL: 修正 知识管理 父菜单 perms(knowledge:info:list -> system:info:list), 新增 system:session:* / system:attach:* / system:fragment:* 菜单, 新建 普通用户 角色(租户 000000,data_scope=5 仅本人)及角色-菜单关联, 写入 sys.register.defaultRoleId 配置项 解决注册用户无默认角色导致无权限访问 AI 对话界面、以及菜单权限标识 与控制器不一致无法授权的问题。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.ruoyi.system.service;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -35,6 +36,12 @@ public class SysRegisterService {
|
||||
private final ISysUserService userService;
|
||||
private final SysUserMapper userMapper;
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final ISysConfigService configService;
|
||||
|
||||
/**
|
||||
* 注册默认角色配置 key,值为角色 ID;未配置或为空则不绑定角色。
|
||||
*/
|
||||
private static final String DEFAULT_ROLE_CONFIG_KEY = "sys.register.defaultRoleId";
|
||||
|
||||
/**
|
||||
* 注册
|
||||
@@ -68,9 +75,27 @@ public class SysRegisterService {
|
||||
if (!regFlag) {
|
||||
throw new UserException("user.register.error");
|
||||
}
|
||||
// 绑定默认角色(未配置则跳过,不影响注册流程)
|
||||
bindDefaultRole(tenantId, sysUser.getUserId());
|
||||
recordLogininfor(tenantId, username, Constants.REGISTER, MessageUtils.message("user.register.success"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取配置 sys.register.defaultRoleId 并为新用户绑定默认角色。
|
||||
* 配置为空或角色 ID 无效时静默跳过。
|
||||
*/
|
||||
private void bindDefaultRole(String tenantId, Long userId) {
|
||||
if (userId == null) {
|
||||
return;
|
||||
}
|
||||
Long defaultRoleId = TenantHelper.dynamic(tenantId, () ->
|
||||
Convert.toLong(configService.selectConfigByKey(DEFAULT_ROLE_CONFIG_KEY), null));
|
||||
if (defaultRoleId == null) {
|
||||
return;
|
||||
}
|
||||
userService.insertUserAuth(userId, new Long[]{defaultRoleId});
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
|
||||
@@ -333,7 +333,10 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
user.setUpdateBy(0L);
|
||||
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
|
||||
sysUser.setTenantId(tenantId);
|
||||
return baseMapper.insert(sysUser) > 0;
|
||||
boolean rows = baseMapper.insert(sysUser) > 0;
|
||||
// 回写主键,调用方(注册服务、mpLogin)需要用 userId 绑定默认角色或登录
|
||||
user.setUserId(sysUser.getUserId());
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user