|
@@ -1,5 +1,6 @@
|
|
|
using Hotline.Settings;
|
|
|
using Hotline.Share.Enums;
|
|
|
+using Microsoft.Extensions.DependencyInjection;
|
|
|
using Org.BouncyCastle.Asn1.X509;
|
|
|
using XF.Domain.Authentications;
|
|
|
using XF.Domain.Dependency;
|
|
@@ -9,13 +10,11 @@ namespace Hotline.Repository.SqlSugar.DataPermissions;
|
|
|
|
|
|
public class DataPermissionManager : IDataPermissionManager, IScopeDependency
|
|
|
{
|
|
|
- private readonly ISystemDataTableRepository _systemDataTableRepository;
|
|
|
- private readonly ISystemDataAuthorityRepository _systemDataAuthorityRepository;
|
|
|
+ private readonly IServiceScopeFactory _serviceScopeFactory;
|
|
|
|
|
|
- public DataPermissionManager(ISystemDataTableRepository systemDataTableRepository,ISystemDataAuthorityRepository systemDataAuthorityRepository)
|
|
|
+ public DataPermissionManager(IServiceScopeFactory serviceScopeFactory)
|
|
|
{
|
|
|
- _systemDataTableRepository = systemDataTableRepository;
|
|
|
- _systemDataAuthorityRepository = systemDataAuthorityRepository;
|
|
|
+ _serviceScopeFactory = serviceScopeFactory;
|
|
|
}
|
|
|
|
|
|
public DataPermissionScheme GetQueryFilter<TEntity>(ISessionContext sessionContext) where TEntity : class, IEntity<string>, IDataPermission, new()
|
|
@@ -52,14 +51,18 @@ public class DataPermissionManager : IDataPermissionManager, IScopeDependency
|
|
|
|
|
|
private EAuthorityType? GetCurrentQueryFilter(string[] roles, string entityName)
|
|
|
{
|
|
|
- //查询对应表配置
|
|
|
- var tableModel = _systemDataTableRepository.GetAsync(x => x.EntityName == entityName).Result;
|
|
|
- //查询表对应数据权限
|
|
|
- var authList = _systemDataAuthorityRepository.QueryExtAsync(x => roles.Contains(x.RoleCode),null,x=>x.OrderBy(d=>d.AuthorityType)).Result;
|
|
|
- if (authList!=null && authList.Count>0)
|
|
|
- {
|
|
|
- return (EAuthorityType)authList[0].AuthorityType;
|
|
|
- }
|
|
|
+ using var scope = _serviceScopeFactory.CreateScope();
|
|
|
+ var systemDataTableRepository = scope.ServiceProvider.GetService<ISystemDataTableRepository>();
|
|
|
+ var systemDataAuthorityRepository = scope.ServiceProvider.GetService<ISystemDataTableRepository>();
|
|
|
+
|
|
|
+ ////查询对应表配置
|
|
|
+ //var tableModel = _systemDataTableRepository.GetAsync(x => x.EntityName == entityName).Result;
|
|
|
+ ////查询表对应数据权限
|
|
|
+ //var authList = _systemDataAuthorityRepository.QueryExtAsync(x => roles.Contains(x.RoleCode),null,x=>x.OrderBy(d=>d.AuthorityType)).Result;
|
|
|
+ //if (authList!=null && authList.Count>0)
|
|
|
+ //{
|
|
|
+ // return (EAuthorityType)authList[0].AuthorityType;
|
|
|
+ //}
|
|
|
return null;
|
|
|
}
|
|
|
}
|