mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-24 03:18:35 +08:00
update 优化 校验角色是否有数据权限
This commit is contained in:
@@ -62,6 +62,7 @@ public class SysTenantBo extends BaseEntity {
|
||||
* 密码(创建系统用户)
|
||||
*/
|
||||
@NotBlank(message = "密码不能为空", groups = { AddGroup.class })
|
||||
// @Pattern(regexp = RegexConstants.PASSWORD, message = "{user.password.format.valid}", groups = { AddGroup.class })
|
||||
private String password;
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,6 +118,13 @@ public interface ISysRoleService {
|
||||
*/
|
||||
void checkRoleDataScope(Long roleId);
|
||||
|
||||
/**
|
||||
* 校验角色是否有数据权限
|
||||
*
|
||||
* @param roleIds 角色ID列表(支持传单个ID)
|
||||
*/
|
||||
void checkRoleDataScope(List<Long> roleIds);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
|
||||
@@ -253,14 +253,23 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
if (ObjectUtil.isNull(roleId)) {
|
||||
return;
|
||||
}
|
||||
if (LoginHelper.isSuperAdmin()) {
|
||||
this.checkRoleDataScope(Collections.singletonList(roleId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色是否有数据权限
|
||||
*
|
||||
* @param roleIds 角色ID列表(支持传单个ID)
|
||||
*/
|
||||
@Override
|
||||
public void checkRoleDataScope(List<Long> roleIds) {
|
||||
if (CollUtil.isEmpty(roleIds) || LoginHelper.isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
List<SysRoleVo> roles = this.selectRoleList(new SysRoleBo(roleId));
|
||||
if (CollUtil.isEmpty(roles)) {
|
||||
throw new ServiceException("没有权限访问角色数据!");
|
||||
long count = baseMapper.selectRoleCount(roleIds);
|
||||
if (count != roleIds.size()) {
|
||||
throw new ServiceException("没有权限访问部分角色数据!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,10 +426,10 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteRoleByIds(List<Long> roleIds) {
|
||||
checkRoleDataScope(roleIds);
|
||||
List<SysRole> roles = baseMapper.selectByIds(roleIds);
|
||||
for (SysRole role : roles) {
|
||||
checkRoleAllowed(BeanUtil.toBean(role, SysRoleBo.class));
|
||||
checkRoleDataScope(role.getRoleId());
|
||||
if (countUserRoleByRoleId(role.getRoleId()) > 0) {
|
||||
throw new ServiceException(String.format("%1$s已分配,不能删除!", role.getRoleName()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user