Browse Source

优化用户权限查询和验证逻辑

在 `GroupsController.cs` 中,调整了用户权限查询条件,以便更灵活地控制用户访问权限。
在 `EnterExitCostDraftRepository.cs` 和 `EnterExitCostRepository.cs` 中,添加了对数据的权限验证,确保用户在查看草稿和出入境费用时能够正确获取权限信息,并返回相应的提示信息。这些改动增强了系统对用户权限的管理和控制。
LEIYI 1 week ago
parent
commit
3f411c77a4

+ 4 - 2
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -5401,7 +5401,8 @@ FROM
             }
             var gj_jobPostIds = new List<int>() { 22, 32 };
             var viewPermissionData = await _sqlSugar.Queryable<Sys_Users>()
-                .Where(x => x.IsDel == 0 && (x.DepId == 7 || gj_jobPostIds.Contains(x.JobPostId)) && x.DepId == 6)
+                .Where(x => x.IsDel == 0 && ((x.DepId == 7 && gj_jobPostIds.Contains(x.JobPostId)) || x.DepId == 6))
+                .Select(x => new { x.Id, Name = x.CnName })
                 .ToListAsync();
             return Ok(JsonView(true, "查询成功!", new
             {
@@ -7547,7 +7548,8 @@ FROM
 
             var gj_jobPostIds = new List<int>() { 22, 32 };
             var viewPermissionData = await _sqlSugar.Queryable<Sys_Users>()
-                .Where(x => x.IsDel == 0 && (x.DepId == 7 || gj_jobPostIds.Contains(x.JobPostId)) && x.DepId == 6)
+                .Where(x => x.IsDel == 0 && ((x.DepId == 7 && gj_jobPostIds.Contains(x.JobPostId)) || x.DepId == 6))
+                .Select(x => new { x.Id, Name = x.CnName })
                 .ToListAsync();
 
             return Ok(JsonView(true, "查询成功!", new

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

@@ -68,15 +68,20 @@ namespace OASystem.Infrastructure.Repositories.Groups
             {
                 if (enterExitCostDraftData != null)
                 {
+
+                    enterExitCostInfoView = _mapper.Map<EnterExitCostDraftInfoView>(enterExitCostDraftData);
+
                     var isView = await PermissionValidationAsync(enterExitCostDraftData.Id, dto.CurrUserId);
 
+                    if (isView) enterExitCostInfoView.IsView = true; //查看权限
+
                     if (enterExitCostDraftData.CreateUserId == dto.CurrUserId)
                     {
                         enterExitCostInfoView.IsSave = true; //操作权限
                         enterExitCostInfoView.IsView = true; //查看权限
                     }
 
-                    if (!isView)
+                    if (!enterExitCostInfoView.IsView)
                     {
                         var setUserName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == enterExitCostDraftData.CreateUserId).Select(x => x.CnName).FirstAsync();
 
@@ -84,7 +89,6 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         return result;
                     }
 
-                    enterExitCostInfoView = _mapper.Map<EnterExitCostDraftInfoView>(enterExitCostDraftData);
 
                     var dayAndCostDraftSql = string.Format(@"Select ntf.Country,ntf.City,ssd.Name CurremcyCode,ssd.Remark CurrencyName,gdac.* From Grp_DayAndCostDraft gdac
                                                         Left Join Grp_NationalTravelFee ntf On ntf.Id = gdac.NationalTravelFeeId

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

@@ -102,27 +102,31 @@ namespace OASystem.Infrastructure.Repositories.Groups
             {
                 if (enterExitCostData != null)
                 {
+                    enterExitCostInfoView = _mapper.Map<EnterExitCostInfoView>(enterExitCostData);
+
                     var isView = await PermissionValidationAsync(dto.DiId, dto.CurrUserId);
+                    if (isView) enterExitCostInfoView.IsView = true; //查看权限
 
                     if (enterExitCostData.CreateUserId == dto.CurrUserId) {
                         enterExitCostInfoView.IsSave = true; //操作权限
                         enterExitCostInfoView.IsView = true; //查看权限
                     }
 
-                    if (!isView)
+
+                    if (!enterExitCostInfoView.IsView)
                     {
                         var setUserName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == enterExitCostData.CreateUserId).Select(x => x.CnName).FirstAsync();
 
                         result.Msg = $"{setUserName}设置了你不能查看当前团组的出入境费用明细数据,如要查看,请联系{setUserName}!";
                         return result;
                     }
+
                     enterExitCostInfoView.ViewUsers = await _sqlSugar
                         .Queryable<Grp_EnterExitCostPermission>()
                         .Where(x => x.GroupId == dto.DiId)
                         .Select(x => x.UserId)
                         .ToArrayAsync();
 
-                    enterExitCostInfoView = _mapper.Map<EnterExitCostInfoView>(enterExitCostData);
                     //enterExitCostInfoView.FirstItemRemark = enterExitCostData.Remark;
                     var dayAndCostSql = string.Format(@"Select ntf.Country,ntf.City,ssd.Name CurremcyCode,ssd.Remark CurrencyName,gdac.* From Grp_DayAndCost gdac
                                                         Left Join Grp_NationalTravelFee ntf On ntf.Id = gdac.NationalTravelFeeId