From b5915801debe66b63e262ce215c26da18517c43e Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 10 Jun 2020 10:06:13 +0300 Subject: [PATCH] Fix: Feature values are not cleared entirely in database resolves https://github.com/abpframework/abp/issues/4289 --- .../Abp/FeatureManagement/FeatureManagementStore.cs | 6 +++--- .../Volo/Abp/FeatureManagement/FeatureManager.cs | 2 +- .../Abp/FeatureManagement/IFeatureValueRepository.cs | 2 ++ .../EfCoreFeatureValueRepository.cs | 10 +++++++++- .../MongoDB/MongoFeatureValueRepository.cs | 8 +++++++- .../FeatureValueRepository_Tests.cs | 12 ++++++++++++ 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs index 8f3574d4a2..b35225edb2 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManagementStore.cs @@ -44,8 +44,8 @@ namespace Volo.Abp.FeatureManagement public virtual async Task DeleteAsync(string name, string providerName, string providerKey) { - var featureValue = await FeatureValueRepository.FindAsync(name, providerName, providerKey); - if (featureValue != null) + var featureValues = await FeatureValueRepository.FindAllAsync(name, providerName, providerKey); + foreach (var featureValue in featureValues) { await FeatureValueRepository.DeleteAsync(featureValue); } @@ -78,4 +78,4 @@ namespace Volo.Abp.FeatureManagement return FeatureValueCacheItem.CalculateCacheKey(name, providerName, providerKey); } } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs index 06ca345bf6..04b7ab6682 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs @@ -183,4 +183,4 @@ namespace Volo.Abp.FeatureManagement return value; } } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/IFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/IFeatureValueRepository.cs index c630d045a1..f5b5c85da4 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/IFeatureValueRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/IFeatureValueRepository.cs @@ -9,6 +9,8 @@ namespace Volo.Abp.FeatureManagement { Task FindAsync(string name, string providerName, string providerKey); + Task> FindAllAsync(string name, string providerName, string providerKey); + Task> GetListAsync(string providerName, string providerKey); } } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs index 34a6c1bbb3..22e7b2775d 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.EntityFrameworkCore/Volo/Abp/FeatureManagement/EntityFrameworkCore/EfCoreFeatureValueRepository.cs @@ -23,6 +23,14 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore ); } + public async Task> FindAllAsync(string name, string providerName, string providerKey) + { + return await DbSet + .Where( + s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey + ).ToListAsync(); + } + public virtual async Task> GetListAsync(string providerName, string providerKey) { return await DbSet @@ -31,4 +39,4 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore ).ToListAsync(); } } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs index 7db01d5288..72e5ac4b3b 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs @@ -22,6 +22,12 @@ namespace Volo.Abp.FeatureManagement.MongoDB .FirstOrDefaultAsync(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey); } + public async Task> FindAllAsync(string name, string providerName, string providerKey) + { + return await GetMongoQueryable() + .Where(s => s.Name == name && s.ProviderName == providerName && s.ProviderKey == providerKey).ToListAsync(); + } + public virtual async Task> GetListAsync(string providerName, string providerKey) { return await GetMongoQueryable() @@ -29,4 +35,4 @@ namespace Volo.Abp.FeatureManagement.MongoDB .ToListAsync(); } } -} \ No newline at end of file +} diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs index c7cbb0d8ae..db606b2582 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs @@ -40,6 +40,18 @@ namespace Volo.Abp.FeatureManagement featureValue.ShouldBeNull(); } + [Fact] + public async Task FindAAllsync() + { + var featureValues = await Repository.FindAllAsync( + TestFeatureDefinitionProvider.ProjectCount, + EditionFeatureValueProvider.ProviderName, + TestEditionIds.Enterprise.ToString() + ); + + featureValues.Count.ShouldBe(1); + } + [Fact] public async Task GetListAsync() {