正在显示
12 个修改的文件
包含
99 行增加
和
0 行删除
| @@ -74,6 +74,7 @@ public class SysDeptController extends BaseController | @@ -74,6 +74,7 @@ public class SysDeptController extends BaseController | ||
| 74 | @GetMapping(value = "/{deptId}") | 74 | @GetMapping(value = "/{deptId}") |
| 75 | public AjaxResult getInfo(@PathVariable Long deptId) | 75 | public AjaxResult getInfo(@PathVariable Long deptId) |
| 76 | { | 76 | { |
| 77 | + deptService.checkDeptDataScope(deptId); | ||
| 77 | return AjaxResult.success(deptService.selectDeptById(deptId)); | 78 | return AjaxResult.success(deptService.selectDeptById(deptId)); |
| 78 | } | 79 | } |
| 79 | 80 |
| @@ -76,6 +76,7 @@ public class SysRoleController extends BaseController | @@ -76,6 +76,7 @@ public class SysRoleController extends BaseController | ||
| 76 | @GetMapping(value = "/{roleId}") | 76 | @GetMapping(value = "/{roleId}") |
| 77 | public AjaxResult getInfo(@PathVariable Long roleId) | 77 | public AjaxResult getInfo(@PathVariable Long roleId) |
| 78 | { | 78 | { |
| 79 | + roleService.checkRoleDataScope(roleId); | ||
| 79 | return AjaxResult.success(roleService.selectRoleById(roleId)); | 80 | return AjaxResult.success(roleService.selectRoleById(roleId)); |
| 80 | } | 81 | } |
| 81 | 82 |
| @@ -96,6 +96,7 @@ public class SysUserController extends BaseController | @@ -96,6 +96,7 @@ public class SysUserController extends BaseController | ||
| 96 | @GetMapping(value = { "/", "/{userId}" }) | 96 | @GetMapping(value = { "/", "/{userId}" }) |
| 97 | public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) | 97 | public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) |
| 98 | { | 98 | { |
| 99 | + userService.checkUserDataScope(userId); | ||
| 99 | AjaxResult ajax = AjaxResult.success(); | 100 | AjaxResult ajax = AjaxResult.success(); |
| 100 | List<SysRole> roles = roleService.selectRoleAll(); | 101 | List<SysRole> roles = roleService.selectRoleAll(); |
| 101 | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); | 102 | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| @@ -84,6 +84,13 @@ public interface ISysDeptService | @@ -84,6 +84,13 @@ public interface ISysDeptService | ||
| 84 | public String checkDeptNameUnique(SysDept dept); | 84 | public String checkDeptNameUnique(SysDept dept); |
| 85 | 85 | ||
| 86 | /** | 86 | /** |
| 87 | + * 校验部门是否有数据权限 | ||
| 88 | + * | ||
| 89 | + * @param deptId 部门id | ||
| 90 | + */ | ||
| 91 | + public void checkDeptDataScope(Long deptId); | ||
| 92 | + | ||
| 93 | + /** | ||
| 87 | * 新增保存部门信息 | 94 | * 新增保存部门信息 |
| 88 | * | 95 | * |
| 89 | * @param dept 部门信息 | 96 | * @param dept 部门信息 |
| @@ -83,6 +83,13 @@ public interface ISysRoleService | @@ -83,6 +83,13 @@ public interface ISysRoleService | ||
| 83 | public void checkRoleAllowed(SysRole role); | 83 | public void checkRoleAllowed(SysRole role); |
| 84 | 84 | ||
| 85 | /** | 85 | /** |
| 86 | + * 校验角色是否有数据权限 | ||
| 87 | + * | ||
| 88 | + * @param roleId 角色id | ||
| 89 | + */ | ||
| 90 | + public void checkRoleDataScope(Long roleId); | ||
| 91 | + | ||
| 92 | + /** | ||
| 86 | * 通过角色ID查询角色使用数量 | 93 | * 通过角色ID查询角色使用数量 |
| 87 | * | 94 | * |
| 88 | * @param roleId 角色ID | 95 | * @param roleId 角色ID |
| @@ -98,6 +98,13 @@ public interface ISysUserService | @@ -98,6 +98,13 @@ public interface ISysUserService | ||
| 98 | public void checkUserAllowed(SysUser user); | 98 | public void checkUserAllowed(SysUser user); |
| 99 | 99 | ||
| 100 | /** | 100 | /** |
| 101 | + * 校验用户是否有数据权限 | ||
| 102 | + * | ||
| 103 | + * @param userId 用户id | ||
| 104 | + */ | ||
| 105 | + public void checkUserDataScope(Long userId); | ||
| 106 | + | ||
| 107 | + /** | ||
| 101 | * 新增用户信息 | 108 | * 新增用户信息 |
| 102 | * | 109 | * |
| 103 | * @param user 用户信息 | 110 | * @param user 用户信息 |
| @@ -11,9 +11,12 @@ import com.ruoyi.common.constant.UserConstants; | @@ -11,9 +11,12 @@ import com.ruoyi.common.constant.UserConstants; | ||
| 11 | import com.ruoyi.common.core.domain.TreeSelect; | 11 | import com.ruoyi.common.core.domain.TreeSelect; |
| 12 | import com.ruoyi.common.core.domain.entity.SysDept; | 12 | import com.ruoyi.common.core.domain.entity.SysDept; |
| 13 | import com.ruoyi.common.core.domain.entity.SysRole; | 13 | import com.ruoyi.common.core.domain.entity.SysRole; |
| 14 | +import com.ruoyi.common.core.domain.entity.SysUser; | ||
| 14 | import com.ruoyi.common.core.text.Convert; | 15 | import com.ruoyi.common.core.text.Convert; |
| 15 | import com.ruoyi.common.exception.ServiceException; | 16 | import com.ruoyi.common.exception.ServiceException; |
| 17 | +import com.ruoyi.common.utils.SecurityUtils; | ||
| 16 | import com.ruoyi.common.utils.StringUtils; | 18 | import com.ruoyi.common.utils.StringUtils; |
| 19 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 17 | import com.ruoyi.system.mapper.SysDeptMapper; | 20 | import com.ruoyi.system.mapper.SysDeptMapper; |
| 18 | import com.ruoyi.system.mapper.SysRoleMapper; | 21 | import com.ruoyi.system.mapper.SysRoleMapper; |
| 19 | import com.ruoyi.system.service.ISysDeptService; | 22 | import com.ruoyi.system.service.ISysDeptService; |
| @@ -172,6 +175,26 @@ public class SysDeptServiceImpl implements ISysDeptService | @@ -172,6 +175,26 @@ public class SysDeptServiceImpl implements ISysDeptService | ||
| 172 | } | 175 | } |
| 173 | 176 | ||
| 174 | /** | 177 | /** |
| 178 | + * 校验部门是否有数据权限 | ||
| 179 | + * | ||
| 180 | + * @param deptId 部门id | ||
| 181 | + */ | ||
| 182 | + @Override | ||
| 183 | + public void checkDeptDataScope(Long deptId) | ||
| 184 | + { | ||
| 185 | + if (!SysUser.isAdmin(SecurityUtils.getUserId())) | ||
| 186 | + { | ||
| 187 | + SysDept dept = new SysDept(); | ||
| 188 | + dept.setDeptId(deptId); | ||
| 189 | + List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); | ||
| 190 | + if (StringUtils.isEmpty(depts)) | ||
| 191 | + { | ||
| 192 | + throw new ServiceException("没有权限访问部门数据!"); | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /** | ||
| 175 | * 新增保存部门信息 | 198 | * 新增保存部门信息 |
| 176 | * | 199 | * |
| 177 | * @param dept 部门信息 | 200 | * @param dept 部门信息 |
| @@ -11,7 +11,9 @@ import org.springframework.transaction.annotation.Transactional; | @@ -11,7 +11,9 @@ import org.springframework.transaction.annotation.Transactional; | ||
| 11 | import com.ruoyi.common.annotation.DataScope; | 11 | import com.ruoyi.common.annotation.DataScope; |
| 12 | import com.ruoyi.common.constant.UserConstants; | 12 | import com.ruoyi.common.constant.UserConstants; |
| 13 | import com.ruoyi.common.core.domain.entity.SysRole; | 13 | import com.ruoyi.common.core.domain.entity.SysRole; |
| 14 | +import com.ruoyi.common.core.domain.entity.SysUser; | ||
| 14 | import com.ruoyi.common.exception.ServiceException; | 15 | import com.ruoyi.common.exception.ServiceException; |
| 16 | +import com.ruoyi.common.utils.SecurityUtils; | ||
| 15 | import com.ruoyi.common.utils.StringUtils; | 17 | import com.ruoyi.common.utils.StringUtils; |
| 16 | import com.ruoyi.common.utils.spring.SpringUtils; | 18 | import com.ruoyi.common.utils.spring.SpringUtils; |
| 17 | import com.ruoyi.system.domain.SysRoleDept; | 19 | import com.ruoyi.system.domain.SysRoleDept; |
| @@ -188,6 +190,26 @@ public class SysRoleServiceImpl implements ISysRoleService | @@ -188,6 +190,26 @@ public class SysRoleServiceImpl implements ISysRoleService | ||
| 188 | } | 190 | } |
| 189 | 191 | ||
| 190 | /** | 192 | /** |
| 193 | + * 校验角色是否有数据权限 | ||
| 194 | + * | ||
| 195 | + * @param roleId 角色id | ||
| 196 | + */ | ||
| 197 | + @Override | ||
| 198 | + public void checkRoleDataScope(Long roleId) | ||
| 199 | + { | ||
| 200 | + if (!SysUser.isAdmin(SecurityUtils.getUserId())) | ||
| 201 | + { | ||
| 202 | + SysRole role = new SysRole(); | ||
| 203 | + role.setRoleId(roleId); | ||
| 204 | + List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); | ||
| 205 | + if (StringUtils.isEmpty(roles)) | ||
| 206 | + { | ||
| 207 | + throw new ServiceException("没有权限访问角色数据!"); | ||
| 208 | + } | ||
| 209 | + } | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + /** | ||
| 191 | * 通过角色ID查询角色使用数量 | 213 | * 通过角色ID查询角色使用数量 |
| 192 | * | 214 | * |
| 193 | * @param roleId 角色ID | 215 | * @param roleId 角色ID |
| @@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.entity.SysUser; | @@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.entity.SysUser; | ||
| 14 | import com.ruoyi.common.exception.ServiceException; | 14 | import com.ruoyi.common.exception.ServiceException; |
| 15 | import com.ruoyi.common.utils.SecurityUtils; | 15 | import com.ruoyi.common.utils.SecurityUtils; |
| 16 | import com.ruoyi.common.utils.StringUtils; | 16 | import com.ruoyi.common.utils.StringUtils; |
| 17 | +import com.ruoyi.common.utils.spring.SpringUtils; | ||
| 17 | import com.ruoyi.system.domain.SysPost; | 18 | import com.ruoyi.system.domain.SysPost; |
| 18 | import com.ruoyi.system.domain.SysUserPost; | 19 | import com.ruoyi.system.domain.SysUserPost; |
| 19 | import com.ruoyi.system.domain.SysUserRole; | 20 | import com.ruoyi.system.domain.SysUserRole; |
| @@ -228,6 +229,26 @@ public class SysUserServiceImpl implements ISysUserService | @@ -228,6 +229,26 @@ public class SysUserServiceImpl implements ISysUserService | ||
| 228 | } | 229 | } |
| 229 | 230 | ||
| 230 | /** | 231 | /** |
| 232 | + * 校验用户是否有数据权限 | ||
| 233 | + * | ||
| 234 | + * @param userId 用户id | ||
| 235 | + */ | ||
| 236 | + @Override | ||
| 237 | + public void checkUserDataScope(Long userId) | ||
| 238 | + { | ||
| 239 | + if (!SysUser.isAdmin(SecurityUtils.getUserId())) | ||
| 240 | + { | ||
| 241 | + SysUser user = new SysUser(); | ||
| 242 | + user.setUserId(userId); | ||
| 243 | + List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user); | ||
| 244 | + if (StringUtils.isEmpty(users)) | ||
| 245 | + { | ||
| 246 | + throw new ServiceException("没有权限访问用户数据!"); | ||
| 247 | + } | ||
| 248 | + } | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + /** | ||
| 231 | * 新增保存用户信息 | 252 | * 新增保存用户信息 |
| 232 | * | 253 | * |
| 233 | * @param user 用户信息 | 254 | * @param user 用户信息 |
| @@ -30,6 +30,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -30,6 +30,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 30 | <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult"> | 30 | <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult"> |
| 31 | <include refid="selectDeptVo"/> | 31 | <include refid="selectDeptVo"/> |
| 32 | where d.del_flag = '0' | 32 | where d.del_flag = '0' |
| 33 | + <if test="deptId != null and deptId != 0"> | ||
| 34 | + AND dept_id = #{deptId} | ||
| 35 | + </if> | ||
| 33 | <if test="parentId != null and parentId != 0"> | 36 | <if test="parentId != null and parentId != 0"> |
| 34 | AND parent_id = #{parentId} | 37 | AND parent_id = #{parentId} |
| 35 | </if> | 38 | </if> |
| @@ -33,6 +33,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -33,6 +33,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 33 | <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult"> | 33 | <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult"> |
| 34 | <include refid="selectRoleVo"/> | 34 | <include refid="selectRoleVo"/> |
| 35 | where r.del_flag = '0' | 35 | where r.del_flag = '0' |
| 36 | + <if test="roleId != null and roleId != 0"> | ||
| 37 | + AND r.role_id = #{roleId} | ||
| 38 | + </if> | ||
| 36 | <if test="roleName != null and roleName != ''"> | 39 | <if test="roleName != null and roleName != ''"> |
| 37 | AND r.role_name like concat('%', #{roleName}, '%') | 40 | AND r.role_name like concat('%', #{roleName}, '%') |
| 38 | </if> | 41 | </if> |
| @@ -59,6 +59,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -59,6 +59,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 59 | select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u | 59 | select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u |
| 60 | left join sys_dept d on u.dept_id = d.dept_id | 60 | left join sys_dept d on u.dept_id = d.dept_id |
| 61 | where u.del_flag = '0' | 61 | where u.del_flag = '0' |
| 62 | + <if test="userId != null and userId != 0"> | ||
| 63 | + AND u.user_id = #{userId} | ||
| 64 | + </if> | ||
| 62 | <if test="userName != null and userName != ''"> | 65 | <if test="userName != null and userName != ''"> |
| 63 | AND u.user_name like concat('%', #{userName}, '%') | 66 | AND u.user_name like concat('%', #{userName}, '%') |
| 64 | </if> | 67 | </if> |
-
请 注册 或 登录 后发表评论