Skip to content

Commit

Permalink
feat(data-protected): added the default filtering configuration for e…
Browse files Browse the repository at this point in the history
…ntities
  • Loading branch information
colinin committed Nov 22, 2024
1 parent b3c7c3e commit 8416366
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Volo.Abp.Auditing;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities;
Expand All @@ -16,15 +17,19 @@ public class AbpDataProtectionOptions
/// <summary>
/// 权限主体
/// </summary>
public IList<IDataAccessSubjectContributor> SubjectContributors { get; set; }
public IList<IDataAccessSubjectContributor> SubjectContributors { get; }
/// <summary>
/// 过滤字段关键字
/// </summary>
public IDictionary<string, IDataAccessKeywordContributor> KeywordContributors { get; set; }
public IDictionary<string, IDataAccessKeywordContributor> KeywordContributors { get; }
/// <summary>
/// 数据操作
/// </summary>
public IDictionary<DataAccessFilterOperate, IDataAccessOperateContributor> OperateContributors { get; set; }
public IDictionary<DataAccessFilterOperate, IDataAccessOperateContributor> OperateContributors { get; }
/// <summary>
/// 默认实体过滤
/// </summary>
public IDictionary<Type, Func<IServiceProvider, Type, DataAccessOperation, LambdaExpression>> DefaultEntityFilters { get; }
/// <summary>
/// 忽略审计字段列表
/// </summary>
Expand All @@ -35,6 +40,7 @@ public AbpDataProtectionOptions()
SubjectContributors = new List<IDataAccessSubjectContributor>();
KeywordContributors = new Dictionary<string, IDataAccessKeywordContributor>();
OperateContributors = new Dictionary<DataAccessFilterOperate, IDataAccessOperateContributor>();
DefaultEntityFilters = new Dictionary<Type, Func<IServiceProvider, Type, DataAccessOperation, LambdaExpression>>();

IgnoreAuditedProperties = new List<string>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public virtual LambdaExpression Build(Type entityType, DataAccessOperation opera
}

LambdaExpression subExp = null;

if (subjectFilterGroups.Count == 0 &&
_options.DefaultEntityFilters.TryGetValue(entityType, out var filterFunc))
{
subExp = filterFunc(_serviceProvider, entityType, operation);
}

foreach (var subGroup in subjectFilterGroups)
{
subExp = subExp == null ? GetExpression(entityType, subGroup) : subExp.OrElse(func, GetExpression(entityType, subGroup));
Expand Down

0 comments on commit 8416366

Please sign in to comment.