From 70bfb0fafbabc4c5d27514a055b697efa66933ea Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Tue, 1 Sep 2020 23:02:35 +0800 Subject: [PATCH 1/7] Add IsAvailableToHost & HostFeatureValueProvider & HostFeatureManagementProvider. --- .../Volo/Abp/Features/AbpFeaturesModule.cs | 1 + .../Volo/Abp/Features/FeatureDefinition.cs | 30 ++++++---- .../Abp/Features/HostFeatureValueProvider.cs | 30 ++++++++++ .../AbpFeatureManagementDomainModule.cs | 3 +- .../HostFeatureManagementProvider.cs | 59 +++++++++++++++++++ 5 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs create mode 100644 modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs index f30017feed..7db32231e0 100644 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs @@ -26,6 +26,7 @@ namespace Volo.Abp.Features context.Services.Configure(options => { options.ValueProviders.Add(); + options.ValueProviders.Add(); options.ValueProviders.Add(); options.ValueProviders.Add(); }); diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinition.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinition.cs index bd79480326..b2b11f0a18 100644 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinition.cs +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinition.cs @@ -51,6 +51,12 @@ namespace Volo.Abp.Features /// public bool IsVisibleToClients { get; set; } + /// + /// Can host use this feature. + /// Default: true. + /// + public bool IsAvailableToHost { get; set; } + /// /// A list of allowed providers to get/set value of this feature. /// An empty list indicates that all providers are allowed. @@ -93,7 +99,8 @@ namespace Volo.Abp.Features ILocalizableString displayName = null, ILocalizableString description = null, IStringValueType valueType = null, - bool isVisibleToClients = true) + bool isVisibleToClients = true, + bool isAvailableToHost = true) { Name = name; DefaultValue = defaultValue; @@ -101,6 +108,7 @@ namespace Volo.Abp.Features Description = description; ValueType = valueType; IsVisibleToClients = isVisibleToClients; + IsAvailableToHost = isAvailableToHost; Properties = new Dictionary(); AllowedProviders = new List(); @@ -136,20 +144,22 @@ namespace Volo.Abp.Features /// /// Returns a newly created child feature public FeatureDefinition CreateChild( - string name, - string defaultValue = null, - ILocalizableString displayName = null, + string name, + string defaultValue = null, + ILocalizableString displayName = null, ILocalizableString description = null, IStringValueType valueType = null, - bool isVisibleToClients = true) + bool isVisibleToClients = true, + bool isAvailableToHost = true) { var feature = new FeatureDefinition( - name, - defaultValue, - displayName, + name, + defaultValue, + displayName, description, valueType, - isVisibleToClients) + isVisibleToClients, + isAvailableToHost) { Parent = this }; @@ -175,4 +185,4 @@ namespace Volo.Abp.Features return $"[{nameof(FeatureDefinition)}: {Name}]"; } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs new file mode 100644 index 0000000000..d895813e6f --- /dev/null +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs @@ -0,0 +1,30 @@ +using System.Threading.Tasks; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.Features +{ + public class HostFeatureValueProvider : FeatureValueProvider + { + public const string ProviderName = "H"; + + public override string Name => ProviderName; + + protected ICurrentTenant CurrentTenant { get; } + + public HostFeatureValueProvider(IFeatureStore featureStore, ICurrentTenant currentTenant) + : base(featureStore) + { + CurrentTenant = currentTenant; + } + + public override async Task GetOrNullAsync(FeatureDefinition feature) + { + if (CurrentTenant.Id.HasValue || !feature.IsAvailableToHost) + { + return null; + } + + return await FeatureStore.GetOrNullAsync(feature.Name, Name, null); + } + } +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs index e8e961d3b4..17e0b9fc04 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs @@ -1,10 +1,8 @@ using Volo.Abp.Caching; using Volo.Abp.FeatureManagement.Localization; using Volo.Abp.Features; -using Volo.Abp.Localization; using Volo.Abp.Localization.ExceptionHandling; using Volo.Abp.Modularity; -using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.FeatureManagement { @@ -20,6 +18,7 @@ namespace Volo.Abp.FeatureManagement Configure(options => { options.Providers.Add(); + options.Providers.Add(); options.Providers.Add(); //TODO: Should be moved to the Tenant Management module diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs new file mode 100644 index 0000000000..d40d2dfdec --- /dev/null +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs @@ -0,0 +1,59 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Features; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.FeatureManagement +{ + public class HostFeatureManagementProvider : FeatureManagementProvider, ITransientDependency + { + public override string Name => HostFeatureValueProvider.ProviderName; + + protected ICurrentTenant CurrentTenant { get; } + + public HostFeatureManagementProvider( + IFeatureManagementStore store, + ICurrentTenant currentTenant) + : base(store) + { + CurrentTenant = currentTenant; + } + + public override async Task GetOrNullAsync(FeatureDefinition feature, string providerKey) + { + if (IsHostSide(feature)) + { + return await Store.GetOrNullAsync(feature.Name, Name, NormalizeProviderKey(providerKey)); + } + + return null; + } + + public override async Task SetAsync(FeatureDefinition feature, string value, string providerKey) + { + if (IsHostSide(feature)) + { + await Store.SetAsync(feature.Name, value, Name, NormalizeProviderKey(providerKey)); + } + } + + public override async Task ClearAsync(FeatureDefinition feature, string providerKey) + { + if (IsHostSide(feature)) + { + await Store.DeleteAsync(feature.Name, Name, NormalizeProviderKey(providerKey)); + } + } + + protected override string NormalizeProviderKey(string providerKey) + { + return null; + } + + //TODO: Should throw an ex when there is not in the host side? + protected virtual bool IsHostSide(FeatureDefinition feature) + { + return feature.IsAvailableToHost && CurrentTenant.Id == null; + } + } +} From 7b09b7e5926db9f80b3f7d14c8b9ac08ad1caf88 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Wed, 2 Sep 2020 15:31:42 +0800 Subject: [PATCH 2/7] Manage Host features. --- .../FeatureManagementPermissions.cs | 16 +++++++ .../FeaturePermissionDefinitionProvider.cs | 28 +++++++++++ .../FeatureManagement/IFeatureAppService.cs | 8 +++- .../FeatureManagement/FeatureAppService.cs | 46 +++++++++++++++++++ .../Localization/Domain/en.json | 7 ++- .../Localization/Domain/tr.json | 7 ++- .../Localization/Domain/zh-Hans.json | 7 ++- .../Localization/Domain/zh-Hant.json | 7 ++- .../FeatureManagement/FeaturesController.cs | 16 ++++++- .../FeatureManagementModal.cshtml.cs | 18 +++++++- .../Localization/Resources/en.json | 7 +-- .../Localization/Resources/tr.json | 3 +- .../Localization/Resources/zh-Hans.json | 3 +- .../Localization/Resources/zh-Hant.json | 3 +- .../TenantManagement/Tenants/Index.cshtml | 9 +++- .../Pages/TenantManagement/Tenants/Index.js | 10 +++- 16 files changed, 173 insertions(+), 22 deletions(-) create mode 100644 modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureManagementPermissions.cs create mode 100644 modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeaturePermissionDefinitionProvider.cs diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureManagementPermissions.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureManagementPermissions.cs new file mode 100644 index 0000000000..86772c0a7b --- /dev/null +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureManagementPermissions.cs @@ -0,0 +1,16 @@ +using Volo.Abp.Reflection; + +namespace Volo.Abp.FeatureManagement +{ + public class FeatureManagementPermissions + { + public const string GroupName = "FeatureManagement"; + + public const string ManageHostFeatures = GroupName + ".ManageHostFeatures"; + + public static string[] GetAll() + { + return ReflectionHelper.GetPublicConstantsRecursively(typeof(FeatureManagementPermissions)); + } + } +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeaturePermissionDefinitionProvider.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeaturePermissionDefinitionProvider.cs new file mode 100644 index 0000000000..27e159ee8a --- /dev/null +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeaturePermissionDefinitionProvider.cs @@ -0,0 +1,28 @@ +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.FeatureManagement.Localization; +using Volo.Abp.Localization; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.FeatureManagement +{ + public class FeaturePermissionDefinitionProvider : PermissionDefinitionProvider + { + public override void Define(IPermissionDefinitionContext context) + { + var featureManagementGroup = context.AddGroup( + FeatureManagementPermissions.GroupName, + L("Permission:FeatureManagement"), + multiTenancySide: MultiTenancySides.Host); + + featureManagementGroup.AddPermission( + FeatureManagementPermissions.ManageHostFeatures, + L("Permission:FeatureManagement.ManageHostFeatures"), + multiTenancySide: MultiTenancySides.Host); + } + + private static LocalizableString L(string name) + { + return LocalizableString.Create(name); + } + } +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs index 2c337f1b2a..a2a87b195b 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs @@ -6,8 +6,12 @@ namespace Volo.Abp.FeatureManagement { public interface IFeatureAppService : IApplicationService { - Task GetAsync([NotNull] string providerName, [NotNull] string providerKey); + Task GetAsync([NotNull] string providerName, [NotNull] string providerKey); - Task UpdateAsync([NotNull] string providerName, [NotNull] string providerKey, UpdateFeaturesDto input); + Task UpdateAsync([NotNull] string providerName, [NotNull] string providerKey, UpdateFeaturesDto input); + + Task GetHostAsync(); + + Task UpdateHostAsync(UpdateFeaturesDto input); } } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs index f0c310650d..6969739baa 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.AspNetCore.Authorization; @@ -65,6 +66,51 @@ namespace Volo.Abp.FeatureManagement } } + [Authorize(FeatureManagementPermissions.ManageHostFeatures)] + public async Task GetHostAsync() + { + var featureDefinitions = FeatureDefinitionManager.GetAll().Where(x => x.IsAvailableToHost); + var features = new List(); + + foreach (var featureDefinition in featureDefinitions) + { + var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, HostFeatureValueProvider.ProviderName, null); + features.Add(new FeatureDto + { + Name = featureDefinition.Name, + DisplayName = featureDefinition.DisplayName?.Localize(StringLocalizerFactory), + ValueType = featureDefinition.ValueType, + Description = featureDefinition.Description?.Localize(StringLocalizerFactory), + ParentName = featureDefinition.Parent?.Name, + Value = feature.Value, + Provider = new FeatureProviderDto + { + Name = feature.Provider?.Name, + Key = feature.Provider?.Key + } + }); + } + + SetFeatureDepth(features, HostFeatureValueProvider.ProviderName, null); + + return new FeatureListDto { Features = features }; + } + + [Authorize(FeatureManagementPermissions.ManageHostFeatures)] + public async Task UpdateHostAsync(UpdateFeaturesDto input) + { + foreach (var feature in input.Features) + { + var featureDefinition = FeatureDefinitionManager.GetOrNull(feature.Name); + if (featureDefinition == null || !featureDefinition.IsAvailableToHost) + { + throw new UserFriendlyException(L["FeatureNotAvailable"]); + } + + await FeatureManager.SetAsync(feature.Name, feature.Value, HostFeatureValueProvider.ProviderName, null); + } + } + protected virtual void SetFeatureDepth(List features, string providerName, string providerKey, FeatureDto parentFeature = null, int depth = 0) { diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json index e5a2406aaf..6e17e8fc48 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json @@ -2,6 +2,9 @@ "culture": "en", "texts": { "Features": "Features", - "NoFeatureFoundMessage": "There isn't any available feature." + "NoFeatureFoundMessage": "There isn't any available feature.", + "FeatureNotAvailable": "Feature not available.", + "Permission:FeatureManagement": "Feature management", + "Permission:FeatureManagement.ManageHostFeatures": "Manage Host features" } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json index b566f654ca..de5ad20624 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json @@ -2,6 +2,9 @@ "culture": "tr", "texts": { "Features": "Özellikler", - "NoFeatureFoundMessage": "Hiç özellik yok." + "NoFeatureFoundMessage": "Hiç özellik yok.", + "FeatureNotAvailable": "özelliği mevcut değil.", + "Permission:FeatureManagement": "Özellik yönetimi", + "Permission:FeatureManagement.ManageHostFeatures": "Yönetilen Ana Bilgisayar özellikleri" } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json index 69b8ca89b1..2ecdb3997b 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json @@ -2,6 +2,9 @@ "culture": "zh-Hans", "texts": { "Features": "功能", - "NoFeatureFoundMessage": "没有可用的功能." + "NoFeatureFoundMessage": "没有可用的功能.", + "FeatureNotAvailable": "功能不可用.", + "Permission:FeatureManagement": "特性管理", + "Permission:FeatureManagement.ManageHostFeatures": "管理Host特性" } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json index bc4dbf268f..6a8ccd099b 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json @@ -2,6 +2,9 @@ "culture": "zh-Hant", "texts": { "Features": "功能", - "NoFeatureFoundMessage": "沒有可用的功能." + "NoFeatureFoundMessage": "沒有可用的功能.", + "FeatureNotAvailable": "功能不可用.", + "Permission:FeatureManagement": "功能管理", + "Permission:FeatureManagement.ManageHostFeatures": "管理Host功能" } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs index 0ae78ed03f..a5c9c1c819 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs @@ -27,5 +27,19 @@ namespace Volo.Abp.FeatureManagement { return FeatureAppService.UpdateAsync(providerName, providerKey, input); } + + [HttpGet] + [Route("host")] + public virtual Task GetHostAsync() + { + return FeatureAppService.GetHostAsync(); + } + + [HttpPut] + [Route("host")] + public virtual Task UpdateHostAsync(UpdateFeaturesDto input) + { + return FeatureAppService.UpdateHostAsync(input); + } } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs index e46d686e69..0fd5d756f7 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs @@ -37,7 +37,14 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement public virtual async Task OnGetAsync() { - FeatureListDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey); + if (ProviderName == HostFeatureValueProvider.ProviderName) + { + FeatureListDto = await FeatureAppService.GetHostAsync(); + } + else + { + FeatureListDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey); + } } public virtual async Task OnPostAsync() @@ -51,7 +58,14 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement }).ToList() }; - await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); + if (ProviderName == HostFeatureValueProvider.ProviderName) + { + await FeatureAppService.UpdateHostAsync(features); + } + else + { + await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); + } return NoContent(); } diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/en.json b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/en.json index d6d1d7c155..ba4109c392 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/en.json +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/en.json @@ -10,13 +10,14 @@ "ConnectionStrings": "Connection Strings", "DisplayName:DefaultConnectionString": "Default Connection String", "DisplayName:UseSharedDatabase": "Use the Shared Database", + "ManageHostFeatures": "Manage Host features", "Permission:TenantManagement": "Tenant management", "Permission:Create": "Create", "Permission:Edit": "Edit", "Permission:Delete": "Delete", "Permission:ManageConnectionStrings": "Manage connection strings", "Permission:ManageFeatures": "Manage features", - "DisplayName:AdminEmailAddress": "Admin Email Address", - "DisplayName:AdminPassword": "Admin Password" + "DisplayName:AdminEmailAddress": "Admin Email Address", + "DisplayName:AdminPassword": "Admin Password" } -} \ No newline at end of file +} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/tr.json b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/tr.json index 72b570f3f9..7315cccc3f 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/tr.json +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/tr.json @@ -10,6 +10,7 @@ "ConnectionStrings": "Bağlantı cümlesi", "DisplayName:DefaultConnectionString": "Varsayılan bağlantı cümlesi", "DisplayName:UseSharedDatabase": "Paylaşılan veritabanını kullan", + "ManageHostFeatures": "Toplantı Sahibi özelliklerini yönetin", "Permission:TenantManagement": "Müşteri yönetimi", "Permission:Create": "Oluşturma", "Permission:Edit": "Düzenleme", @@ -19,4 +20,4 @@ "DisplayName:AdminEmailAddress": "Admin Eposta Adresi", "DisplayName:AdminPassword": "Admin Şifresi" } -} \ No newline at end of file +} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hans.json b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hans.json index b60c68e2e0..f85f6cf638 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hans.json +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hans.json @@ -10,6 +10,7 @@ "ConnectionStrings": "连接字符串", "DisplayName:DefaultConnectionString": "默认连接字符串", "DisplayName:UseSharedDatabase": "使用共享数据库", + "ManageHostFeatures": "管理Host特性", "Permission:TenantManagement": "租户管理", "Permission:Create": "创建", "Permission:Edit": "编辑", @@ -17,4 +18,4 @@ "Permission:ManageConnectionStrings": "管理连接字符串", "Permission:ManageFeatures": "管理功能" } -} \ No newline at end of file +} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hant.json b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hant.json index ea8be8ae0e..6950a1ca00 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hant.json +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/Localization/Resources/zh-Hant.json @@ -10,13 +10,14 @@ "ConnectionStrings": "資料庫連線字串", "DisplayName:DefaultConnectionString": "預設資料庫連線字串", "DisplayName:UseSharedDatabase": "使用共用資料庫", + "ManageHostFeatures": "管理Host功能", "Permission:TenantManagement": "租戶管理", "Permission:Create": "新增", "Permission:Edit": "編輯", "Permission:Delete": "刪除", "Permission:ManageConnectionStrings": "管理資料庫連線字串", "Permission:ManageFeatures": "管理功能", - "DisplayName:AdminEmailAddress": "管理者信箱", + "DisplayName:AdminEmailAddress": "管理者信箱", "DisplayName:AdminPassword": "管理者密碼" } } diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.cshtml b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.cshtml index eabc75c786..bb972b02d8 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.cshtml +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.cshtml @@ -2,6 +2,7 @@ @using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Mvc.Localization @using Volo.Abp.AspNetCore.Mvc.UI.Layout +@using Volo.Abp.FeatureManagement @using Volo.Abp.TenantManagement @using Volo.Abp.TenantManagement.Localization @using Volo.Abp.TenantManagement.Web.Navigation @@ -29,9 +30,13 @@ @L["Tenants"] + @if (await Authorization.IsGrantedAsync(FeatureManagementPermissions.ManageHostFeatures)) + { + + } @if (await Authorization.IsGrantedAsync(TenantManagementPermissions.Tenants.Create)) { - + } @@ -39,4 +44,4 @@ - \ No newline at end of file + diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js index 4b19d0bbb7..828f163908 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js @@ -100,7 +100,7 @@ }, 0 //adds as the first contributor ); - + $(function () { var _$wrapper = $('#TenantsWrapper'); @@ -128,5 +128,13 @@ e.preventDefault(); _createModal.open(); }); + + _$wrapper.find('button[name=ManageHostFeatures]').click(function (e) { + e.preventDefault(); + _featuresModal.open({ + providerName: 'H', + providerKey: 'H' + }); + }); }); })(); From 6845b0a58804ba1a61c73504985fbb01446282c6 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:18:24 +0800 Subject: [PATCH 3/7] Update modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Halil İbrahim Kalkan --- .../Volo/Abp/FeatureManagement/Localization/Domain/tr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json index de5ad20624..a7dab6dac3 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json @@ -3,7 +3,7 @@ "texts": { "Features": "Özellikler", "NoFeatureFoundMessage": "Hiç özellik yok.", - "FeatureNotAvailable": "özelliği mevcut değil.", + "FeatureNotAvailable": "Özellik bulunamadı.", "Permission:FeatureManagement": "Özellik yönetimi", "Permission:FeatureManagement.ManageHostFeatures": "Yönetilen Ana Bilgisayar özellikleri" } From e2bba2941eb8125276c5024100ec0260c3dc2a8c Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:18:41 +0800 Subject: [PATCH 4/7] Update modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Halil İbrahim Kalkan --- .../Volo/Abp/FeatureManagement/Localization/Domain/tr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json index a7dab6dac3..285b4143cf 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json @@ -5,6 +5,6 @@ "NoFeatureFoundMessage": "Hiç özellik yok.", "FeatureNotAvailable": "Özellik bulunamadı.", "Permission:FeatureManagement": "Özellik yönetimi", - "Permission:FeatureManagement.ManageHostFeatures": "Yönetilen Ana Bilgisayar özellikleri" + "Permission:FeatureManagement.ManageHostFeatures": "Host özelliklerini düzenle" } } From 40978470c6b5bc8f032d320aa59535d237c646b8 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Tue, 8 Sep 2020 11:17:34 +0800 Subject: [PATCH 5/7] Refactor --- .../FeatureManagement/IFeatureAppService.cs | 8 +-- .../FeatureManagement/FeatureAppService.cs | 52 ++++--------------- .../AbpFeatureManagementDomainModule.cs | 1 + .../FeatureManagement/FeaturesController.cs | 14 ----- .../FeatureManagementModal.cshtml.cs | 21 +------- .../Pages/TenantManagement/Tenants/Index.js | 3 +- 6 files changed, 15 insertions(+), 84 deletions(-) diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs index a2a87b195b..ce9609976e 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/IFeatureAppService.cs @@ -6,12 +6,8 @@ namespace Volo.Abp.FeatureManagement { public interface IFeatureAppService : IApplicationService { - Task GetAsync([NotNull] string providerName, [NotNull] string providerKey); + Task GetAsync([NotNull] string providerName, string providerKey); - Task UpdateAsync([NotNull] string providerName, [NotNull] string providerKey, UpdateFeaturesDto input); - - Task GetHostAsync(); - - Task UpdateHostAsync(UpdateFeaturesDto input); + Task UpdateAsync([NotNull] string providerName, string providerKey, UpdateFeaturesDto input); } } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs index 6969739baa..7bb305054e 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs @@ -25,13 +25,18 @@ namespace Volo.Abp.FeatureManagement Options = options.Value; } - public virtual async Task GetAsync([NotNull] string providerName, [NotNull] string providerKey) + public virtual async Task GetAsync([NotNull] string providerName, string providerKey) { await CheckProviderPolicy(providerName); var featureDefinitions = FeatureDefinitionManager.GetAll(); var features = new List(); + if (providerName == HostFeatureValueProvider.ProviderName) + { + featureDefinitions = featureDefinitions.Where(x => x.IsAvailableToHost).ToList(); + } + foreach (var featureDefinition in featureDefinitions) { var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, providerName, providerKey); @@ -56,58 +61,19 @@ namespace Volo.Abp.FeatureManagement return new FeatureListDto { Features = features }; } - public virtual async Task UpdateAsync([NotNull] string providerName, [NotNull] string providerKey, UpdateFeaturesDto input) + public virtual async Task UpdateAsync([NotNull] string providerName, string providerKey, UpdateFeaturesDto input) { await CheckProviderPolicy(providerName); - foreach (var feature in input.Features) - { - await FeatureManager.SetAsync(feature.Name, feature.Value, providerName, providerKey); - } - } - - [Authorize(FeatureManagementPermissions.ManageHostFeatures)] - public async Task GetHostAsync() - { - var featureDefinitions = FeatureDefinitionManager.GetAll().Where(x => x.IsAvailableToHost); - var features = new List(); - - foreach (var featureDefinition in featureDefinitions) - { - var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, HostFeatureValueProvider.ProviderName, null); - features.Add(new FeatureDto - { - Name = featureDefinition.Name, - DisplayName = featureDefinition.DisplayName?.Localize(StringLocalizerFactory), - ValueType = featureDefinition.ValueType, - Description = featureDefinition.Description?.Localize(StringLocalizerFactory), - ParentName = featureDefinition.Parent?.Name, - Value = feature.Value, - Provider = new FeatureProviderDto - { - Name = feature.Provider?.Name, - Key = feature.Provider?.Key - } - }); - } - - SetFeatureDepth(features, HostFeatureValueProvider.ProviderName, null); - - return new FeatureListDto { Features = features }; - } - - [Authorize(FeatureManagementPermissions.ManageHostFeatures)] - public async Task UpdateHostAsync(UpdateFeaturesDto input) - { foreach (var feature in input.Features) { var featureDefinition = FeatureDefinitionManager.GetOrNull(feature.Name); - if (featureDefinition == null || !featureDefinition.IsAvailableToHost) + if (featureDefinition == null || (providerName == HostFeatureValueProvider.ProviderName && !featureDefinition.IsAvailableToHost)) { throw new UserFriendlyException(L["FeatureNotAvailable"]); } - await FeatureManager.SetAsync(feature.Name, feature.Value, HostFeatureValueProvider.ProviderName, null); + await FeatureManager.SetAsync(feature.Name, feature.Value, providerName, providerKey); } } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs index 17e0b9fc04..b9992309dd 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs @@ -19,6 +19,7 @@ namespace Volo.Abp.FeatureManagement { options.Providers.Add(); options.Providers.Add(); + options.ProviderPolicies[HostFeatureValueProvider.ProviderName] = "FeatureManagement.ManageHostFeatures"; options.Providers.Add(); //TODO: Should be moved to the Tenant Management module diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs index a5c9c1c819..1c956e1fcf 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.HttpApi/Volo/Abp/FeatureManagement/FeaturesController.cs @@ -27,19 +27,5 @@ namespace Volo.Abp.FeatureManagement { return FeatureAppService.UpdateAsync(providerName, providerKey, input); } - - [HttpGet] - [Route("host")] - public virtual Task GetHostAsync() - { - return FeatureAppService.GetHostAsync(); - } - - [HttpPut] - [Route("host")] - public virtual Task UpdateHostAsync(UpdateFeaturesDto input) - { - return FeatureAppService.UpdateHostAsync(input); - } } } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs index 0fd5d756f7..ecc59d11f9 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml.cs @@ -16,7 +16,6 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement [BindProperty(SupportsGet = true)] public string ProviderName { get; set; } - [Required] [HiddenInput] [BindProperty(SupportsGet = true)] public string ProviderKey { get; set; } @@ -37,14 +36,7 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement public virtual async Task OnGetAsync() { - if (ProviderName == HostFeatureValueProvider.ProviderName) - { - FeatureListDto = await FeatureAppService.GetHostAsync(); - } - else - { - FeatureListDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey); - } + FeatureListDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey); } public virtual async Task OnPostAsync() @@ -58,14 +50,7 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement }).ToList() }; - if (ProviderName == HostFeatureValueProvider.ProviderName) - { - await FeatureAppService.UpdateHostAsync(features); - } - else - { - await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); - } + await FeatureAppService.UpdateAsync(ProviderName, ProviderKey, features); return NoContent(); } @@ -88,8 +73,6 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement public string Value { get; set; } - public string ProviderName { get; set; } - public bool BoolValue { get; set; } public string Type { get; set; } diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js index 828f163908..ecb2309f36 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js @@ -132,8 +132,7 @@ _$wrapper.find('button[name=ManageHostFeatures]').click(function (e) { e.preventDefault(); _featuresModal.open({ - providerName: 'H', - providerKey: 'H' + providerName: 'H' }); }); }); From 835e5466c0e62377d948ed9deece0be00bc46e36 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Tue, 8 Sep 2020 22:20:24 +0800 Subject: [PATCH 6/7] Refactor --- .../Volo/Abp/Features/AbpFeaturesModule.cs | 1 - .../Abp/Features/HostFeatureValueProvider.cs | 30 ---------- .../FeatureManagement/FeatureAppService.cs | 33 +++++++---- .../Localization/Domain/en.json | 1 - .../Localization/Domain/tr.json | 1 - .../Localization/Domain/zh-Hans.json | 1 - .../Localization/Domain/zh-Hant.json | 1 - .../AbpFeatureManagementDomainModule.cs | 3 - .../HostFeatureManagementProvider.cs | 59 ------------------- .../Pages/TenantManagement/Tenants/Index.js | 2 +- 10 files changed, 21 insertions(+), 111 deletions(-) delete mode 100644 framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs delete mode 100644 modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs index 7db32231e0..f30017feed 100644 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/AbpFeaturesModule.cs @@ -26,7 +26,6 @@ namespace Volo.Abp.Features context.Services.Configure(options => { options.ValueProviders.Add(); - options.ValueProviders.Add(); options.ValueProviders.Add(); options.ValueProviders.Add(); }); diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs deleted file mode 100644 index d895813e6f..0000000000 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/HostFeatureValueProvider.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.MultiTenancy; - -namespace Volo.Abp.Features -{ - public class HostFeatureValueProvider : FeatureValueProvider - { - public const string ProviderName = "H"; - - public override string Name => ProviderName; - - protected ICurrentTenant CurrentTenant { get; } - - public HostFeatureValueProvider(IFeatureStore featureStore, ICurrentTenant currentTenant) - : base(featureStore) - { - CurrentTenant = currentTenant; - } - - public override async Task GetOrNullAsync(FeatureDefinition feature) - { - if (CurrentTenant.Id.HasValue || !feature.IsAvailableToHost) - { - return null; - } - - return await FeatureStore.GetOrNullAsync(feature.Name, Name, null); - } - } -} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs index 5c19df8751..6f0fe4815e 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs @@ -28,7 +28,7 @@ namespace Volo.Abp.FeatureManagement public virtual async Task GetAsync([NotNull] string providerName, string providerKey) { - await CheckProviderPolicy(providerName); + await CheckProviderPolicy(providerName, providerKey); var result = new GetFeatureListResultDto { @@ -46,7 +46,10 @@ namespace Volo.Abp.FeatureManagement foreach (var featureDefinition in group.GetFeaturesWithChildren()) { - if (providerName == HostFeatureValueProvider.ProviderName && !featureDefinition.IsAvailableToHost) + if (providerName == TenantFeatureValueProvider.ProviderName && + CurrentTenant.Id == null && + providerKey == null && + !featureDefinition.IsAvailableToHost) { continue; } @@ -78,16 +81,10 @@ namespace Volo.Abp.FeatureManagement public virtual async Task UpdateAsync([NotNull] string providerName, string providerKey, UpdateFeaturesDto input) { - await CheckProviderPolicy(providerName); + await CheckProviderPolicy(providerName, providerKey); foreach (var feature in input.Features) { - var featureDefinition = FeatureDefinitionManager.GetOrNull(feature.Name); - if (featureDefinition == null || (providerName == HostFeatureValueProvider.ProviderName && !featureDefinition.IsAvailableToHost)) - { - throw new UserFriendlyException(L["FeatureNotAvailable"]); - } - await FeatureManager.SetAsync(feature.Name, feature.Value, providerName, providerKey); } } @@ -105,12 +102,22 @@ namespace Volo.Abp.FeatureManagement } } - protected virtual async Task CheckProviderPolicy(string providerName) + protected virtual async Task CheckProviderPolicy(string providerName, string providerKey) { - var policyName = Options.ProviderPolicies.GetOrDefault(providerName); - if (policyName.IsNullOrEmpty()) + string policyName; + if (providerName == TenantFeatureValueProvider.ProviderName) { - throw new AbpException($"No policy defined to get/set permissions for the provider '{policyName}'. Use {nameof(FeatureManagementOptions)} to map the policy."); + policyName = CurrentTenant.Id == null && providerKey == null ? + "FeatureManagement.ManageHostFeatures" : + "AbpTenantManagement.Tenants.ManageFeatures"; + } + else + { + policyName = Options.ProviderPolicies.GetOrDefault(providerName); + if (policyName.IsNullOrEmpty()) + { + throw new AbpException($"No policy defined to get/set permissions for the provider '{policyName}'. Use {nameof(FeatureManagementOptions)} to map the policy."); + } } await AuthorizationService.CheckAsync(policyName); diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json index 6e17e8fc48..26f5dc736b 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/en.json @@ -3,7 +3,6 @@ "texts": { "Features": "Features", "NoFeatureFoundMessage": "There isn't any available feature.", - "FeatureNotAvailable": "Feature not available.", "Permission:FeatureManagement": "Feature management", "Permission:FeatureManagement.ManageHostFeatures": "Manage Host features" } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json index 285b4143cf..8233674933 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/tr.json @@ -3,7 +3,6 @@ "texts": { "Features": "Özellikler", "NoFeatureFoundMessage": "Hiç özellik yok.", - "FeatureNotAvailable": "Özellik bulunamadı.", "Permission:FeatureManagement": "Özellik yönetimi", "Permission:FeatureManagement.ManageHostFeatures": "Host özelliklerini düzenle" } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json index 2ecdb3997b..9737a9a59c 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hans.json @@ -3,7 +3,6 @@ "texts": { "Features": "功能", "NoFeatureFoundMessage": "没有可用的功能.", - "FeatureNotAvailable": "功能不可用.", "Permission:FeatureManagement": "特性管理", "Permission:FeatureManagement.ManageHostFeatures": "管理Host特性" } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json index 6a8ccd099b..7d68fd5bc2 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain.Shared/Volo/Abp/FeatureManagement/Localization/Domain/zh-Hant.json @@ -3,7 +3,6 @@ "texts": { "Features": "功能", "NoFeatureFoundMessage": "沒有可用的功能.", - "FeatureNotAvailable": "功能不可用.", "Permission:FeatureManagement": "功能管理", "Permission:FeatureManagement.ManageHostFeatures": "管理Host功能" } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs index b9992309dd..34a0e198c7 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs @@ -18,13 +18,10 @@ namespace Volo.Abp.FeatureManagement Configure(options => { options.Providers.Add(); - options.Providers.Add(); - options.ProviderPolicies[HostFeatureValueProvider.ProviderName] = "FeatureManagement.ManageHostFeatures"; options.Providers.Add(); //TODO: Should be moved to the Tenant Management module options.Providers.Add(); - options.ProviderPolicies[TenantFeatureValueProvider.ProviderName] = "AbpTenantManagement.Tenants.ManageFeatures"; }); Configure(options => diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs deleted file mode 100644 index d40d2dfdec..0000000000 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/HostFeatureManagementProvider.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Features; -using Volo.Abp.MultiTenancy; - -namespace Volo.Abp.FeatureManagement -{ - public class HostFeatureManagementProvider : FeatureManagementProvider, ITransientDependency - { - public override string Name => HostFeatureValueProvider.ProviderName; - - protected ICurrentTenant CurrentTenant { get; } - - public HostFeatureManagementProvider( - IFeatureManagementStore store, - ICurrentTenant currentTenant) - : base(store) - { - CurrentTenant = currentTenant; - } - - public override async Task GetOrNullAsync(FeatureDefinition feature, string providerKey) - { - if (IsHostSide(feature)) - { - return await Store.GetOrNullAsync(feature.Name, Name, NormalizeProviderKey(providerKey)); - } - - return null; - } - - public override async Task SetAsync(FeatureDefinition feature, string value, string providerKey) - { - if (IsHostSide(feature)) - { - await Store.SetAsync(feature.Name, value, Name, NormalizeProviderKey(providerKey)); - } - } - - public override async Task ClearAsync(FeatureDefinition feature, string providerKey) - { - if (IsHostSide(feature)) - { - await Store.DeleteAsync(feature.Name, Name, NormalizeProviderKey(providerKey)); - } - } - - protected override string NormalizeProviderKey(string providerKey) - { - return null; - } - - //TODO: Should throw an ex when there is not in the host side? - protected virtual bool IsHostSide(FeatureDefinition feature) - { - return feature.IsAvailableToHost && CurrentTenant.Id == null; - } - } -} diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js index ecb2309f36..69bbb0b955 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Web/Pages/TenantManagement/Tenants/Index.js @@ -132,7 +132,7 @@ _$wrapper.find('button[name=ManageHostFeatures]').click(function (e) { e.preventDefault(); _featuresModal.open({ - providerName: 'H' + providerName: 'T' }); }); }); From 3fa367455213636f564435862233788d0f535eec Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Wed, 9 Sep 2020 22:43:56 +0800 Subject: [PATCH 7/7] Refactor. --- .../Volo/Abp/FeatureManagement/FeatureAppService.cs | 6 ++---- .../FeatureManagement/AbpFeatureManagementDomainModule.cs | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs index 6f0fe4815e..bfb6e65ea8 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application/Volo/Abp/FeatureManagement/FeatureAppService.cs @@ -105,11 +105,9 @@ namespace Volo.Abp.FeatureManagement protected virtual async Task CheckProviderPolicy(string providerName, string providerKey) { string policyName; - if (providerName == TenantFeatureValueProvider.ProviderName) + if (providerName == TenantFeatureValueProvider.ProviderName && CurrentTenant.Id == null && providerKey == null ) { - policyName = CurrentTenant.Id == null && providerKey == null ? - "FeatureManagement.ManageHostFeatures" : - "AbpTenantManagement.Tenants.ManageFeatures"; + policyName = "FeatureManagement.ManageHostFeatures"; } else { diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs index 34a0e198c7..38a2fa3c56 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/AbpFeatureManagementDomainModule.cs @@ -22,6 +22,7 @@ namespace Volo.Abp.FeatureManagement //TODO: Should be moved to the Tenant Management module options.Providers.Add(); + options.ProviderPolicies[TenantFeatureValueProvider.ProviderName] = "AbpTenantManagement.Tenants.ManageFeatures"; }); Configure(options =>