public bool CheckFun(string modelName, string funName) { RunTimeModel runTime = GetRunTime(modelName, 2); return(runTime.fun.ContainsKey(funName) && ObEx.ToInt(runTime.fun[funName]) == 1); }
public RunTimeModel GetRunTime(string modelName, int getType = 1) { RunTimeModel runTimeModel = new RunTimeModel(); DbContext dbContext = dbContext_0; Dictionary <string, object> dictionary = new Dictionary <string, object>(); string currentUserID = SysContext.WanJiangUserID; List <string> list = WanJiangAuth.GetRoleUsers(currentUserID); List <string> list2 = new List <string>(); List <string> list3 = new List <string>(); List <string> list4 = new List <string>(); core_funRightsRule core_funRightsRule = null; List <RightsDataSaveModel> fnRights = new List <RightsDataSaveModel>(); foreach (string item in list) { core_right core_rights = dbContext.FirstOrDefault <core_right>("where MasterType = @0 and MasterID = @1", new object[2] { "role", item }); if (core_rights != null && !string.IsNullOrEmpty(core_rights.RightsValue)) { RightsSaveModel rightsSaveModel = JsonHelper.DeserializeJsonToObject <RightsSaveModel>(core_rights.RightsValue); if (rightsSaveModel != null) { RightsDataSaveModel rightsDataSaveModel = (from a in rightsSaveModel.funRights where string.Compare(a.modelName, modelName, true) == 0 select a).FirstOrDefault(); RightsDataSaveModel rightsDataSaveModel2 = (from a in rightsSaveModel.fieldRights where string.Compare(a.modelName, modelName, true) == 0 select a).FirstOrDefault(); if (rightsDataSaveModel != null) { fnRights.Add(rightsDataSaveModel); } if (getType != 2 && rightsDataSaveModel2 != null && !string.IsNullOrEmpty(rightsDataSaveModel2.rightsValue)) { core_fieldRightsRule core_fieldRightsRule = null; core_fieldRightsRule = dbContext.FirstOrDefault <core_fieldRightsRule>("where RuleEnabled = 1 and ID = @0", new object[1] { rightsDataSaveModel2.rightsValue }); if (core_fieldRightsRule != null && !string.IsNullOrEmpty(core_fieldRightsRule.RuleContent)) { List <FieldRuleItem> list5 = JsonHelper.DeserializeJsonToList <FieldRuleItem>(core_fieldRightsRule.RuleContent); foreach (FieldRuleItem item2 in list5) { if (item2.disable == 1) { list2.Add(item2.field); } else if (item2.enable == 1) { list3.Add(item2.field); } else { list4.Add(item2.field); } } } } } } } if (getType != 3 && core_funRightsRule == null) { core_funRightsRule = dbContext.FirstOrDefault <core_funRightsRule>("where RuleEnabled = 1 and ModelName = @0", new object[1] { modelName }); } List <SelectionItem> extendsRight = null; ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(modelName); if (core_funRightsRule != null) { string[] array = new string[7] { "enabledVisit", "enabledAdd", "enabledDel", "enabledEdit", "enabledImport", "enabledExport", "enabledPrint" }; string[] array2 = array; for (int i = 0; i < array2.Length; i++) { Func <RightsDataSaveModel, bool> func = null; string btn = array2[i]; List <RightsDataSaveModel> source = fnRights; func = ((RightsDataSaveModel a) => a.rightsValue != null && a.rightsValue.Contains(btn)); if (source.Any(func)) { dictionary[btn] = 1; } } if (serviceConfig == null) { using (List <string> .Enumerator enumerator = array.Where(r => r != "enabledVisit").ToList().GetEnumerator()) { while (enumerator.MoveNext()) { Func <RightsDataSaveModel, bool> func2 = null; string btn2 = enumerator.Current; List <RightsDataSaveModel> source2 = fnRights; func2 = ((RightsDataSaveModel a) => a.rightsValue != null && a.rightsValue.Contains(btn2)); if (source2.Any(func2)) { dictionary[btn2] = 0; } } } } if (!string.IsNullOrEmpty(core_funRightsRule.EnabledButtons)) { extendsRight = JsonHelper.DeserializeJsonToList <SelectionItem>(core_funRightsRule.EnabledButtons); if (extendsRight != null) { extendsRight = extendsRight.Where(ex => { return(fnRights.Any(fn => fn.rightsValue.Contains(ex.id))); }).ToList(); } dictionary["extends"] = extendsRight; } } else { string[] array = new string[4] { "enabledVisit", "enabledAdd", "enabledDel", "enabledEdit" }; string[] array2 = array; foreach (string text in array2) { if (serviceConfig == null && text != "enabledVisit") { dictionary[text] = 0; } else { dictionary[text] = 1; } } } if (string.Compare(modelName, "core_role") == 0 && CurrentUserIsAdmin()) { if (extendsRight != null) { if (!extendsRight.Any(r => r.id == "rights")) { extendsRight.Add(new SelectionItem { id = "rights", text = "权限管理" }); dictionary["extends"] = extendsRight; } } else { extendsRight = new List <SelectionItem>(); extendsRight.Add(new SelectionItem { id = "rights", text = "权限管理" }); dictionary["extends"] = extendsRight; } } runTimeModel.fun = dictionary; List <string> list7 = new List <string>(); foreach (string item3 in list2) { list7.Add(item3); } foreach (string item4 in list4) { if (!list3.Contains(item4)) { list7.Add(item4); } } runTimeModel.field = new Dictionary <string, object> { { "disableFields", list7 } }; return(runTimeModel); }
public List <string> GetDisabledFields(string modelId) { RunTimeModel runTime = GetRunTime(modelId, 3); return(runTime.field["disableFields"] as List <string>); }