From 80a1b0bfdb35faca35f8d7ef5161d7c6b211eca9 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 7 Sep 2020 17:22:02 +0800 Subject: [PATCH 01/13] Add unadded users/roles method to OrganizationUnitRepository --- .../Identity/IOrganizationUnitRepository.cs | 16 ++++++ .../Volo/Abp/Identity/OrganizationUnit.cs | 10 ++-- .../EfCoreOrganizationUnitRepository.cs | 52 +++++++++++++++++-- .../MongoOrganizationUnitRepository.cs | 37 +++++++++++++ .../OrganizationUnitRepository_Tests.cs | 21 ++++++++ 5 files changed, 128 insertions(+), 8 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs index 6650f62c82..81474425db 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs @@ -55,6 +55,14 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default ); + Task> GetUnaddedRolesAsync( + OrganizationUnit organizationUnit, + string filter = null, + string sorting = null, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); + Task> GetMembersAsync( OrganizationUnit organizationUnit, string sorting = null, @@ -71,6 +79,14 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default ); + Task> GetUnaddedUsersAsync( + OrganizationUnit organizationUnit, + string filter = null, + string sorting = null, + bool includeDetails = false, + CancellationToken cancellationToken = default + ); + Task RemoveAllRolesAsync( OrganizationUnit organizationUnit, CancellationToken cancellationToken = default diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnit.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnit.cs index 3d1bbb0531..981a0f8fae 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnit.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnit.cs @@ -23,16 +23,16 @@ namespace Volo.Abp.Identity /// /// Hierarchical Code of this organization unit. /// Example: "00001.00042.00005". - /// This is a unique code for a Tenant. + /// This is a unique code for an OrganizationUnit. /// It's changeable if OU hierarchy is changed. /// public virtual string Code { get; internal set; } /// - /// Display name of this role. + /// Display name of this OrganizationUnit. /// - public virtual string DisplayName { get; set; } - + public virtual string DisplayName { get; set; } + /// /// Roles of this OU. /// @@ -77,7 +77,7 @@ namespace Volo.Abp.Identity } /// - /// Appends a child code to a parent code. + /// Appends a child code to a parent code. /// Example: if parentCode = "00001", childCode = "00042" then returns "00001.00042". /// /// Parent code. Can be null or empty if parent is a root. diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs index 7bdb7d6837..d50745ab1d 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs @@ -12,7 +12,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { public class EfCoreOrganizationUnitRepository : EfCoreRepository, - IOrganizationUnitRepository + IOrganizationUnitRepository { public EfCoreOrganizationUnitRepository( IDbContextProvider dbContextProvider) @@ -56,6 +56,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } + public virtual async Task> GetListAsync( IEnumerable ids, bool includeDetails = false, @@ -111,6 +112,23 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return await query.CountAsync(GetCancellationToken(cancellationToken)); } + public virtual async Task> GetUnaddedRolesAsync( + OrganizationUnit organizationUnit, + string filter = null, + string sorting = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToList(); + + return await DbContext.Roles + .Where(r => !roleIds.Contains(r.Id)) + .IncludeDetails(includeDetails) + .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) + .OrderBy(sorting ?? nameof(IdentityRole.Name)) + .ToListAsync(cancellationToken); + } + public virtual async Task> GetMembersAsync( OrganizationUnit organizationUnit, string sorting = null, @@ -118,8 +136,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore int skipCount = 0, string filter = null, bool includeDetails = false, - CancellationToken cancellationToken = default - ) + CancellationToken cancellationToken = default) { var query = CreateGetMembersFilteredQuery(organizationUnit, filter); @@ -138,6 +155,35 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return await query.CountAsync(GetCancellationToken(cancellationToken)); } + public virtual async Task> GetUnaddedUsersAsync( + OrganizationUnit organizationUnit, + string filter = null, + string sorting = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var userIdsInOrganizationUnit = DbContext.Set() + .Where(uou => uou.OrganizationUnitId == organizationUnit.Id) + .Select(uou => uou.UserId); + + var query = DbContext.Users + .Where(u => !userIdsInOrganizationUnit.Contains(u.Id)); + + if (!filter.IsNullOrWhiteSpace()) + { + query = query.Where(u => + u.UserName.Contains(filter) || + u.Email.Contains(filter) || + (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) + ); + } + + return await query + .IncludeDetails(includeDetails) + .OrderBy(sorting ?? nameof(IdentityUser.Name)) + .ToListAsync(cancellationToken); + } + public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs index 8c163d4126..2823c99a6c 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs @@ -107,6 +107,22 @@ namespace Volo.Abp.Identity.MongoDB .CountAsync(cancellationToken); } + public async Task> GetUnaddedRolesAsync( + OrganizationUnit organizationUnit, + string filter = null, + string sorting = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); + return await DbContext.Roles.AsQueryable() + .Where(r => !roleIds.Contains(r.Id)) + .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) + .OrderBy(sorting ?? nameof(IdentityRole.Name)) + .As>() + .ToListAsync(cancellationToken); + } + public virtual async Task> GetMembersAsync( OrganizationUnit organizationUnit, string sorting = null, @@ -135,6 +151,27 @@ namespace Volo.Abp.Identity.MongoDB return await query.CountAsync(GetCancellationToken(cancellationToken)); } + public async Task> GetUnaddedUsersAsync( + OrganizationUnit organizationUnit, + string filter = null, + string sorting = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + return await DbContext.Users.AsQueryable() + .Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) + .WhereIf>( + !filter.IsNullOrWhiteSpace(), + u => + u.UserName.Contains(filter) || + u.Email.Contains(filter) || + (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) + ) + .OrderBy(sorting ?? nameof(IdentityUser.UserName)) + .As>() + .ToListAsync(GetCancellationToken(cancellationToken)); + } + public virtual Task RemoveAllRolesAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) { organizationUnit.Roles.Clear(); diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs index bb8300d449..97544cd1e9 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs @@ -284,5 +284,26 @@ namespace Volo.Abp.Identity await uow.CompleteAsync(); } } + + [Fact] + public async Task GetUnaddedUsersOfOrganizationUnitAsync() + { + var ou = await _organizationUnitRepository.GetAsync("OU111", true); + var unaddedUsers = await _organizationUnitRepository.GetUnaddedUsersAsync(ou); + + unaddedUsers.ShouldNotContain(u => u.UserName == "john.nash"); + unaddedUsers.ShouldContain(u => u.UserName == "administrator"); + } + + [Fact] + public async Task GetUnaddedRolesOfOrganizationUnitAsync() + { + var ou = await _organizationUnitRepository.GetAsync("OU111", true); + var unaddedRoles = await _organizationUnitRepository.GetUnaddedRolesAsync(ou); + + unaddedRoles.ShouldNotContain(u => u.Name == "manager"); + unaddedRoles.ShouldNotContain(u => u.Name == "moderator"); + unaddedRoles.ShouldContain(u => u.Name.Contains("admin")); + } } } From 731539ef84a655c47e92891417aa1a72dafc236a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 8 Sep 2020 10:43:42 +0300 Subject: [PATCH 02/13] Added Feature Management section. --- docs/en/Features.md | 35 +++++++++++++++++++++++- docs/en/Modules/Feature-Management.md | 2 ++ docs/en/Modules/Permission-Management.md | 2 ++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/en/Features.md b/docs/en/Features.md index 1ab26a113a..05712eb803 100644 --- a/docs/en/Features.md +++ b/docs/en/Features.md @@ -170,6 +170,8 @@ namespace FeaturesDemo > ABP automatically discovers this class and registers the features. No additional configuration required. +> This class is generally created in the `Application.Contracts` project of your solution. + * In the `Define` method, you first need to add a **feature group** for your application/module or get an existing group then add **features** to this group. * First feature, named `MyApp.PdfReporting`, is a `boolean` feature with `false` as the default value. * Second feature, named `MyApp.MaxProductCount`, is a numeric feature with `10` as the default value. @@ -339,7 +341,38 @@ See the [features](Features.md) document for the Angular UI. ## Feature Management -TODO +Feature management is normally done by an admin user using the feature management modal: + +![features-modal](images/features-modal.png) + +This modal is available on the related entities, like tenants in a multi-tenant application. To open it, navigate to the **Tenant Management** page (for a multi-tenant application), click to the **Actions** button left to the Tenant and select the **Features** action. + +If you need to manage features by code, inject the `IFeatureManager` service. + +**Example: Enable PDF reporting for a tenant** + +```csharp +public class MyService : ITransientDependency +{ + private readonly IFeatureManager _featureManager; + + public MyService(IFeatureManager featureManager) + { + _featureManager = featureManager; + } + + public async Task EnablePdfReporting(Guid tenantId) + { + await _featureManager.SetForTenantAsync( + tenantId, + "MyApp.PdfReporting", + true.ToString() + ); + } +} +``` + +`IFeatureManager` is defined by the Feature Management module. It comes pre-installed with the application startup template. See the [feature management module documentation](Modules/Feature-Management.md) for more information. ## Advanced Topics diff --git a/docs/en/Modules/Feature-Management.md b/docs/en/Modules/Feature-Management.md index 5c41277dd8..968b742092 100644 --- a/docs/en/Modules/Feature-Management.md +++ b/docs/en/Modules/Feature-Management.md @@ -1,3 +1,5 @@ # Feature Management Module +> This module implements the `IFeatureStore` to store and manage feature values in a database. See the [Features System document](../Features.md) to understand the features first. + TODO \ No newline at end of file diff --git a/docs/en/Modules/Permission-Management.md b/docs/en/Modules/Permission-Management.md index faa03eecc9..ad48b60171 100644 --- a/docs/en/Modules/Permission-Management.md +++ b/docs/en/Modules/Permission-Management.md @@ -1,3 +1,5 @@ # Permission Management Module +This module implements the `IPermissionStore` to store and manage feature values in a database. See the [Authorization document](../Authorization.md) to understand the authorization and permission systems first. + TODO \ No newline at end of file From 5c173a692e6d927d82688cca0c446f054d0fcf63 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 8 Sep 2020 15:54:12 +0800 Subject: [PATCH 03/13] Group features on the feature management modal --- .../Abp/Features/FeatureDefinitionManager.cs | 9 +- .../Abp/Features/IFeatureDefinitionManager.cs | 4 +- .../Abp/FeatureManagement/FeatureGroupDto.cs | 18 ++++ .../Abp/FeatureManagement/FeatureListDto.cs | 9 -- .../GetFeatureListResultDto.cs | 9 ++ .../FeatureManagement/IFeatureAppService.cs | 2 +- .../FeatureManagement/FeatureAppService.cs | 55 +++++++---- .../FeatureManagement/FeaturesController.cs | 2 +- .../FeatureManagementModal.cshtml | 98 +++++++++++-------- .../FeatureManagementModal.cshtml.cs | 19 +++- .../FeatureAppService_Tests.cs | 4 +- .../StringValueJsonConverter_Tests.cs | 82 +++++++++------- 12 files changed, 190 insertions(+), 121 deletions(-) create mode 100644 modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureGroupDto.cs delete mode 100644 modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureListDto.cs create mode 100644 modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/GetFeatureListResultDto.cs diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinitionManager.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinitionManager.cs index f8e8d9e9fe..31498e0756 100644 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinitionManager.cs +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureDefinitionManager.cs @@ -62,6 +62,11 @@ namespace Volo.Abp.Features return FeatureDefinitions.GetOrDefault(name); } + public IReadOnlyList GetGroups() + { + return FeatureGroupDefinitions.Values.ToImmutableList(); + } + protected virtual Dictionary CreateFeatureDefinitions() { var features = new Dictionary(); @@ -78,7 +83,7 @@ namespace Volo.Abp.Features } protected virtual void AddFeatureToDictionaryRecursively( - Dictionary features, + Dictionary features, FeatureDefinition feature) { if (features.ContainsKey(feature.Name)) @@ -114,4 +119,4 @@ namespace Volo.Abp.Features return context.Groups; } } -} \ No newline at end of file +} diff --git a/framework/src/Volo.Abp.Features/Volo/Abp/Features/IFeatureDefinitionManager.cs b/framework/src/Volo.Abp.Features/Volo/Abp/Features/IFeatureDefinitionManager.cs index c0172d7bc3..ca0a8cbcc6 100644 --- a/framework/src/Volo.Abp.Features/Volo/Abp/Features/IFeatureDefinitionManager.cs +++ b/framework/src/Volo.Abp.Features/Volo/Abp/Features/IFeatureDefinitionManager.cs @@ -11,5 +11,7 @@ namespace Volo.Abp.Features IReadOnlyList GetAll(); FeatureDefinition GetOrNull(string name); + + IReadOnlyList GetGroups(); } -} \ No newline at end of file +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureGroupDto.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureGroupDto.cs new file mode 100644 index 0000000000..dea10fd298 --- /dev/null +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureGroupDto.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace Volo.Abp.FeatureManagement +{ + public class FeatureGroupDto + { + public string Name { get; set; } + + public string DisplayName { get; set; } + + public List Features { get; set; } + + public string GetNormalizedGroupName() + { + return Name.Replace(".", "_"); + } + } +} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureListDto.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureListDto.cs deleted file mode 100644 index ee7bad8d5c..0000000000 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/FeatureListDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Volo.Abp.FeatureManagement -{ - public class FeatureListDto - { - public List Features { get; set; } - } -} \ No newline at end of file diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/GetFeatureListResultDto.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/GetFeatureListResultDto.cs new file mode 100644 index 0000000000..86329598cc --- /dev/null +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Application.Contracts/Volo/Abp/FeatureManagement/GetFeatureListResultDto.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.FeatureManagement +{ + public class GetFeatureListResultDto + { + public List Groups { get; set; } + } +} 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..00c36b7f55 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,7 +6,7 @@ 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); } 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..dbe649e51f 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 @@ -4,6 +4,7 @@ using System.Threading.Tasks; using JetBrains.Annotations; using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Options; +using Volo.Abp.Authorization.Permissions; using Volo.Abp.Features; namespace Volo.Abp.FeatureManagement @@ -24,35 +25,49 @@ 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, [NotNull] string providerKey) { await CheckProviderPolicy(providerName); - var featureDefinitions = FeatureDefinitionManager.GetAll(); - var features = new List(); + var result = new GetFeatureListResultDto + { + Groups = new List() + }; - foreach (var featureDefinition in featureDefinitions) + foreach (var group in FeatureDefinitionManager.GetGroups()) { - var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, providerName, providerKey); - features.Add(new FeatureDto + var groupDto = new FeatureGroupDto + { + Name = group.Name, + DisplayName = group.DisplayName.Localize(StringLocalizerFactory), + Features = new List() + }; + + foreach (var featureDefinition in group.GetFeaturesWithChildren()) { - 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 + var feature = await FeatureManager.GetOrNullWithProviderAsync(featureDefinition.Name, providerName, providerKey); + groupDto.Features.Add(new FeatureDto { - Name = feature.Provider?.Name, - Key = feature.Provider?.Key - } - }); - } + 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(groupDto.Features, providerName, providerKey); - SetFeatureDepth(features, providerName, providerKey); + result.Groups.Add(groupDto); + } - return new FeatureListDto { Features = features }; + return result; } public virtual async Task UpdateAsync([NotNull] string providerName, [NotNull] string providerKey, UpdateFeaturesDto input) 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..cc00fb370b 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 @@ -17,7 +17,7 @@ namespace Volo.Abp.FeatureManagement } [HttpGet] - public virtual Task GetAsync(string providerName, string providerKey) + public virtual Task GetAsync(string providerName, string providerKey) { return FeatureAppService.GetAsync(providerName, providerKey); } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml index f5adbf79d4..601926b193 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Web/Pages/FeatureManagement/FeatureManagementModal.cshtml @@ -4,7 +4,6 @@ @using Volo.Abp.FeatureManagement.Localization @using Volo.Abp.Validation.StringValues @using Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement -@using Volo.Abp.Features @model FeatureManagementModal @inject IHtmlLocalizer L @{ @@ -13,53 +12,67 @@
- @if (Model.FeatureListDto?.Features != null && Model.FeatureListDto.Features.Any()) + @if (Model.FeatureListResultDto != null && Model.FeatureListResultDto.Groups.Any()) { - - - @for (var i = 0; i < Model.FeatureListDto.Features.Count; i++) - { - var feature = Model.FeatureListDto.Features[i]; - var disabled = Model.IsDisabled(feature.Provider.Name); -
+ + + + @for (var i = 0; i < Model.FeatureListResultDto.Groups.Count; i++) + { + +

@Model.FeatureListResultDto.Groups[i].DisplayName

+
+
+
+ @for (var j = 0; j < Model.FeatureListResultDto.Groups[i].Features.Count; j++) + { + var feature = Model.FeatureListResultDto.Groups[i].Features[j]; + var disabled = Model.IsDisabled(feature.Provider.Name); +
- @feature.DisplayName @(disabled ? $"({feature.Provider.Name})" : "") + @feature.DisplayName @(disabled ? $"({feature.Provider.Name})" : "") - - - @if (feature.ValueType is FreeTextStringValueType) - { - - - } - @if (feature.ValueType is SelectionStringValueType) - { - - + + @if (feature.ValueType is FreeTextStringValueType) + { + + + } + @if (feature.ValueType is SelectionStringValueType) + { + + + } + @if (feature.ValueType is ToggleStringValueType) + { + + + } +
} - } - - } - @if (feature.ValueType is ToggleStringValueType) - { - - - } -
- } +
+
+ + } + +
- + } else { @@ -69,4 +82,3 @@ }
- 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..1464a1fc9b 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 @@ -22,9 +22,9 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement public string ProviderKey { get; set; } [BindProperty] - public List Features { get; set; } + public List FeatureGroups { get; set; } - public FeatureListDto FeatureListDto { get; set; } + public GetFeatureListResultDto FeatureListResultDto { get; set; } protected IFeatureAppService FeatureAppService { get; } @@ -35,16 +35,20 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement FeatureAppService = featureAppService; } - public virtual async Task OnGetAsync() + public virtual async Task OnGetAsync() { - FeatureListDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey); + ValidateModel(); + + FeatureListResultDto = await FeatureAppService.GetAsync(ProviderName, ProviderKey); + + return Page(); } public virtual async Task OnPostAsync() { var features = new UpdateFeaturesDto { - Features = Features.Select(f => new UpdateFeatureDto + Features = FeatureGroups.SelectMany(g => g.Features).Select(f => new UpdateFeatureDto { Name = f.Name, Value = f.Type == nameof(ToggleStringValueType) ? f.BoolValue.ToString() : f.Value @@ -68,6 +72,11 @@ namespace Volo.Abp.FeatureManagement.Web.Pages.FeatureManagement public string ProviderKey { get; set; } } + public class FeatureGroupViewModel + { + public List Features { get; set; } + } + public class FeatureViewModel { public string Name { get; set; } diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/FeatureAppService_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/FeatureAppService_Tests.cs index b257f873cd..2f904a46d2 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/FeatureAppService_Tests.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/FeatureAppService_Tests.cs @@ -41,7 +41,7 @@ namespace Volo.Abp.FeatureManagement TestEditionIds.Regular.ToString()); featureList.ShouldNotBeNull(); - featureList.Features.ShouldContain(feature => feature.Name == TestFeatureDefinitionProvider.SocialLogins); + featureList.Groups.SelectMany(g =>g .Features).ShouldContain(feature => feature.Name == TestFeatureDefinitionProvider.SocialLogins); } [Fact] @@ -63,7 +63,7 @@ namespace Volo.Abp.FeatureManagement }); (await _featureAppService.GetAsync(EditionFeatureValueProvider.ProviderName, - TestEditionIds.Regular.ToString())).Features.Any(x => + TestEditionIds.Regular.ToString())).Groups.SelectMany(g => g.Features).Any(x => x.Name == TestFeatureDefinitionProvider.SocialLogins && x.Value == false.ToString().ToLowerInvariant()) .ShouldBeTrue(); diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/StringValueJsonConverter_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/StringValueJsonConverter_Tests.cs index 528e0de5e8..1b7553b773 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/StringValueJsonConverter_Tests.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.Application.Tests/Volo/Abp/FeatureManagement/StringValueJsonConverter_Tests.cs @@ -20,38 +20,46 @@ namespace Volo.Abp.FeatureManagement [Fact] public void Should_Serialize_And_Deserialize() { - var featureListDto = new FeatureListDto + var featureListDto = new GetFeatureListResultDto { - Features = new List + Groups = new List { - new FeatureDto + new FeatureGroupDto { - ValueType = new FreeTextStringValueType + Name = "MyGroup", + DisplayName = "MyGroup", + Features = new List { - Validator = new BooleanValueValidator() - } - }, - new FeatureDto - { - ValueType = new SelectionStringValueType - { - ItemSource = new StaticSelectionStringValueItemSource( - new LocalizableSelectionStringValueItem + new FeatureDto + { + ValueType = new FreeTextStringValueType { - Value = "TestValue", - DisplayText = new LocalizableStringInfo("TestResourceName", "TestName") - }), - Validator = new AlwaysValidValueValidator() - } - }, - new FeatureDto - { - ValueType = new ToggleStringValueType - { - Validator = new NumericValueValidator + Validator = new BooleanValueValidator() + } + }, + new FeatureDto { - MaxValue = 1000, - MinValue = 10 + ValueType = new SelectionStringValueType + { + ItemSource = new StaticSelectionStringValueItemSource( + new LocalizableSelectionStringValueItem + { + Value = "TestValue", + DisplayText = new LocalizableStringInfo("TestResourceName", "TestName") + }), + Validator = new AlwaysValidValueValidator() + } + }, + new FeatureDto + { + ValueType = new ToggleStringValueType + { + Validator = new NumericValueValidator + { + MaxValue = 1000, + MinValue = 10 + } + } } } } @@ -59,22 +67,22 @@ namespace Volo.Abp.FeatureManagement }; var serialized = _jsonSerializer.Serialize(featureListDto, indented: true); - var featureListDto2 = _jsonSerializer.Deserialize(serialized); + var featureListDto2 = _jsonSerializer.Deserialize(serialized); - featureListDto2.Features[0].ValueType.ShouldBeOfType(); - featureListDto2.Features[0].ValueType.Validator.ShouldBeOfType(); + featureListDto2.Groups[0].Features[0].ValueType.ShouldBeOfType(); + featureListDto2.Groups[0].Features[0].ValueType.Validator.ShouldBeOfType(); - featureListDto2.Features[1].ValueType.ShouldBeOfType(); - featureListDto2.Features[1].ValueType.Validator.ShouldBeOfType(); - featureListDto2.Features[1].ValueType.As().ItemSource.Items.ShouldBeOfType(); - featureListDto2.Features[1].ValueType.As().ItemSource.Items.ShouldContain(x => + featureListDto2.Groups[0].Features[1].ValueType.ShouldBeOfType(); + featureListDto2.Groups[0].Features[1].ValueType.Validator.ShouldBeOfType(); + featureListDto2.Groups[0].Features[1].ValueType.As().ItemSource.Items.ShouldBeOfType(); + featureListDto2.Groups[0].Features[1].ValueType.As().ItemSource.Items.ShouldContain(x => x.Value == "TestValue" && x.DisplayText.ResourceName == "TestResourceName" && x.DisplayText.Name == "TestName"); - featureListDto2.Features[2].ValueType.ShouldBeOfType(); - featureListDto2.Features[2].ValueType.Validator.ShouldBeOfType(); - featureListDto2.Features[2].ValueType.Validator.As().MaxValue.ShouldBe(1000); - featureListDto2.Features[2].ValueType.Validator.As().MinValue.ShouldBe(10); + featureListDto2.Groups[0].Features[2].ValueType.ShouldBeOfType(); + featureListDto2.Groups[0].Features[2].ValueType.Validator.ShouldBeOfType(); + featureListDto2.Groups[0].Features[2].ValueType.Validator.As().MaxValue.ShouldBe(1000); + featureListDto2.Groups[0].Features[2].ValueType.Validator.As().MinValue.ShouldBe(10); } } } From 8fdbab9576574b37b3a112e965c91fe0fe64da09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 8 Sep 2020 11:09:28 +0300 Subject: [PATCH 04/13] Completed the Features document. --- docs/en/Features.md | 67 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/docs/en/Features.md b/docs/en/Features.md index 05712eb803..1ec35f730a 100644 --- a/docs/en/Features.md +++ b/docs/en/Features.md @@ -176,6 +176,8 @@ namespace FeaturesDemo * First feature, named `MyApp.PdfReporting`, is a `boolean` feature with `false` as the default value. * Second feature, named `MyApp.MaxProductCount`, is a numeric feature with `10` as the default value. +Default value is used if there is no other value set for the current user/tenant. + ### Other Feature Properties While these minimal definitions are enough to make the feature system working, you can specify the **optional properties** for the features; @@ -376,11 +378,70 @@ public class MyService : ITransientDependency ## Advanced Topics -TODO - ### Feature Value Providers -TODO +Feature system is extensible. Any class derived from `FeatureValueProvider` (or implements `IFeatureValueProvider`) can contribute to the feature system. A value provider is responsible to **obtain the current value** of a given feature. + +Feature value providers are **executed one by one**. If one of them return a non-null value, then this feature value is used and the other providers are not executed. + +There are three pre-defined value providers, executed by the given order: + +* `TenantFeatureValueProvider` tries to get if the feature value is explicitly set for the **current tenant**. +* `EditionFeatureValueProvider` tries to get the feature value for the current edition. Edition Id is obtained from the current principal identity (`ICurrentPrincipalAccessor`) with the claim name `editionid` (a constant defined as`AbpClaimTypes.EditionId`). Editions are not implemented for the [tenant management](Modules/Tenant-Management.md) module. You can implement it yourself or consider to use the [SaaS module](https://commercial.abp.io/modules/Volo.Saas) of the ABP Commercial. +* `DefaultValueFeatureValueProvider` gets the default value of the feature. + +You can write your own provider by inheriting the `FeatureValueProvider`. + +**Example: Enable all features for a user with "SystemAdmin" as a "User_Type" claim value** + +```csharp +using System.Threading.Tasks; +using Volo.Abp.Features; +using Volo.Abp.Security.Claims; +using Volo.Abp.Validation.StringValues; + +namespace FeaturesDemo +{ + public class SystemAdminFeatureValueProvider : FeatureValueProvider + { + public override string Name => "SA"; + + private readonly ICurrentPrincipalAccessor _currentPrincipalAccessor; + + public SystemAdminFeatureValueProvider( + IFeatureStore featureStore, + ICurrentPrincipalAccessor currentPrincipalAccessor) + : base(featureStore) + { + _currentPrincipalAccessor = currentPrincipalAccessor; + } + + public override Task GetOrNullAsync(FeatureDefinition feature) + { + if (feature.ValueType is ToggleStringValueType && + _currentPrincipalAccessor.Principal?.FindFirst("User_Type")?.Value == "SystemAdmin") + { + return Task.FromResult("true"); + } + + return null; + } + } +} +``` + +If a provider returns `null`, then the next provider is executed. + +Once a provider is defined, it should be added to the `AbpFeatureOptions` as shown below: + +```csharp +Configure(options => +{ + options.ValueProviders.Add(); +}); +``` + +Use this code inside the `ConfigureServices` of your [module](Module-Development-Basics.md) class. ### Feature Store From 311287cce9b522f326e16e6138b378b020884251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 8 Sep 2020 11:14:48 +0300 Subject: [PATCH 05/13] Added Features to the nav menu --- docs/en/Multi-Tenancy.md | 3 +++ docs/en/docs-nav.json | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/docs/en/Multi-Tenancy.md b/docs/en/Multi-Tenancy.md index 901a5c5cff..5138c9de04 100644 --- a/docs/en/Multi-Tenancy.md +++ b/docs/en/Multi-Tenancy.md @@ -369,3 +369,6 @@ options.AddDomainTenantResolver("{0}.mydomain.com"); options.AddDomainTenantResolver("{0}.com"); ```` +## See Also + +* [Features](Features.md) \ No newline at end of file diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index dc872a2279..654bc720e2 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -170,6 +170,10 @@ "text": "Settings", "path": "Settings.md" }, + { + "text": "Features", + "path": "Features.md" + }, { "text": "Data Filtering", "path": "Data-Filtering.md" From f5b6ef2388250eb4c742254ff9b0b0331299702d Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 8 Sep 2020 18:06:58 +0800 Subject: [PATCH 06/13] add paged --- .../Volo/Abp/Identity/IOrganizationUnitRepository.cs | 8 ++++++-- .../EfCoreOrganizationUnitRepository.cs | 10 ++++++++-- .../MongoDB/MongoOrganizationUnitRepository.cs | 10 ++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs index 81474425db..4d5bf7d060 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs @@ -57,8 +57,10 @@ namespace Volo.Abp.Identity Task> GetUnaddedRolesAsync( OrganizationUnit organizationUnit, - string filter = null, string sorting = null, + int maxResultCount = int.MaxValue, + int skipCount = 0, + string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default ); @@ -81,8 +83,10 @@ namespace Volo.Abp.Identity Task> GetUnaddedUsersAsync( OrganizationUnit organizationUnit, - string filter = null, string sorting = null, + int maxResultCount = int.MaxValue, + int skipCount = 0, + string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default ); diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs index d50745ab1d..ebfa9b8ebb 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs @@ -114,8 +114,10 @@ namespace Volo.Abp.Identity.EntityFrameworkCore public virtual async Task> GetUnaddedRolesAsync( OrganizationUnit organizationUnit, - string filter = null, string sorting = null, + int maxResultCount = int.MaxValue, + int skipCount = 0, + string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -126,6 +128,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .IncludeDetails(includeDetails) .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) .OrderBy(sorting ?? nameof(IdentityRole.Name)) + .PageBy(skipCount, maxResultCount) .ToListAsync(cancellationToken); } @@ -157,8 +160,10 @@ namespace Volo.Abp.Identity.EntityFrameworkCore public virtual async Task> GetUnaddedUsersAsync( OrganizationUnit organizationUnit, - string filter = null, string sorting = null, + int maxResultCount = int.MaxValue, + int skipCount = 0, + string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -181,6 +186,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return await query .IncludeDetails(includeDetails) .OrderBy(sorting ?? nameof(IdentityUser.Name)) + .PageBy(skipCount, maxResultCount) .ToListAsync(cancellationToken); } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs index 2823c99a6c..2b28a2e3a1 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs @@ -109,8 +109,10 @@ namespace Volo.Abp.Identity.MongoDB public async Task> GetUnaddedRolesAsync( OrganizationUnit organizationUnit, - string filter = null, string sorting = null, + int maxResultCount = int.MaxValue, + int skipCount = 0, + string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -120,6 +122,7 @@ namespace Volo.Abp.Identity.MongoDB .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) .OrderBy(sorting ?? nameof(IdentityRole.Name)) .As>() + .PageBy>(skipCount, maxResultCount) .ToListAsync(cancellationToken); } @@ -153,8 +156,10 @@ namespace Volo.Abp.Identity.MongoDB public async Task> GetUnaddedUsersAsync( OrganizationUnit organizationUnit, - string filter = null, string sorting = null, + int maxResultCount = int.MaxValue, + int skipCount = 0, + string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -169,6 +174,7 @@ namespace Volo.Abp.Identity.MongoDB ) .OrderBy(sorting ?? nameof(IdentityUser.UserName)) .As>() + .PageBy>(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } From 59a6c630be8f9de8cbadbe68f8c328fa55de37d8 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 8 Sep 2020 18:33:59 +0800 Subject: [PATCH 07/13] Add get count method --- .../Identity/IOrganizationUnitRepository.cs | 12 +++++++ .../EfCoreOrganizationUnitRepository.cs | 31 +++++++++++++++++++ .../MongoOrganizationUnitRepository.cs | 29 +++++++++++++++++ .../OrganizationUnitRepository_Tests.cs | 17 ++++++++++ 4 files changed, 89 insertions(+) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs index 4d5bf7d060..bf39874e00 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs @@ -65,6 +65,12 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default ); + Task GetUnaddedRolesCountAsync( + OrganizationUnit organizationUnit, + string filter = null, + CancellationToken cancellationToken = default + ); + Task> GetMembersAsync( OrganizationUnit organizationUnit, string sorting = null, @@ -91,6 +97,12 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default ); + Task GetUnaddedUsersCountAsync( + OrganizationUnit organizationUnit, + string filter = null, + CancellationToken cancellationToken = default + ); + Task RemoveAllRolesAsync( OrganizationUnit organizationUnit, CancellationToken cancellationToken = default diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs index ebfa9b8ebb..59fbd9518e 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs @@ -132,6 +132,19 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .ToListAsync(cancellationToken); } + public virtual async Task GetUnaddedRolesCountAsync( + OrganizationUnit organizationUnit, + string filter = null, + CancellationToken cancellationToken = default) + { + var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToList(); + + return await DbContext.Roles + .Where(r => !roleIds.Contains(r.Id)) + .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) + .CountAsync(cancellationToken); + } + public virtual async Task> GetMembersAsync( OrganizationUnit organizationUnit, string sorting = null, @@ -190,6 +203,24 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .ToListAsync(cancellationToken); } + public virtual async Task GetUnaddedUsersCountAsync( + OrganizationUnit organizationUnit, + string filter = null, + CancellationToken cancellationToken = default) + { + var userIdsInOrganizationUnit = DbContext.Set() + .Where(uou => uou.OrganizationUnitId == organizationUnit.Id) + .Select(uou => uou.UserId); + + return await DbContext.Users + .Where(u => !userIdsInOrganizationUnit.Contains(u.Id)) + .WhereIf(!filter.IsNullOrWhiteSpace(), u => + u.UserName.Contains(filter) || + u.Email.Contains(filter) || + (u.PhoneNumber != null && u.PhoneNumber.Contains(filter))) + .CountAsync(cancellationToken); + } + public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs index 2b28a2e3a1..10ae4cd038 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs @@ -126,6 +126,19 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(cancellationToken); } + public async Task GetUnaddedRolesCountAsync( + OrganizationUnit organizationUnit, + string filter = null, + CancellationToken cancellationToken = default) + { + var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray(); + return await DbContext.Roles.AsQueryable() + .Where(r => !roleIds.Contains(r.Id)) + .WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter)) + .As>() + .CountAsync(cancellationToken); + } + public virtual async Task> GetMembersAsync( OrganizationUnit organizationUnit, string sorting = null, @@ -178,6 +191,22 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } + public async Task GetUnaddedUsersCountAsync(OrganizationUnit organizationUnit, string filter = null, + CancellationToken cancellationToken = default) + { + return await DbContext.Users.AsQueryable() + .Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) + .WhereIf>( + !filter.IsNullOrWhiteSpace(), + u => + u.UserName.Contains(filter) || + u.Email.Contains(filter) || + (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) + ) + .As>() + .CountAsync(GetCancellationToken(cancellationToken)); + } + public virtual Task RemoveAllRolesAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) { organizationUnit.Roles.Clear(); diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs index 97544cd1e9..a671ba3284 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs @@ -305,5 +305,22 @@ namespace Volo.Abp.Identity unaddedRoles.ShouldNotContain(u => u.Name == "moderator"); unaddedRoles.ShouldContain(u => u.Name.Contains("admin")); } + + [Fact] + public async Task GetUnaddedUsersCountOfOrganizationUnitAsync() + { + var ou = await _organizationUnitRepository.GetAsync("OU111", true); + var count = await _organizationUnitRepository.GetUnaddedUsersCountAsync(ou); + count.ShouldBeGreaterThan(0); + + } + + [Fact] + public async Task GetUnaddedRolesCountOfOrganizationUnitAsync() + { + var ou = await _organizationUnitRepository.GetAsync("OU111", true); + var count = await _organizationUnitRepository.GetUnaddedRolesCountAsync(ou); + count.ShouldBeGreaterThan(0); + } } } From d43dc102c76e0f34d2ce2341e9774309ff004c01 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 8 Sep 2020 15:30:40 +0300 Subject: [PATCH 08/13] Update Default.cshtml --- .../Pages/CmsKit/Shared/Components/Commenting/Default.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml index ab7fc9805b..f988dd29e7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/Default.cshtml @@ -175,7 +175,7 @@ } - @if (comment.Replies.Count >= 5) + @if (comment.Replies.Count >= 3) {
@if (CurrentUser.IsAuthenticated) From cd91017415ab506d2cd0dafed9f047b4caa2ce38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Tue, 8 Sep 2020 17:31:32 +0300 Subject: [PATCH 09/13] Update AbpComponentDemoSectionTagHelper.cs --- .../Shared/TagHelpers/AbpComponentDemoSectionTagHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/TagHelpers/AbpComponentDemoSectionTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/TagHelpers/AbpComponentDemoSectionTagHelper.cs index 722460992d..1f1f71b066 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/TagHelpers/AbpComponentDemoSectionTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo/Views/Components/Themes/Shared/TagHelpers/AbpComponentDemoSectionTagHelper.cs @@ -47,7 +47,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Demo.Views.Components.Themes.S output.PreContent.AppendHtml($"

{Title}

"); output.PreContent.AppendHtml("
"); output.PreContent.AppendHtml("