管理员用户&角色不允许操作

This commit is contained in:
RuoYi
2019-10-03 09:45:41 +08:00
parent ac97d15a7f
commit 661b6fe5d5
11 changed files with 82 additions and 18 deletions

View File

@ -52,6 +52,16 @@ public class SysRole extends BaseEntity
/** 部门组(数据权限) */
private Long[] deptIds;
public SysRole()
{
}
public SysRole(Long roleId)
{
this.roleId = roleId;
}
public Long getRoleId()
{
return roleId;
@ -62,6 +72,16 @@ public class SysRole extends BaseEntity
this.roleId = roleId;
}
public boolean isAdmin()
{
return isAdmin(this.roleId);
}
public static boolean isAdmin(Long roleId)
{
return roleId != null && 1L == roleId;
}
public String getDataScope()
{
return dataScope;

View File

@ -93,6 +93,16 @@ public class SysUser extends BaseEntity
/** 岗位组 */
private Long[] postIds;
public SysUser()
{
}
public SysUser(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;

View File

@ -108,6 +108,13 @@ public interface ISysRoleService
*/
public String checkRoleKeyUnique(SysRole role);
/**
* 校验角色是否允许操作
*
* @param role 角色信息
*/
public void checkRoleAllowed(SysRole role);
/**
* 通过角色ID查询角色使用数量
*
@ -123,6 +130,7 @@ public interface ISysRoleService
* @return 结果
*/
public int changeStatus(SysRole role);
/**
* 取消授权用户角色
*
@ -139,7 +147,7 @@ public interface ISysRoleService
* @return 结果
*/
public int deleteAuthUsers(Long roleId, String userIds);
/**
* 批量选择授权用户角色
*

View File

@ -139,6 +139,13 @@ public interface ISysUserService
*/
public String checkEmailUnique(SysUser user);
/**
* 校验用户是否允许操作
*
* @param user 用户信息
*/
public void checkUserAllowed(SysUser user);
/**
* 根据用户ID查询用户所属角色组
*

View File

@ -150,6 +150,7 @@ public class SysRoleServiceImpl implements ISysRoleService
Long[] roleIds = Convert.toLongArray(ids);
for (Long roleId : roleIds)
{
checkRoleAllowed(new SysRole(roleId));
SysRole role = selectRoleById(roleId);
if (countUserRoleByRoleId(roleId) > 0)
{
@ -293,6 +294,19 @@ public class SysRoleServiceImpl implements ISysRoleService
return UserConstants.ROLE_KEY_UNIQUE;
}
/**
* 校验角色是否允许操作
*
* @param role 角色信息
*/
public void checkRoleAllowed(SysRole role)
{
if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin())
{
throw new BusinessException("不允许操作超级管理员角色");
}
}
/**
* 通过角色ID查询角色使用数量
*

View File

@ -167,10 +167,7 @@ public class SysUserServiceImpl implements ISysUserService
Long[] userIds = Convert.toLongArray(ids);
for (Long userId : userIds)
{
if (SysUser.isAdmin(userId))
{
throw new BusinessException("不允许删除超级管理员用户");
}
checkUserAllowed(new SysUser(userId));
}
return userMapper.deleteUserByIds(userIds);
}
@ -345,6 +342,19 @@ public class SysUserServiceImpl implements ISysUserService
return UserConstants.USER_EMAIL_UNIQUE;
}
/**
* 校验用户是否允许操作
*
* @param user 用户信息
*/
public void checkUserAllowed(SysUser user)
{
if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin())
{
throw new BusinessException("不允许操作超级管理员用户");
}
}
/**
* 查询用户所属角色组
*
@ -465,10 +475,6 @@ public class SysUserServiceImpl implements ISysUserService
@Override
public int changeStatus(SysUser user)
{
if (SysUser.isAdmin(user.getUserId()))
{
throw new BusinessException("不允许修改超级管理员用户");
}
return userMapper.updateUser(user);
}
}