From 5fad997d38f58f689f6a9c1c174c3785abccdfe9 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 21 Sep 2024 11:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=92=E8=89=B2=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E6=9D=83=E9=99=90=E4=B8=8D=E5=A4=B1=E6=95=88=E9=97=AE?= =?UTF-8?q?=E9=A2=98(IAA8ZX)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/common/constant/UserConstants.java | 3 +++ .../com/ruoyi/framework/aspectj/DataScopeAspect.java | 8 ++++---- .../framework/web/service/SysPermissionService.java | 11 ++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java index b09b6f3d5..f2b5ab588 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java @@ -21,6 +21,9 @@ public class UserConstants /** 用户封禁状态 */ public static final String USER_DISABLE = "1"; + /** 角色正常状态 */ + public static final String ROLE_NORMAL = "0"; + /** 角色封禁状态 */ public static final String ROLE_DISABLE = "1"; diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java index 1543ec5b8..719c3711f 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java @@ -7,6 +7,7 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; import com.ruoyi.common.annotation.DataScope; +import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; @@ -73,8 +74,7 @@ public class DataScopeAspect if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) { String permission = StringUtils.defaultIfEmpty(controllerDataScope.permission(), PermissionContextHolder.getContext()); - dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), - controllerDataScope.userAlias(), permission); + dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), controllerDataScope.userAlias(), permission); } } } @@ -94,7 +94,7 @@ public class DataScopeAspect List conditions = new ArrayList(); List scopeCustomIds = new ArrayList(); user.getRoles().forEach(role -> { - if (DATA_SCOPE_CUSTOM.equals(role.getDataScope()) && StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission))) + if (DATA_SCOPE_CUSTOM.equals(role.getDataScope()) && StringUtils.equals(role.getStatus(), UserConstants.ROLE_NORMAL) && StringUtils.containsAny(role.getPermissions(), Convert.toStrArray(permission))) { scopeCustomIds.add(Convert.toStr(role.getRoleId())); } @@ -103,7 +103,7 @@ public class DataScopeAspect for (SysRole role : user.getRoles()) { String dataScope = role.getDataScope(); - if (conditions.contains(dataScope)) + if (conditions.contains(dataScope) || StringUtils.equals(role.getStatus(), UserConstants.ROLE_DISABLE)) { continue; } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java index 640075065..dbfccde27 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java @@ -6,8 +6,10 @@ import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.service.ISysMenuService; import com.ruoyi.system.service.ISysRoleService; @@ -68,9 +70,12 @@ public class SysPermissionService // 多角色设置permissions属性,以便数据权限匹配权限 for (SysRole role : roles) { - Set rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); - role.setPermissions(rolePerms); - perms.addAll(rolePerms); + if (StringUtils.equals(role.getStatus(), UserConstants.ROLE_NORMAL)) + { + Set rolePerms = menuService.selectMenuPermsByRoleId(role.getRoleId()); + role.setPermissions(rolePerms); + perms.addAll(rolePerms); + } } } else