Browse Source

更新权限验证逻辑和默认值初始化

在 `EnterExitCostDraftView.cs` 中,将 `ViewUsers` 属性的默认值更改为 `Array.Empty<int>()`,以避免为 `null` 的情况。

在 `EnterExitCostDraftRepository.cs` 和 `EnterExitCostRepository.cs` 中,修改 `PermissionValidationAsync` 方法的参数,新增 `userId`,并增加对其有效性的检查,同时更新查询条件以支持基于用户 ID 的权限验证。

更新权限验证和默认值设置

在 `EnterExitCostDraftView.cs` 和 `EnterExitCostView.cs` 中,将 `ViewUsers` 属性的默认值更改为 `Array.Empty<int>()`,以确保在没有用户时初始化为空数组。
同时,在 `EnterExitCostDraftRepository.cs` 和 `EnterExitCostRepository.cs` 中,修改 `PermissionValidationAsync` 方法的参数,增加 `userId` 验证,并确保其值大于 0,以提高权限验证的准确性。
LEIYI 1 week ago
parent
commit
6e427cef76

+ 1 - 1
OASystem/OASystem.Domain/ViewModels/Groups/EnterExitCostDraftView.cs

@@ -20,7 +20,7 @@ namespace OASystem.Domain.ViewModels.Groups
         public bool IsSave { get; set; }
         public bool IsView { get; set; } = false;
 
-        public int[] ViewUsers { get; set; }
+        public int[] ViewUsers { get; set; } = Array.Empty<int>();
 
         /// <summary>
         /// Id

+ 1 - 1
OASystem/OASystem.Domain/ViewModels/Groups/EnterExitCostView.cs

@@ -262,7 +262,7 @@ namespace OASystem.Domain.ViewModels.Groups
         public bool IsSave { get; set; }
         public bool IsView { get; set; } = false;
 
-        public int[] ViewUsers { get; set; }
+        public int[] ViewUsers { get; set; } = Array.Empty<int>();
 
         /// <summary>
         /// Id

+ 2 - 2
OASystem/OASystem.Infrastructure/Repositories/Groups/EnterExitCostDraftRepository.cs

@@ -35,7 +35,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
         /// <param name="groupId">草稿Id</param>
         /// <param name="permission">操作权限 1:查看;2:新增;3:编辑;4:删除;5:下载; </param>
         /// <returns></returns>
-        public async Task<bool> PermissionValidationAsync(int groupId, int permission)
+        public async Task<bool> PermissionValidationAsync(int groupId, int userId, int permission=1)
         {
             //参数验证
             if (groupId < 1) return false;
@@ -43,7 +43,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
             if (!permissionIds.Contains(permission)) return false;
 
             var info = await _sqlSugar.Queryable<Grp_EnterExitCostDraftPermission>()
-                     .Where(it => it.DraftId == groupId && it.Permission == permission)
+                     .Where(it => it.DraftId == groupId && it.UserId == userId && it.Permission == permission)
                      .FirstAsync();
             if (info != null) return true;
 

+ 3 - 2
OASystem/OASystem.Infrastructure/Repositories/Groups/EnterExitCostRepository.cs

@@ -38,15 +38,16 @@ namespace OASystem.Infrastructure.Repositories.Groups
         /// <param name="groupId">团组Id</param>
         /// <param name="permission">操作权限 1:查看;2:新增;3:编辑;4:删除;5:下载; </param>
         /// <returns></returns>
-        public async Task<bool> PermissionValidationAsync(int groupId, int permission)
+        public async Task<bool> PermissionValidationAsync(int groupId, int userId, int permission = 1)
         {
             //参数验证
             if (groupId < 1) return false;
+            if (userId < 1) return false;
             var permissionIds = new List<int>() { 1, 2, 3, 4, 5 };
             if (!permissionIds.Contains(permission)) return false;
 
             var info = await _sqlSugar.Queryable<Grp_EnterExitCostPermission>()
-                     .Where(it => it.GroupId == groupId && it.Permission == permission)
+                     .Where(it => it.GroupId == groupId && it.UserId == userId && it.Permission == permission)
                      .FirstAsync();
             if (info != null) return true;