Преглед изворни кода

优化数据权限,去除数据过滤条件判断更严谨,只有数据范围是全部才会去除数据过滤条件,超级管理员和租户管理员查询数据权限时数据范围默认全部不受数据过滤条件控制
初始化数据普通员工角色数据权限默认为本人

zhontai пре 1 година
родитељ
комит
f6481d828a

+ 1 - 1
src/hosts/ZhonTai.Host/InitData/Admin/ad_role.json

@@ -25,7 +25,7 @@
     "name": "普通员工",
     "code": "emp",
     "type": 2,
-    "dataScope": 1,
+    "dataScope": 4,
     "description": "",
     "hidden": false,
     "sort": 3,

+ 1 - 1
src/hosts/ZhonTai.Host/InitData/Admin/ad_role.tenant.json

@@ -27,7 +27,7 @@
     "name": "普通员工",
     "code": "emp",
     "type": 2,
-    "dataScope": 1,
+    "dataScope": 4,
     "description": "",
     "hidden": false,
     "sort": 3,

+ 2 - 0
src/hosts/ZhonTai.Host/Program.cs

@@ -118,6 +118,8 @@ new HostApp(new HostAppOptions
             });
 		}
         #endregion
+
+        app.UseTaskScheduler();
 	}
 }).Run(args);
 

+ 2 - 2
src/platform/ZhonTai.Admin/Core/Db/DBServiceCollectionExtensions.cs

@@ -40,10 +40,10 @@ public static class DBServiceCollectionExtensions
         services.AddSingleton<IFreeSql>(freeSqlCloud);
         services.AddSingleton(freeSqlCloud);
         services.AddScoped<UnitOfWorkManagerCloud>();
-        //定义基础仓储主库
+        //定义主库
         var fsql = freeSqlCloud.Use(dbConfig.Key);
         services.AddSingleton(provider => fsql);
-        //运行数据库注册方法
+        //运行主库
         fsql.Select<object>();
     }
 

+ 12 - 17
src/platform/ZhonTai.Admin/Core/Db/DbHelper.cs

@@ -533,7 +533,9 @@ public class DbHelper
                 () =>
                 {
                     if (user?.Id > 0 && user.Type != UserType.Member)
+                    {
                         return false;
+                    }
                     return true;
                 },
                 a => a.MemberId == user.Id
@@ -543,24 +545,24 @@ public class DbHelper
             fsql.GlobalFilter.ApplyOnlyIf<IData>(FilterNames.Self,
                 () =>
                 {
-                    if (!(user?.Id > 0))
-                        return false;
                     var dataPermission = user.DataPermission;
-                    if (user.Type == UserType.DefaultUser && dataPermission != null)
-                        return dataPermission.DataScope != DataScope.All && dataPermission.OrgIds.Count == 0;
-                    return false;
+                    if (dataPermission != null && (dataPermission.DataScope == DataScope.All || dataPermission.OrgIds.Count > 0))
+                    {
+                        return false;
+                    }
+                    return true;
                 },
                 a => a.OwnerId == user.Id
             );
             fsql.GlobalFilter.ApplyOnlyIf<IData>(FilterNames.Data,
                 () =>
                 {
-                    if (!(user?.Id > 0))
-                        return false;
                     var dataPermission = user.DataPermission;
-                    if (user.Type == UserType.DefaultUser && dataPermission != null)
-                        return dataPermission.DataScope != DataScope.All && dataPermission.OrgIds.Count > 0;
-                    return false;
+                    if (dataPermission == null || (dataPermission != null && (dataPermission.DataScope == DataScope.All || dataPermission.OrgIds.Count == 0)))
+                    {
+                        return false;
+                    }
+                    return true;
                 },
                 a => a.OwnerId == user.Id || user.DataPermission.OrgIds.Contains(a.OwnerOrgId.Value)
             );
@@ -595,12 +597,5 @@ public class DbHelper
 
             return fsql;
         }, idelTime);
-
-        //执行注册数据库
-        var fsql = freeSqlCloud.Use(dbConfig.Key);
-        if (dbConfig.SyncStructure)
-        {
-            var _ = fsql.CodeFirst;
-        }
     }
 }

+ 1 - 2
src/platform/ZhonTai.Admin/Services/Tenant/TenantService.cs

@@ -26,7 +26,6 @@ using Yitter.IdGenerator;
 using ZhonTai.Admin.Domain.Pkg;
 using ZhonTai.Admin.Domain.TenantPkg;
 using ZhonTai.Admin.Services.Pkg;
-using ZhonTai.Admin.Core.Entities;
 
 namespace ZhonTai.Admin.Services.Tenant;
 
@@ -287,7 +286,7 @@ public class TenantService : BaseService, ITenantService, IDynamicApi
                     Name = "普通员工",
                     Code = "emp",
                     ParentId = jobGroupId,
-                    DataScope = DataScope.All,
+                    DataScope = DataScope.Self,
                     Sort = 2
                 }
             };

+ 1 - 1
src/platform/ZhonTai.Admin/Services/User/UserService.cs

@@ -237,7 +237,7 @@ public partial class UserService : BaseService, IUserService, IDynamicApi
                 {
                     OrgId = user.OrgId,
                     OrgIds = orgIds.Distinct().ToList(),
-                    DataScope = dataScope
+                    DataScope = (User.PlatformAdmin || User.TenantAdmin) ? DataScope.All : dataScope
                 };
             }
         });