Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced global features interceptor #8131

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

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