From 3e70e209d6f8fdc45d36b14547fff81b33d172c6 Mon Sep 17 00:00:00 2001 From: yhw0507 Date: Tue, 5 Dec 2023 15:50:31 +0800 Subject: [PATCH] =?UTF-8?q?20231205=E7=89=B9=E6=AE=8A=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=B8=8D=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SGGL/WebAPI/Filter/TestPermissionAttribute.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs index a25b586d..e674fd0f 100644 --- a/SGGL/WebAPI/Filter/TestPermissionAttribute.cs +++ b/SGGL/WebAPI/Filter/TestPermissionAttribute.cs @@ -25,7 +25,7 @@ namespace WebAPI.Filter { isOk = true; } - + bool isWithOut = false; if (!isOk && token != null) { using (Model.SGGLDB db = new Model.SGGLDB(BLL.Funs.ConnString)) @@ -34,29 +34,34 @@ namespace WebAPI.Filter if (getUser != null) { isOk = true; + isWithOut = true; } } } // base.OnActionExecuting(actionContext); if (isOk) - { // 在调用 Action 方法之前执行的代码,可获取请求的接口名称和参数 - IDictionary arguments = actionContext.ActionArguments; // 获取参数 - foreach (KeyValuePair item in arguments) + { + if (!isWithOut) { - if (item.Key == "projectid" || item.Key == "ProjectId" || item.Key == "projectId" || item.Key == "Projectid") + // 在调用 Action 方法之前执行的代码,可获取请求的接口名称和参数 + IDictionary arguments = actionContext.ActionArguments; // 获取参数 + foreach (KeyValuePair item in arguments) { - var ProjectItems = APIProjectService.geProjectsByUserId(token.FirstOrDefault()); - List projects = new List(); - if (ProjectItems.Count > 0) - { - projects = ProjectItems.Select(x => x.ProjectId).ToList(); - } - if (item.Value != null && !projects.Contains(item.Value.ToString())) + if (item.Key == "projectid" || item.Key == "ProjectId" || item.Key == "projectId" || item.Key == "Projectid") { + var ProjectItems = APIProjectService.geProjectsByUserId(token.FirstOrDefault()); + List projects = new List(); + if (ProjectItems.Count > 0) + { + projects = ProjectItems.Select(x => x.ProjectId).ToList(); + } + if (item.Value != null && !projects.Contains(item.Value.ToString())) + { - actionContext.Response = actionContext.Request.CreateResponse(System.Net.HttpStatusCode.OK, - new { code = "0", message = "您没有该项目权限!" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter); - return; + actionContext.Response = actionContext.Request.CreateResponse(System.Net.HttpStatusCode.OK, + new { code = "0", message = "您没有该项目权限!" }, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter); + return; + } } } } @@ -72,7 +77,7 @@ namespace WebAPI.Filter /// /// /// - public static List lists = new List { "User*postLoginOn" }; + public static List lists = new List { "User*postLoginOn", "HazardRegister*getHazardRegisterCount", "HazardRegister*getHazardRegisterByProjectIdStates" }; /// ///