Skip to content

Commit

Permalink
Merge pull request #8131 from abpframework/maliming/patch-1
Browse files Browse the repository at this point in the history
Enhanced global features interceptor
  • Loading branch information
realLiangshiwei committed Mar 19, 2021
2 parents 6cb7e8a + 2347b37 commit 6f8a957
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Volo.Abp.ExceptionHandling;

namespace Volo.Abp.GlobalFeatures
{
[Serializable]
public class AbpGlobalFeatureNotEnabledException : AbpException, IHasErrorCode
{
public string Code { get; }

public AbpGlobalFeatureNotEnabledException(string message = null, string code = null, Exception innerException = null)
: base(message, innerException)
{
Code = code;
}

public AbpGlobalFeatureNotEnabledException WithData(string name, object value)
{
Data[name] = value;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Volo.Abp.GlobalFeatures
{
public static class GlobalFeatureHelper
{
public static bool IsGlobalFeatureEnabled(Type controllerType, out RequiresGlobalFeatureAttribute attribute)
public static bool IsGlobalFeatureEnabled(Type type, out RequiresGlobalFeatureAttribute attribute)
{
attribute = ReflectionHelper.GetSingleAttributeOrDefault<RequiresGlobalFeatureAttribute>(controllerType);
attribute = ReflectionHelper.GetSingleAttributeOrDefault<RequiresGlobalFeatureAttribute>(type);
return attribute == null || GlobalFeatureManager.Instance.IsEnabled(attribute.GetFeatureName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override async Task InterceptAsync(IAbpMethodInvocation invocation)

if (!GlobalFeatureHelper.IsGlobalFeatureEnabled(invocation.TargetObject.GetType(), out var attribute))
{
throw new AbpGlobalFeatureNotEnableException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
throw new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
.WithData("ServiceName", invocation.TargetObject.GetType().FullName)
.WithData("GlobalFeatureName", attribute.Name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void AbpAuthorizationException_Localization()
{
using (CultureHelper.Use("zh-Hans"))
{
var exception = new AbpGlobalFeatureNotEnableException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
var exception = new AbpGlobalFeatureNotEnabledException(code: AbpGlobalFeatureErrorCodes.GlobalFeatureIsNotEnabled)
.WithData("ServiceName", "MyService")
.WithData("GlobalFeatureName", "TestFeature");;
var errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public GlobalFeatureInterceptor_Tests()
[Fact]
public async Task Interceptor_Test()
{
var ex = await Assert.ThrowsAsync<AbpGlobalFeatureNotEnableException>(async () =>
var ex = await Assert.ThrowsAsync<AbpGlobalFeatureNotEnabledException>(async () =>
{
await _testAppServiceV1.TestMethod();
});
Expand Down

0 comments on commit 6f8a957

Please sign in to comment.