From 148c295e70c272e39938199722012b26a49fd835 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 9 Oct 2024 14:59:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(data-protected):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9C=AA=E6=8E=88=E6=9D=83=E6=95=B0=E6=8D=AE=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbpDataProtectedWriteEntityInterceptor.cs | 5 ++--- .../DataProtection/AbpDataAccessDeniedException.cs | 14 ++++++++++++++ .../IDataAuthorizationServiceExtensions.cs | 3 +-- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataAccessDeniedException.cs diff --git a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.EntityFrameworkCore/LINGYUN/Abp/DataProtection/EntityFrameworkCore/AbpDataProtectedWriteEntityInterceptor.cs b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.EntityFrameworkCore/LINGYUN/Abp/DataProtection/EntityFrameworkCore/AbpDataProtectedWriteEntityInterceptor.cs index 59b497734..03e0e1f48 100644 --- a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.EntityFrameworkCore/LINGYUN/Abp/DataProtection/EntityFrameworkCore/AbpDataProtectedWriteEntityInterceptor.cs +++ b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection.EntityFrameworkCore/LINGYUN/Abp/DataProtection/EntityFrameworkCore/AbpDataProtectedWriteEntityInterceptor.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Volo.Abp; -using Volo.Abp.Authorization; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities; @@ -40,7 +39,7 @@ public class AbpDataProtectedWriteEntityInterceptor : SaveChangesInterceptor, IT var entityKeys = updateEntites .Select(entity => (entity is IEntity abpEntity ? abpEntity.GetKeys() : new string[1] { entity.ToString() }).ToString()) .JoinAsString(";"); - throw new AbpAuthorizationException( + throw new AbpDataAccessDeniedException( $"Delete data permission not granted to entity {updateEntites.First().GetType()} for data {entityKeys}!"); } } @@ -56,7 +55,7 @@ public class AbpDataProtectedWriteEntityInterceptor : SaveChangesInterceptor, IT var entityKeys = deleteEntites .Select(entity => (entity is IEntity abpEntity ? abpEntity.GetKeys() : new string[1] { entity.ToString() }).ToString()) .JoinAsString(";"); - throw new AbpAuthorizationException( + throw new AbpDataAccessDeniedException( $"Delete data permission not granted to entity {deleteEntites.First().GetType()} for data {entityKeys}!"); } } diff --git a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataAccessDeniedException.cs b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataAccessDeniedException.cs new file mode 100644 index 000000000..41265fc74 --- /dev/null +++ b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/AbpDataAccessDeniedException.cs @@ -0,0 +1,14 @@ +using Volo.Abp; + +namespace LINGYUN.Abp.DataProtection; +public class AbpDataAccessDeniedException : BusinessException +{ + public AbpDataAccessDeniedException() + { + } + + public AbpDataAccessDeniedException(string message) + : base("DataProtection:010001", message) + { + } +} diff --git a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/IDataAuthorizationServiceExtensions.cs b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/IDataAuthorizationServiceExtensions.cs index 6c415fec7..365969624 100644 --- a/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/IDataAuthorizationServiceExtensions.cs +++ b/aspnet-core/framework/data-protection/LINGYUN.Abp.DataProtection/LINGYUN/Abp/DataProtection/IDataAuthorizationServiceExtensions.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Volo.Abp.Authorization; using Volo.Abp.Domain.Entities; namespace LINGYUN.Abp.DataProtection; @@ -13,7 +12,7 @@ public static class IDataAuthorizationServiceExtensions if (!result.Succeeded) { var entityKeys = entities.Select(x => x.ToString()).JoinAsString(";"); - throw new AbpAuthorizationException( + throw new AbpDataAccessDeniedException( $"The {operation} operation with entity type {typeof(Entity)} identified as {entityKeys} is not allowed!"); } }