mirror of https://gitee.com/stylefeng/roses
【8.0.1】【system】非管理员用户只能删除自己创建的角色
parent
d794054060
commit
b5fd51b697
|
@ -26,7 +26,12 @@ public enum SysRoleExceptionEnum implements AbstractExceptionEnum {
|
||||||
/**
|
/**
|
||||||
* 超级管理员不能被删除
|
* 超级管理员不能被删除
|
||||||
*/
|
*/
|
||||||
SYSTEM_ROLE_CANT_DELETE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10003", "系统角色不能被删除");
|
SYSTEM_ROLE_CANT_DELETE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10003", "系统角色不能被删除"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 非管理员用户,不能删除其他角色
|
||||||
|
*/
|
||||||
|
DEL_PERMISSION_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10004", "非管理员用户,不能删除其他角色");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误编码
|
* 错误编码
|
||||||
|
|
|
@ -65,6 +65,13 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
throw new ServiceException(SysRoleExceptionEnum.SYSTEM_ROLE_CANT_DELETE);
|
throw new ServiceException(SysRoleExceptionEnum.SYSTEM_ROLE_CANT_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 非管理员,只能删除自己的角色
|
||||||
|
if (!LoginContext.me().getSuperAdminFlag()) {
|
||||||
|
if (!sysRole.getCreateUser().equals(LoginContext.me().getLoginUser().getUserId())) {
|
||||||
|
throw new ServiceException(SysRoleExceptionEnum.DEL_PERMISSION_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 删除角色
|
// 删除角色
|
||||||
this.baseDelete(CollectionUtil.set(false, sysRole.getRoleId()));
|
this.baseDelete(CollectionUtil.set(false, sysRole.getRoleId()));
|
||||||
}
|
}
|
||||||
|
@ -82,6 +89,17 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
throw new ServiceException(SysRoleExceptionEnum.SYSTEM_ROLE_CANT_DELETE);
|
throw new ServiceException(SysRoleExceptionEnum.SYSTEM_ROLE_CANT_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果当前用户是非管理员,则只能删除自己创建的角色
|
||||||
|
if (!LoginContext.me().getSuperAdminFlag()) {
|
||||||
|
LambdaQueryWrapper<SysRole> tempWrapper = new LambdaQueryWrapper<>();
|
||||||
|
tempWrapper.in(SysRole::getRoleId, sysRoleRequest.getRoleIdList());
|
||||||
|
tempWrapper.ne(BaseEntity::getCreateUser, LoginContext.me().getLoginUser().getUserId());
|
||||||
|
long notMeCreateCount = this.count(tempWrapper);
|
||||||
|
if (notMeCreateCount > 0) {
|
||||||
|
throw new ServiceException(SysRoleExceptionEnum.DEL_PERMISSION_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 执行删除角色
|
// 执行删除角色
|
||||||
this.baseDelete(sysRoleRequest.getRoleIdList());
|
this.baseDelete(sysRoleRequest.getRoleIdList());
|
||||||
}
|
}
|
||||||
|
@ -188,22 +206,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
return this.list(wrapper);
|
return this.list(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 过滤角色的权限展示
|
|
||||||
* <p>
|
|
||||||
* 非管理员只能看到自己的角色和自己创建的角色
|
|
||||||
*
|
|
||||||
* @author fengshuonan
|
|
||||||
* @since 2023/10/9 10:44
|
|
||||||
*/
|
|
||||||
private void filterRolePermission(LambdaQueryWrapper<SysRole> wrapper) {
|
|
||||||
if (!LoginContext.me().getSuperAdminFlag()) {
|
|
||||||
Long userId = LoginContext.me().getLoginUser().getUserId();
|
|
||||||
wrapper.eq(SysRole::getCreateUser, userId);
|
|
||||||
wrapper.in(SysRole::getRoleId, sysUserRoleServiceApi.getUserRoleIdList(userId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getDefaultRoleId() {
|
public Long getDefaultRoleId() {
|
||||||
|
|
||||||
|
@ -294,4 +296,20 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
// 删除角色
|
// 删除角色
|
||||||
this.removeBatchByIds(roleIdList);
|
this.removeBatchByIds(roleIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过滤角色的权限展示
|
||||||
|
* <p>
|
||||||
|
* 非管理员只能看到自己的角色和自己创建的角色
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @since 2023/10/9 10:44
|
||||||
|
*/
|
||||||
|
private void filterRolePermission(LambdaQueryWrapper<SysRole> wrapper) {
|
||||||
|
if (!LoginContext.me().getSuperAdminFlag()) {
|
||||||
|
Long userId = LoginContext.me().getLoginUser().getUserId();
|
||||||
|
wrapper.eq(SysRole::getCreateUser, userId).or().in(SysRole::getRoleId, sysUserRoleServiceApi.getUserRoleIdList(userId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue