committed by
GitHub
13 changed files with 275 additions and 2 deletions
@ -0,0 +1,24 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<EmbeddedResource Include="LINGYUN\Abp\FeatureManagement\Localization\Client\*.json" /> |
||||
|
<Content Remove="LINGYUN\Abp\FeatureManagement\Localization\Client\*.json" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Volo.Abp.Authorization" Version="3.1.0" /> |
||||
|
<PackageReference Include="Volo.Abp.FeatureManagement.Domain" Version="3.1.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\LINGYUN.Abp.Features.Client\LINGYUN.Abp.Features.Client.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,25 @@ |
|||||
|
using LINGYUN.Abp.FeatureManagement.Client; |
||||
|
using LINGYUN.Abp.FeatureManagement.Client.Permissions; |
||||
|
using LINGYUN.Abp.Features.Client; |
||||
|
using Volo.Abp.FeatureManagement; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.FeatureManagement |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpFeaturesClientModule), |
||||
|
typeof(AbpFeatureManagementDomainModule) |
||||
|
)] |
||||
|
public class AbpFeatureManagementClientModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<FeatureManagementOptions>(options => |
||||
|
{ |
||||
|
options.Providers.Add<ClientFeatureManagementProvider>(); |
||||
|
|
||||
|
options.ProviderPolicies[ClientFeatureValueProvider.ProviderName] = ClientFeaturePermissionNames.Clients.ManageFeatures; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using LINGYUN.Abp.Features.Client; |
||||
|
using Volo.Abp.Clients; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.FeatureManagement; |
||||
|
|
||||
|
namespace LINGYUN.Abp.FeatureManagement.Client |
||||
|
{ |
||||
|
|
||||
|
public class ClientFeatureManagementProvider : FeatureManagementProvider, ITransientDependency |
||||
|
{ |
||||
|
public override string Name => ClientFeatureValueProvider.ProviderName; |
||||
|
|
||||
|
protected ICurrentClient CurrentClient; |
||||
|
|
||||
|
public ClientFeatureManagementProvider( |
||||
|
ICurrentClient currentClient, |
||||
|
IFeatureManagementStore store) |
||||
|
: base(store) |
||||
|
{ |
||||
|
CurrentClient = currentClient; |
||||
|
} |
||||
|
|
||||
|
protected override string NormalizeProviderKey(string providerKey) |
||||
|
{ |
||||
|
if (providerKey != null) |
||||
|
{ |
||||
|
return providerKey; |
||||
|
} |
||||
|
|
||||
|
return CurrentClient.Id; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.FeatureManagement.Localization; |
||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace LINGYUN.Abp.FeatureManagement.Client.Permissions |
||||
|
{ |
||||
|
public class ClientFeaturePermissionDefinitionProvider : PermissionDefinitionProvider |
||||
|
{ |
||||
|
public override void Define(IPermissionDefinitionContext context) |
||||
|
{ |
||||
|
var identityServerGroup = context.GetGroupOrNull(ClientFeaturePermissionNames.GroupName); |
||||
|
if (identityServerGroup == null) |
||||
|
{ |
||||
|
identityServerGroup = context |
||||
|
.AddGroup( |
||||
|
name: ClientFeaturePermissionNames.GroupName, |
||||
|
displayName: L("Permissions:IdentityServer"), |
||||
|
multiTenancySide: Volo.Abp.MultiTenancy.MultiTenancySides.Host); |
||||
|
} |
||||
|
identityServerGroup |
||||
|
.AddPermission( |
||||
|
name: ClientFeaturePermissionNames.Clients.ManageFeatures, |
||||
|
displayName: L("Permissions:ManageFeatures"), |
||||
|
multiTenancySide: Volo.Abp.MultiTenancy.MultiTenancySides.Host) |
||||
|
.WithProviders(ClientPermissionValueProvider.ProviderName); |
||||
|
} |
||||
|
|
||||
|
protected virtual LocalizableString L(string name) |
||||
|
{ |
||||
|
return LocalizableString.Create<AbpFeatureManagementResource>(name); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
namespace LINGYUN.Abp.FeatureManagement.Client.Permissions |
||||
|
{ |
||||
|
public class ClientFeaturePermissionNames |
||||
|
{ |
||||
|
public const string GroupName = "IdentityServer"; |
||||
|
|
||||
|
public static class Clients |
||||
|
{ |
||||
|
public const string Default = GroupName + ".Clients"; |
||||
|
/// <summary>
|
||||
|
/// 管理功能权限
|
||||
|
/// </summary>
|
||||
|
public const string ManageFeatures = Default + ".ManageFeatures"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
using LINGYUN.Abp.Features.Client; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.FeatureManagement; |
||||
|
|
||||
|
namespace LINGYUN.Abp.FeatureManagement |
||||
|
{ |
||||
|
public static class ClientFeatureManagerExtensions |
||||
|
{ |
||||
|
public static Task<string> GetOrNullForClientAsync(this IFeatureManager featureManager, [NotNull] string name, string clientId, bool fallback = true) |
||||
|
{ |
||||
|
return featureManager.GetOrNullAsync(name, ClientFeatureValueProvider.ProviderName, clientId, fallback); |
||||
|
} |
||||
|
|
||||
|
public static Task<List<FeatureNameValue>> GetAllForClientAsync(this IFeatureManager featureManager, string clientId, bool fallback = true) |
||||
|
{ |
||||
|
return featureManager.GetAllAsync(ClientFeatureValueProvider.ProviderName, clientId, fallback); |
||||
|
} |
||||
|
|
||||
|
public static Task<FeatureNameValueWithGrantedProvider> GetOrNullWithProviderForClientAsync(this IFeatureManager featureManager, [NotNull] string name, string clientId, bool fallback = true) |
||||
|
{ |
||||
|
return featureManager.GetOrNullWithProviderAsync(name, ClientFeatureValueProvider.ProviderName, clientId, fallback); |
||||
|
} |
||||
|
|
||||
|
public static Task<List<FeatureNameValueWithGrantedProvider>> GetAllWithProviderForClientAsync(this IFeatureManager featureManager, string clientId, bool fallback = true) |
||||
|
{ |
||||
|
return featureManager.GetAllWithProviderAsync(ClientFeatureValueProvider.ProviderName, clientId, fallback); |
||||
|
} |
||||
|
|
||||
|
public static Task SetForEditionAsync(this IFeatureManager featureManager, string clientId, [NotNull] string name, [CanBeNull] string value, bool forceToSet = false) |
||||
|
{ |
||||
|
return featureManager.SetAsync(name, value, ClientFeatureValueProvider.ProviderName, clientId, forceToSet); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"Permissions:IdentityServer": "IdentityServer", |
||||
|
"Permissions:ManageFeatures": "Manage features" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"culture": "zh-Hans", |
||||
|
"texts": { |
||||
|
"Permissions:IdentityServer": "IdentityServer管理", |
||||
|
"ManageFeatures": "管理功能" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netstandard2.0</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Volo.Abp.Features" Version="3.1.0" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,18 @@ |
|||||
|
using Volo.Abp.Features; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Features.Client |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpFeaturesModule))] |
||||
|
public class AbpFeaturesClientModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpFeatureOptions>(options => |
||||
|
{ |
||||
|
options.ValueProviders.Add<ClientFeatureValueProvider>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Clients; |
||||
|
using Volo.Abp.Features; |
||||
|
|
||||
|
namespace LINGYUN.Abp.Features.Client |
||||
|
{ |
||||
|
public class ClientFeatureValueProvider : FeatureValueProvider |
||||
|
{ |
||||
|
public const string ProviderName = "C"; |
||||
|
|
||||
|
public override string Name => ProviderName; |
||||
|
|
||||
|
protected ICurrentClient CurrentClient; |
||||
|
|
||||
|
public ClientFeatureValueProvider( |
||||
|
IFeatureStore featureStore, |
||||
|
ICurrentClient currentClient) |
||||
|
: base(featureStore) |
||||
|
{ |
||||
|
CurrentClient = currentClient; |
||||
|
} |
||||
|
|
||||
|
public override async Task<string> GetOrNullAsync(FeatureDefinition feature) |
||||
|
{ |
||||
|
if (!CurrentClient.IsAuthenticated) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return await FeatureStore.GetOrNullAsync(feature.Name, Name, CurrentClient.Id); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue