mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 01:58:01 +08:00
🔄refactor: 删除MVC相关的代码
This commit is contained in:
@@ -74,17 +74,6 @@ namespace OpenAuth.App
|
||||
return _strategy.GetTableColumns(moduleCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色可访问的字段信息,因为MVC版本没有代码生成器,所以只能通过直接读取数据库表结构的方式
|
||||
/// </summary>
|
||||
/// <param name="moduleCode"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("获取角色可访问的字段信息,因为MVC版本没有代码生成器,所以只能通过直接读取数据库表结构的方式")]
|
||||
public List<BuilderTableColumn> GetTableColumnsFromDb(string moduleCode)
|
||||
{
|
||||
return _strategy.GetTableColumnsFromDb(moduleCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -148,24 +148,6 @@ namespace OpenAuth.App
|
||||
return allprops.Where(u => props.Contains(u.ColumnName)).ToList();
|
||||
}
|
||||
|
||||
public List<BuilderTableColumn> GetTableColumnsFromDb(string moduleCode)
|
||||
{
|
||||
var allprops = _dbExtension.GetTableColumnsFromDb(moduleCode);
|
||||
|
||||
//如果是系统模块,直接返回所有字段。防止开发者把模块配置成系统模块,还在外层调用loginContext.GetProperties("xxxx");
|
||||
bool? isSysModule = SugarClient.Queryable<Module>().First(u => u.Code == moduleCode)?.IsSys;
|
||||
if (isSysModule!= null && isSysModule.Value)
|
||||
{
|
||||
return allprops.ToList();
|
||||
}
|
||||
|
||||
var props =SugarClient.Queryable<Relevance>().Where(u =>
|
||||
u.RelKey == Define.ROLEDATAPROPERTY && _userRoleIds.Contains(u.FirstId) && u.SecondId == moduleCode)
|
||||
.Select(u => u.ThirdId).ToList();
|
||||
|
||||
return allprops.Where(u => props.Contains(u.ColumnName)).ToList();
|
||||
}
|
||||
|
||||
//用户角色
|
||||
|
||||
public NormalAuthStrategy(ISqlSugarClient client,DbExtension dbExtension) : base(client, null)
|
||||
|
@@ -85,11 +85,6 @@ namespace OpenAuth.App
|
||||
return SugarClient.Queryable<BuilderTableColumn>().Where(u => u.TableName.ToLower() == moduleCode.ToLower()).ToList();
|
||||
}
|
||||
|
||||
public List<BuilderTableColumn> GetTableColumnsFromDb(string moduleCode)
|
||||
{
|
||||
return _dbExtension.GetTableColumnsFromDb(moduleCode);
|
||||
}
|
||||
|
||||
|
||||
public SystemAuthStrategy(ISqlSugarClient client,DbExtension dbExtension) : base(client, null)
|
||||
{
|
||||
|
@@ -31,53 +31,6 @@ namespace OpenAuth.App
|
||||
SugarClient = sugarClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过实体获取字段定义,因为MVC版本没有代码生成界面,只能通过这种方式
|
||||
/// </summary>
|
||||
/// <param name="moduleName">模块名称/表名</param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("因为MVC版本没有代码生成界面,只能通过这种方式")]
|
||||
public List<BuilderTableColumn> GetTableColumnsFromDb(string moduleName)
|
||||
{
|
||||
var result = new List<BuilderTableColumn>();
|
||||
|
||||
//获取所有继承了StringEntity的类型
|
||||
//单元测试时,这个一直报错????奇怪
|
||||
var entiTypes = typeof(StringEntity).Assembly.GetTypes().Where(u => typeof(StringEntity).IsAssignableFrom(u) && !u.IsAbstract).ToList();
|
||||
|
||||
var entityType = entiTypes.FirstOrDefault(u => u.Name.ToLower() == moduleName.ToLower());
|
||||
if (entityType == null)
|
||||
{
|
||||
throw new Exception($"未能找到{moduleName}对应的实体类");
|
||||
}
|
||||
|
||||
foreach (var property in entityType.GetProperties())
|
||||
{
|
||||
object[] objs = property.GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
object[] browsableObjs = property.GetCustomAttributes(typeof(BrowsableAttribute), true);
|
||||
var description = objs.Length > 0 ? ((DescriptionAttribute)objs[0]).Description : property.Name;
|
||||
if (string.IsNullOrEmpty(description)) description = property.Name;
|
||||
//如果没有BrowsableAttribute或 [Browsable(true)]表示可见,其他均为不可见,需要前端配合显示
|
||||
bool browsable = browsableObjs == null || browsableObjs.Length == 0 ||
|
||||
((BrowsableAttribute)browsableObjs[0]).Browsable;
|
||||
var typeName = property.PropertyType.Name;
|
||||
if (Nullable.GetUnderlyingType(property.PropertyType) != null)
|
||||
{
|
||||
typeName = Nullable.GetUnderlyingType(property.PropertyType).Name;
|
||||
}
|
||||
result.Add(new BuilderTableColumn
|
||||
{
|
||||
ColumnName = property.Name,
|
||||
TableName = moduleName,
|
||||
Remark = description,
|
||||
IsList = browsable,
|
||||
ColumnType = typeName
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据库表结构信息
|
||||
/// </summary>
|
||||
|
@@ -46,13 +46,6 @@ namespace OpenAuth.App
|
||||
/// <param name="moduleCode"></param>
|
||||
/// <returns></returns>
|
||||
List<BuilderTableColumn> GetTableColumns(string moduleCode);
|
||||
/// <summary>
|
||||
/// 获取角色可访问的字段信息,因为MVC版本没有代码生成器,所以只能通过直接读取数据库表结构的方式
|
||||
/// </summary>
|
||||
/// <param name="moduleCode"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("获取角色可访问的字段信息,因为MVC版本没有代码生成器,所以只能通过直接读取数据库表结构的方式")]
|
||||
List<BuilderTableColumn> GetTableColumnsFromDb(string moduleCode);
|
||||
|
||||
}
|
||||
}
|
@@ -9,16 +9,6 @@ namespace OpenAuth.App.Test
|
||||
class TestDbExtension :TestBase
|
||||
{
|
||||
private ILog log = LogManager.GetLogger(typeof(TestDbExtension));
|
||||
|
||||
[Test]
|
||||
public void TestGetProperties()
|
||||
{
|
||||
|
||||
var app = _autofacServiceProvider.GetService<DbExtension>();
|
||||
|
||||
var result = app.GetTableColumnsFromDb("Category");
|
||||
Console.WriteLine(JsonHelper.Instance.Serialize(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetTables()
|
||||
|
Reference in New Issue
Block a user