Browse Source

数据权限

Dun.Jason 2 years ago
parent
commit
121c53a1ce

+ 0 - 1
src/Hotline.Repository.SqlSugar/DataPermissions/DataPermissionFilterBuilder.cs

@@ -33,7 +33,6 @@ public class DataPermissionFilterBuilder : IDataPermissionFilterBuilder, IScopeD
                 return d => true;
             default:
                 return d => false;
-                //throw new ArgumentOutOfRangeException();
         }
     }
 }

+ 5 - 9
src/Hotline.Repository.SqlSugar/DataPermissions/DataPermissionManager.cs

@@ -53,16 +53,12 @@ public class DataPermissionManager : IDataPermissionManager, IScopeDependency
     {
         using var scope = _serviceScopeFactory.CreateScope();
         var systemDataTableRepository = scope.ServiceProvider.GetService<ISystemDataTableRepository>();
-        var systemDataAuthorityRepository = scope.ServiceProvider.GetService<ISystemDataTableRepository>();
+        var systemDataAuthorityRepository = scope.ServiceProvider.GetService<ISystemDataAuthorityRepository>();
 
         ////查询对应表配置
-        //var tableModel = _systemDataTableRepository.GetAsync(x => x.EntityName == entityName).Result;
-        ////查询表对应数据权限
-        //var authList = _systemDataAuthorityRepository.QueryExtAsync(x => roles.Contains(x.RoleCode),null,x=>x.OrderBy(d=>d.AuthorityType)).Result;
-        //if (authList!=null && authList.Count>0)
-        //{
-        //    return (EAuthorityType)authList[0].AuthorityType;
-        //}
-        return null;
+        var tableModel = systemDataTableRepository!.GetAsync(x => x.EntityName == entityName).Result;
+        ////查询表对应最高数据权限
+        var auth = systemDataAuthorityRepository!.GetMyTopDataAuth(roles, tableModel!.Id);
+        return auth;
     }
 }

+ 7 - 0
src/Hotline.Repository.SqlSugar/System/SystemDataAuthorityRepository.cs

@@ -1,5 +1,6 @@
 using Hotline.Repository.SqlSugar.DataPermissions;
 using Hotline.Settings;
+using Hotline.Share.Enums;
 using SqlSugar;
 using XF.Domain.Dependency;
 
@@ -10,5 +11,11 @@ namespace Hotline.Repository.SqlSugar.System
         public SystemDataAuthorityRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder) : base(uow, dataPermissionFilterBuilder)
         {
         }
+
+        public EAuthorityType? GetMyTopDataAuth(string[] roles,string tableid)
+        {
+            var dataAuth =Db.Queryable<SystemDataAuthority>().Where(x => roles.Contains(x.RoleCode) && x.TableId == tableid).Min(x=>x.AuthorityType);
+            return dataAuth;
+        }
     }
 }

+ 3 - 1
src/Hotline/Settings/ISystemDataAuthorityRepository.cs

@@ -1,8 +1,10 @@
-using XF.Domain.Repository;
+using Hotline.Share.Enums;
+using XF.Domain.Repository;
 
 namespace Hotline.Settings
 {
     public interface ISystemDataAuthorityRepository : IRepository<SystemDataAuthority>
     {
+        EAuthorityType? GetMyTopDataAuth(string[] roles, string tableid);
     }
 }