From 39c0ce7253c705c393e1b762062fecee7d374e35 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 9 Oct 2024 15:02:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(data-protection):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=95=B0=E6=8D=AE=E8=A7=84=E5=88=99?= =?UTF-8?q?=E4=B8=BB=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataProtection/DataAccessFilterOperate.cs | 30 +++++-------- .../DataProtection/AbpDataProtectionModule.cs | 7 +-- .../Subjects/DataAccessClientIdContributor.cs | 43 +++++++++++++++++++ 3 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/Subjects/DataAccessClientIdContributor.cs diff --git a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.Abstractions/LINGYUN/Abp/DataProtection/DataAccessFilterOperate.cs b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.Abstractions/LINGYUN/Abp/DataProtection/DataAccessFilterOperate.cs index 844f4e424..c3064bdf9 100644 --- a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.Abstractions/LINGYUN/Abp/DataProtection/DataAccessFilterOperate.cs +++ b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.Abstractions/LINGYUN/Abp/DataProtection/DataAccessFilterOperate.cs @@ -6,64 +6,54 @@ namespace LINGYUN.Abp.DataProtection; /// public enum DataAccessFilterOperate { - /// - /// 且 - /// - [Description("且")] - And = 1, - /// - /// 或 - /// - [Description("或")] - Or = 2, /// /// 等于 /// [Description("等于")] - Equal = 3, + Equal = 1, /// /// 不等于 /// [Description("不等于")] - NotEqual = 4, + NotEqual = 2, /// /// 小于 /// [Description("小于")] - Less = 5, + Less = 3, /// /// 小于或等于 /// [Description("小于等于")] - LessOrEqual = 6, + LessOrEqual = 4, /// /// 大于 /// [Description("大于")] - Greater = 7, + Greater = 5, /// /// 大于或等于 /// [Description("大于等于")] - GreaterOrEqual = 8, + GreaterOrEqual = 6, /// /// 左包含 /// [Description("左包含")] - StartsWith = 9, + StartsWith = 7, /// /// 右包含 /// [Description("右包含")] - EndsWith = 10, + EndsWith = 8, /// /// 包含 /// [Description("包含")] - Contains = 11, + Contains = 9, /// /// 不包含 /// [Description("不包含")] - NotContains = 12, + NotContains = 10, } \ No newline at end of file diff --git a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataProtectionModule.cs b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataProtectionModule.cs index a1b59af62..982b7757a 100644 --- a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataProtectionModule.cs +++ b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataProtectionModule.cs @@ -4,7 +4,7 @@ using LINGYUN.Abp.DataProtection.Operations; using LINGYUN.Abp.DataProtection.Subjects; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Domain; -using Volo.Abp.Localization; +using Volo.Abp.Localization.ExceptionHandling; using Volo.Abp.Modularity; namespace LINGYUN.Abp.DataProtection; @@ -37,13 +37,14 @@ public class AbpDataProtectionModule : AbpModule options.OperateContributors.Add(DataAccessFilterOperate.NotContains, new DataAccessNotContainsContributor()); options.SubjectContributors.Add(new DataAccessUserIdContributor()); + options.SubjectContributors.Add(new DataAccessClientIdContributor()); options.SubjectContributors.Add(new DataAccessRoleNameContributor()); options.SubjectContributors.Add(new DataAccessOrganizationUnitContributor()); }); - Configure(options => + Configure(options => { - options.Resources.Add(); + options.MapCodeNamespace("DataProtection", typeof(DataProtectionResource)); }); } } diff --git a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/Subjects/DataAccessClientIdContributor.cs b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/Subjects/DataAccessClientIdContributor.cs new file mode 100644 index 000000000..2c566076d --- /dev/null +++ b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/Subjects/DataAccessClientIdContributor.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.Clients; + +namespace LINGYUN.Abp.DataProtection.Subjects; +public class DataAccessClientIdContributor : IDataAccessSubjectContributor +{ + public string Name => ClientPermissionValueProvider.ProviderName; + + public virtual List GetAllowProperties(DataAccessSubjectContributorContext context) + { + var allowProperties = new List(); + var currentClient = context.ServiceProvider.GetRequiredService(); + if (currentClient.IsAuthenticated) + { + var resourceStore = context.ServiceProvider.GetRequiredService(); + var resource = resourceStore.Get(Name, currentClient.Id, context.EntityTypeFullName, context.Operation); + if (resource?.AllowProperties.Any() == true) + { + allowProperties.AddIfNotContains(resource.AllowProperties); + } + } + return allowProperties; + } + + public virtual List GetFilterGroups(DataAccessSubjectContributorContext context) + { + var groups = new List(); + var currentClient = context.ServiceProvider.GetRequiredService(); + if (currentClient.IsAuthenticated) + { + var resourceStore = context.ServiceProvider.GetRequiredService(); + var resource = resourceStore.Get(Name, currentClient.Id, context.EntityTypeFullName, context.Operation); + if (resource?.FilterGroup != null) + { + groups.Add(resource.FilterGroup); + } + } + return groups; + } +}