获取当前用户的可视权限范围 修改

dev
cjy 2 months ago
parent 229d5b9e69
commit 7ecddd6698

@ -1447,7 +1447,7 @@ public class CommonService : ICommonService
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId)); var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
if (userInfo.UserType == 0) if (userInfo.UserType == 0)
{ {
return db.Queryable<T>(); //超级管理员特权 return tenantDb.Queryable<T>(); //超级管理员特权
} }
var moduleName = typeof(T).Name.ToLower(); var moduleName = typeof(T).Name.ToLower();
@ -1461,18 +1461,18 @@ public class CommonService : ICommonService
if ((long)rule.VisibleTemplateId == 0) if ((long)rule.VisibleTemplateId == 0)
{ {
return db.Queryable<T>(); return tenantDb.Queryable<T>();
} }
var ruleInfo = tenantDb.Queryable<CodeDataRuleTemplate>().First(x => x.Id == (long)rule.VisibleTemplateId); var ruleInfo = tenantDb.Queryable<CodeDataRuleTemplate>().First(x => x.Id == (long)rule.VisibleTemplateId);
if (ruleInfo.DataRules.IsNull()) if (ruleInfo.DataRules.IsNull())
{ {
return db.Queryable<T>(); return tenantDb.Queryable<T>();
} }
if (ruleInfo.RuleScope == "all") if (ruleInfo.RuleScope == "all")
{ {
return db.Queryable<T>().ClearFilter<IOrgId>(); return tenantDb.Queryable<T>().ClearFilter<IOrgId>();
} }
if (ruleInfo.RuleScope == "none") if (ruleInfo.RuleScope == "none")
{ {
@ -1488,18 +1488,30 @@ public class CommonService : ICommonService
} }
if (ruleInfo.RuleScope == "self_dept") if (ruleInfo.RuleScope == "self_dept")
{ {
if (String.IsNullOrEmpty(userInfo.DeptName))
{
SqlSugar.Check.ExceptionEasy("NO Operation", "当前员工没有默认归属部门!");
}
var deptUsers = db.Queryable<SysUser>().Where(x => x.DeptId == userInfo.DeptId).Select(x => x.Id).ToList(); var deptUsers = db.Queryable<SysUser>().Where(x => x.DeptId == userInfo.DeptId).Select(x => x.Id).ToList();
ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginDept, string.Join(",", deptUsers)); ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginDept, string.Join(",", deptUsers));
} }
if (ruleInfo.RuleScope == "select_org") if (ruleInfo.RuleScope == "select_org")
{ {
var orgUsers = db.Queryable<SysUser>().Where(x => x.DefaultOrgId == userInfo.DefaultOrgId).Select(x => x.Id).ToList(); //var orgUsers = db.Queryable<SysUser>().Where(x => x.DefaultOrgId == userInfo.DefaultOrgId).Select(x => x.Id).ToList();
ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginDept, string.Join(",", orgUsers)); //ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginDept, string.Join(",", orgUsers));
var conditions1 = ruleInfo.DataRules.ConvertSqlSugarExpression(); var conditions1 = ruleInfo.DataRules.ConvertSqlSugarExpression();
var conditionalModels1 = var conditionalModels1 =
db.ConfigQuery.Context.Utilities.JsonToConditionalModels( db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
JsonConvert.SerializeObject(conditions1)); JsonConvert.SerializeObject(conditions1));
return db.Queryable<T>().ClearFilter<IOrgId>().Where(conditionalModels1); return tenantDb.Queryable<T>().ClearFilter<IOrgId>().Where(conditionalModels1);
}
if (ruleInfo.RuleScope == "select_user")
{
var conditions2 = ruleInfo.DataRules.ConvertSqlSugarExpression();
var conditionalModels2 =
db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
JsonConvert.SerializeObject(conditions2));
return tenantDb.Queryable<T>().ClearFilter<IOrgId>().Where(conditionalModels2);
} }
#endregion #endregion
@ -1509,7 +1521,7 @@ public class CommonService : ICommonService
var conditionalModels = var conditionalModels =
db.ConfigQuery.Context.Utilities.JsonToConditionalModels( db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
JsonConvert.SerializeObject(conditions)); JsonConvert.SerializeObject(conditions));
return db.Queryable<T>().Where(conditionalModels); return tenantDb.Queryable<T>().Where(conditionalModels);
} }
#region 获取数据库表及字段属性 #region 获取数据库表及字段属性

Loading…
Cancel
Save