Browse Source

Add `Extension Property Policy` feature.

pull/20281/head
maliming 2 years ago
parent
commit
991fe6dac5
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyDto.cs
  2. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyFeaturePolicyDto.cs
  3. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyGlobalFeaturePolicyDto.cs
  4. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyPermissionPolicyDto.cs
  5. 24
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyPolicyDto.cs
  6. 31
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/ui-extensions.js
  7. 19
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs
  8. 37
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/MvcExtensionPropertyPolicyChecker.cs
  9. 8
      framework/src/Volo.Abp.BlazoriseUI/AbpBlazoriseUIModule.cs
  10. 20
      framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs
  11. 37
      framework/src/Volo.Abp.BlazoriseUI/BlazoriseExtensionPropertyPolicyChecker.cs
  12. 2
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor
  13. 18
      framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor.cs
  14. 2
      framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj
  15. 8
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyFeaturePolicyConfiguration.cs
  16. 8
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyGlobalFeaturePolicyConfiguration.cs
  17. 8
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyPermissionPolicyConfiguration.cs
  18. 70
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyPolicyChecker.cs
  19. 17
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyPolicyConfiguration.cs
  20. 4
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs
  21. 1
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs
  22. 31
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs
  23. 5
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs
  24. 6
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs
  25. 6
      modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs
  26. 2
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml
  27. 2
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml
  28. 2
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml
  29. 2
      modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml
  30. 6
      modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs

4
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyDto.cs

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
@ -17,6 +16,8 @@ public class ExtensionPropertyDto
public ExtensionPropertyUiDto Ui { get; set; }
public ExtensionPropertyPolicyDto Policy { get; set; }
public List<ExtensionPropertyAttributeDto> Attributes { get; set; }
public Dictionary<string, object> Configuration { get; set; }
@ -27,6 +28,7 @@ public class ExtensionPropertyDto
{
Api = new ExtensionPropertyApiDto();
Ui = new ExtensionPropertyUiDto();
Policy = new ExtensionPropertyPolicyDto();
Attributes = new List<ExtensionPropertyAttributeDto>();
Configuration = new Dictionary<string, object>();
}

11
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyFeaturePolicyDto.cs

@ -0,0 +1,11 @@
using System;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
[Serializable]
public class ExtensionPropertyFeaturePolicyDto
{
public string[] Features { get; set; } = default!;
public bool RequiresAll { get; set; }
}

11
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyGlobalFeaturePolicyDto.cs

@ -0,0 +1,11 @@
using System;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
[Serializable]
public class ExtensionPropertyGlobalFeaturePolicyDto
{
public string[] Features { get; set; } = default!;
public bool RequiresAll { get; set; } = default!;
}

11
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyPermissionPolicyDto.cs

@ -0,0 +1,11 @@
using System;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
[Serializable]
public class ExtensionPropertyPermissionPolicyDto
{
public string[] PermissionNames { get; set; } = default!;
public bool RequiresAll { get; set; }
}

24
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ExtensionPropertyPolicyDto.cs

@ -0,0 +1,24 @@
using System;
using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
[Serializable]
public class ExtensionPropertyPolicyDto
{
[NotNull]
public ExtensionPropertyGlobalFeaturePolicyDto GlobalFeatures { get; set; }
[NotNull]
public ExtensionPropertyFeaturePolicyDto Features { get; set; }
[NotNull]
public ExtensionPropertyPermissionPolicyDto Permissions { get; set; }
public ExtensionPropertyPolicyDto()
{
GlobalFeatures = new ExtensionPropertyGlobalFeaturePolicyDto();
Features = new ExtensionPropertyFeaturePolicyDto();
Permissions = new ExtensionPropertyPermissionPolicyDto();
}
}

31
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/ui-extensions.js

@ -187,6 +187,14 @@ var abp = abp || {};
for (var i = 0; i < propertyNames.length; i++) {
var propertyName = propertyNames[i];
var propertyConfig = objectConfig.properties[propertyName];
var policy = propertyConfig.policy;
if (!checkPolicy(policy.globalFeatures.features, policy.globalFeatures.requiresAll, abp.features.isEnabled) ||
!checkPolicy(policy.features.features, policy.features.requiresAll, abp.features.isEnabled) ||
!checkPolicy(policy.permissions.permissionNames, policy.permissions.requiresAll, abp.auth.isGranted)) {
continue;
}
if (propertyConfig.ui.onTable.isVisible) {
if (propertyName.endsWith("_Text")) {
var lookupPropertyName = propertyName.replace("_Text", "");
@ -216,6 +224,29 @@ var abp = abp || {};
return tableProperties;
}
function checkPolicy(names, requiresAll, checkFunc) {
if (names.length === 0) {
return true;
}
var hasAny = false;
for (var i = 0; i < names.length; i++) {
if (!checkFunc(names[i])) {
if (requiresAll) {
return false;
}
}
else {
hasAny = true;
if (!requiresAll) {
break;
}
}
}
return hasAny;
}
function getValueFromRow(property, row) {
return row.extraProperties[property.name];
}

19
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs

@ -142,6 +142,24 @@ public class CachedObjectExtensionsDtoService : ICachedObjectExtensionsDtoServic
{
IsVisible = propertyConfig.UI.OnTable.IsVisible
}
},
Policy = new ExtensionPropertyPolicyDto
{
GlobalFeatures = new ExtensionPropertyGlobalFeaturePolicyDto
{
Features = propertyConfig.Policy.Features.Features,
RequiresAll = propertyConfig.Policy.Features.RequiresAll
},
Features = new ExtensionPropertyFeaturePolicyDto
{
Features = propertyConfig.Policy.Features.Features,
RequiresAll = propertyConfig.Policy.Features.RequiresAll
},
Permissions = new ExtensionPropertyPermissionPolicyDto
{
PermissionNames = propertyConfig.Policy.Permissions.PermissionNames,
RequiresAll = propertyConfig.Policy.Permissions.RequiresAll
}
}
};
@ -157,7 +175,6 @@ public class CachedObjectExtensionsDtoService : ICachedObjectExtensionsDtoServic
};
}
foreach (var attribute in propertyConfig.Attributes)
{
extensionPropertyDto.Attributes.Add(

37
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/ObjectExtending/MvcExtensionPropertyPolicyChecker.cs

@ -0,0 +1,37 @@
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
using Volo.Abp.GlobalFeatures;
namespace Volo.Abp.ObjectExtending;
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(ExtensionPropertyPolicyChecker))]
public class MvcExtensionPropertyPolicyChecker : ExtensionPropertyPolicyChecker
{
protected IFeatureChecker FeatureChecker { get; }
protected IPermissionChecker PermissionChecker { get; }
public MvcExtensionPropertyPolicyChecker(IFeatureChecker featureChecker, IPermissionChecker permissionChecker)
{
FeatureChecker = featureChecker;
PermissionChecker = permissionChecker;
}
protected override Task<bool> CheckGlobalFeaturesAsync(string featureName)
{
return Task.FromResult<bool>(GlobalFeatureManager.Instance.IsEnabled(featureName));
}
protected async override Task<bool> CheckFeaturesAsync(string featureName)
{
return await FeatureChecker.IsEnabledAsync(featureName);
}
protected async override Task<bool> CheckPermissionsAsync(string permissionName)
{
return await PermissionChecker.IsGrantedAsync(permissionName);
}
}

8
framework/src/Volo.Abp.BlazoriseUI/AbpBlazoriseUIModule.cs

@ -5,6 +5,8 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Application;
using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.Authorization;
using Volo.Abp.Features;
using Volo.Abp.GlobalFeatures;
using Volo.Abp.Modularity;
namespace Volo.Abp.BlazoriseUI;
@ -12,7 +14,9 @@ namespace Volo.Abp.BlazoriseUI;
[DependsOn(
typeof(AbpAspNetCoreComponentsWebModule),
typeof(AbpDddApplicationContractsModule),
typeof(AbpAuthorizationModule)
typeof(AbpAuthorizationModule),
typeof(AbpGlobalFeaturesModule),
typeof(AbpFeaturesModule)
)]
public class AbpBlazoriseUIModule : AbpModule
{
@ -32,4 +36,4 @@ public class AbpBlazoriseUIModule : AbpModule
context.Services.Replace(ServiceDescriptor.Scoped<IComponentActivator, ComponentActivator>());
context.Services.AddSingleton(typeof(AbpBlazorMessageLocalizerHelper<>));
}
}
}

20
framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs

@ -177,7 +177,7 @@ public abstract class AbpCrudPageBase<
[Inject] protected TAppService AppService { get; set; } = default!;
[Inject] protected IStringLocalizer<AbpUiResource> UiLocalizer { get; set; } = default!;
[Inject] public IAbpEnumLocalizer AbpEnumLocalizer { get; set; } = default!;
[Inject]protected ExtensionPropertyPolicyChecker ExtensionPropertyPolicyChecker { get; set; } = default!;
protected virtual int PageSize { get; } = LimitedResultRequestDto.DefaultMaxResultCount;
protected int CurrentPage = 1;
@ -642,23 +642,29 @@ public abstract class AbpCrudPageBase<
return ValueTask.CompletedTask;
}
protected virtual IEnumerable<TableColumn> GetExtensionTableColumns(string moduleName, string entityType)
protected virtual async Task<List<TableColumn>> GetExtensionTableColumnsAsync(string moduleName, string entityType)
{
var properties = ModuleExtensionConfigurationHelper.GetPropertyConfigurations(moduleName, entityType);
var tableColumns = new List<TableColumn>();
var properties = ModuleExtensionConfigurationHelper.GetPropertyConfigurations(moduleName, entityType).ToList();
foreach (var propertyInfo in properties)
{
if (!await ExtensionPropertyPolicyChecker.CheckPolicyAsync(propertyInfo.Policy))
{
continue;
}
if (propertyInfo.IsAvailableToClients && propertyInfo.UI.OnTable.IsVisible)
{
if (propertyInfo.Name.EndsWith("_Text"))
{
var lookupPropertyName = propertyInfo.Name.RemovePostFix("_Text");
var lookupPropertyDefinition = properties.SingleOrDefault(t => t.Name == lookupPropertyName)!;
yield return new TableColumn
tableColumns.Add(new TableColumn
{
Title = lookupPropertyDefinition.GetLocalizedDisplayName(StringLocalizerFactory),
Data = $"ExtraProperties[{propertyInfo.Name}]",
PropertyName = propertyInfo.Name
};
});
}
else
{
@ -680,9 +686,11 @@ public abstract class AbpCrudPageBase<
AbpEnumLocalizer.GetString(propertyInfo.Type, val.As<ExtensibleObject>().ExtraProperties[propertyInfo.Name]!, new IStringLocalizer?[]{ StringLocalizerFactory.CreateDefaultOrNull() });
}
yield return column;
tableColumns.Add(column);
}
}
}
return tableColumns;
}
}

37
framework/src/Volo.Abp.BlazoriseUI/BlazoriseExtensionPropertyPolicyChecker.cs

@ -0,0 +1,37 @@
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
using Volo.Abp.GlobalFeatures;
using Volo.Abp.ObjectExtending;
namespace Volo.Abp.BlazoriseUI;
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(ExtensionPropertyPolicyChecker))]
public class BlazoriseExtensionPropertyPolicyChecker : ExtensionPropertyPolicyChecker
{
protected IFeatureChecker FeatureChecker { get; }
protected IPermissionChecker PermissionChecker { get; }
public BlazoriseExtensionPropertyPolicyChecker(IFeatureChecker featureChecker, IPermissionChecker permissionChecker)
{
FeatureChecker = featureChecker;
PermissionChecker = permissionChecker;
}
protected override Task<bool> CheckGlobalFeaturesAsync(string featureName)
{
return Task.FromResult<bool>(GlobalFeatureManager.Instance.IsEnabled(featureName));
}
protected async override Task<bool> CheckFeaturesAsync(string featureName)
{
return await FeatureChecker.IsEnabledAsync(featureName);
}
protected async override Task<bool> CheckPermissionsAsync(string permissionName)
{
return await PermissionChecker.IsGrantedAsync(permissionName);
}
}

2
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor

@ -6,7 +6,7 @@
@{
Entity.SetDefaultsForExtraProperties();
foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<TEntityType>())
foreach (var propertyInfo in Properties)
{
if (!propertyInfo.Name.EndsWith("_Text"))
{

18
framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/ExtensionProperties.razor.cs

@ -1,4 +1,8 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Volo.Abp.AspNetCore.Components.Web;
using Volo.Abp.Data;
@ -17,7 +21,17 @@ public partial class ExtensionProperties<TEntityType, TResourceType> : Component
[Parameter]
public TEntityType Entity { get; set; } = default!;
[Inject]
public IServiceProvider ServiceProvider { get; set; } = default!;
[Parameter]
public ExtensionPropertyModalType? ModalType { get; set; }
public ImmutableList<ObjectExtensionPropertyInfo> Properties { get; set; } = ImmutableList<ObjectExtensionPropertyInfo>.Empty;
protected async override Task OnInitializedAsync()
{
Properties = await ObjectExtensionManager.Instance.GetPropertiesAndCheckPolicyAsync<TEntityType>(ServiceProvider);
}
}

2
framework/src/Volo.Abp.BlazoriseUI/Volo.Abp.BlazoriseUI.csproj

@ -13,6 +13,8 @@
<ProjectReference Include="..\Volo.Abp.AspNetCore.Components.Web\Volo.Abp.AspNetCore.Components.Web.csproj" />
<ProjectReference Include="..\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" />
<ProjectReference Include="..\Volo.Abp.Ddd.Application.Contracts\Volo.Abp.Ddd.Application.Contracts.csproj" />
<ProjectReference Include="..\Volo.Abp.Features\Volo.Abp.Features.csproj" />
<ProjectReference Include="..\Volo.Abp.GlobalFeatures\Volo.Abp.GlobalFeatures.csproj" />
</ItemGroup>
<ItemGroup>

8
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyFeaturePolicyConfiguration.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.ObjectExtending;
public class ExtensionPropertyFeaturePolicyConfiguration
{
public string[] Features { get; set; } = [];
public bool RequiresAll { get; set; } = default!;
}

8
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyGlobalFeaturePolicyConfiguration.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.ObjectExtending;
public class ExtensionPropertyGlobalFeaturePolicyConfiguration
{
public string[] Features { get; set; } = [];
public bool RequiresAll { get; set; } = default!;
}

8
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyPermissionPolicyConfiguration.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.ObjectExtending;
public class ExtensionPropertyPermissionPolicyConfiguration
{
public string[] PermissionNames { get; set; } = [];
public bool RequiresAll { get; set; } = default!;
}

70
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyPolicyChecker.cs

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.ObjectExtending;
public class ExtensionPropertyPolicyChecker : ITransientDependency
{
public virtual async Task<bool> CheckPolicyAsync([NotNull] ExtensionPropertyPolicyConfiguration policy)
{
if (!await CheckAsync(policy.GlobalFeatures.Features, policy.GlobalFeatures.RequiresAll, CheckGlobalFeaturesAsync))
{
return false;
}
if (!await CheckAsync(policy.Features.Features, policy.Features.RequiresAll, CheckFeaturesAsync))
{
return false;
}
return await CheckAsync(policy.Permissions.PermissionNames, policy.Permissions.RequiresAll, CheckPermissionsAsync);
}
protected virtual async Task<bool> CheckAsync(string[] names, bool requiresAll, Func<string, Task<bool>> checkFunc)
{
if (names.IsNullOrEmpty())
{
return true;
}
var hasAny = false;
foreach (var name in names)
{
if (!await checkFunc(name))
{
if (requiresAll)
{
return false;
}
}
else
{
hasAny = true;
if (!requiresAll)
{
break;
}
}
}
return hasAny;
}
protected virtual Task<bool> CheckGlobalFeaturesAsync(string featureName)
{
return Task.FromResult(true);
}
protected virtual Task<bool> CheckFeaturesAsync(string featureName)
{
return Task.FromResult(true);
}
protected virtual Task<bool> CheckPermissionsAsync(string permissionName)
{
return Task.FromResult(true);
}
}

17
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ExtensionPropertyPolicyConfiguration.cs

@ -0,0 +1,17 @@
namespace Volo.Abp.ObjectExtending;
public class ExtensionPropertyPolicyConfiguration
{
public ExtensionPropertyGlobalFeaturePolicyConfiguration GlobalFeatures { get; set; }
public ExtensionPropertyFeaturePolicyConfiguration Features { get; set; }
public ExtensionPropertyPermissionPolicyConfiguration Permissions { get; set; }
public ExtensionPropertyPolicyConfiguration()
{
GlobalFeatures = new ExtensionPropertyGlobalFeaturePolicyConfiguration();
Features = new ExtensionPropertyFeaturePolicyConfiguration();
Permissions = new ExtensionPropertyPermissionPolicyConfiguration();
}
}

4
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ExtensionPropertyConfiguration.cs

@ -45,6 +45,9 @@ public class ExtensionPropertyConfiguration : IHasNameWithLocalizableDisplayName
[NotNull]
public ExtensionPropertyApiConfiguration Api { get; }
[NotNull]
public ExtensionPropertyPolicyConfiguration Policy { get; }
/// <summary>
/// Uses as the default value if <see cref="DefaultValueFactory"/> was not set.
/// </summary>
@ -72,6 +75,7 @@ public class ExtensionPropertyConfiguration : IHasNameWithLocalizableDisplayName
Entity = new ExtensionPropertyEntityConfiguration();
UI = new ExtensionPropertyUiConfiguration();
Api = new ExtensionPropertyApiConfiguration();
Policy = new ExtensionPropertyPolicyConfiguration();
Attributes.AddRange(ExtensionPropertyHelper.GetDefaultAttributes(Type));
DefaultValue = TypeHelper.GetDefaultValue(Type);

1
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/Modularity/ModuleExtensionConfigurationHelper.cs

@ -175,6 +175,7 @@ public static class ModuleExtensionConfigurationHelper
property.DefaultValueFactory = propertyConfig.DefaultValueFactory;
property.Lookup = propertyConfig.UI.Lookup;
property.UI.Order = propertyConfig.UI.Order;
property.Policy = propertyConfig.Policy;
foreach (var configuration in propertyConfig.Configuration)
{
property.Configuration[configuration.Key] = configuration.Value;

31
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionManagerExtensions.cs

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Data;
namespace Volo.Abp.ObjectExtending;
@ -130,4 +132,33 @@ public static class ObjectExtensionManagerExtensions
return extensionInfo.GetProperties();
}
public static Task<ImmutableList<ObjectExtensionPropertyInfo>> GetPropertiesAndCheckPolicyAsync<TObject>(
[NotNull] this ObjectExtensionManager objectExtensionManager,
[NotNull] IServiceProvider serviceProvider)
{
return objectExtensionManager.GetPropertiesAndCheckPolicyAsync(typeof(TObject), serviceProvider);
}
public async static Task<ImmutableList<ObjectExtensionPropertyInfo>> GetPropertiesAndCheckPolicyAsync(
[NotNull] this ObjectExtensionManager objectExtensionManager,
[NotNull] Type objectType,
[NotNull] IServiceProvider serviceProvider)
{
Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
Check.NotNull(objectType, nameof(objectType));
Check.NotNull(serviceProvider, nameof(serviceProvider));
var extensionPropertyPolicyConfigurationChecker = serviceProvider.GetRequiredService<ExtensionPropertyPolicyChecker>();
var properties = new List<ObjectExtensionPropertyInfo>();
foreach (var propertyInfo in objectExtensionManager.GetProperties(objectType))
{
if (await extensionPropertyPolicyConfigurationChecker.CheckPolicyAsync(propertyInfo.Policy))
{
properties.Add(propertyInfo);
}
}
return properties.ToImmutableList();
}
}

5
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ObjectExtensionPropertyInfo.cs

@ -59,6 +59,8 @@ public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName, I
public ExtensionPropertyUI UI { get; set; }
public ExtensionPropertyPolicyConfiguration Policy { get; set; }
public ObjectExtensionPropertyInfo(
[NotNull] ObjectExtensionInfo objectExtension,
[NotNull] Type type,
@ -76,6 +78,7 @@ public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName, I
DefaultValue = TypeHelper.GetDefaultValue(Type);
Lookup = new ExtensionPropertyLookupConfiguration();
UI = new ExtensionPropertyUI();
Policy = new ExtensionPropertyPolicyConfiguration();
}
public object? GetDefaultValue()
@ -86,7 +89,7 @@ public class ObjectExtensionPropertyInfo : IHasNameWithLocalizableDisplayName, I
public class ExtensionPropertyUI
{
public int Order { get; set; }
public ExtensionPropertyUIEditModal EditModal { get; set; }
public ExtensionPropertyUI()

6
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/RoleManagement.razor.cs

@ -80,7 +80,7 @@ public partial class RoleManagement
return base.SetEntityActionsAsync();
}
protected override ValueTask SetTableColumnsAsync()
protected override async ValueTask SetTableColumnsAsync()
{
RoleManagementTableColumns
.AddRange(new TableColumn[]
@ -99,10 +99,10 @@ public partial class RoleManagement
},
});
RoleManagementTableColumns.AddRange(GetExtensionTableColumns(IdentityModuleExtensionConsts.ModuleName,
RoleManagementTableColumns.AddRange(await GetExtensionTableColumnsAsync(IdentityModuleExtensionConsts.ModuleName,
IdentityModuleExtensionConsts.EntityNames.Role));
return base.SetTableColumnsAsync();
await base.SetTableColumnsAsync();
}
protected override async Task SetPermissionsAsync()

6
modules/identity/src/Volo.Abp.Identity.Blazor/Pages/Identity/UserManagement.razor.cs

@ -197,7 +197,7 @@ public partial class UserManagement
return base.SetEntityActionsAsync();
}
protected override ValueTask SetTableColumnsAsync()
protected override async ValueTask SetTableColumnsAsync()
{
UserManagementTableColumns
.AddRange(new TableColumn[]
@ -227,9 +227,9 @@ public partial class UserManagement
}
});
UserManagementTableColumns.AddRange(GetExtensionTableColumns(IdentityModuleExtensionConsts.ModuleName,
UserManagementTableColumns.AddRange(await GetExtensionTableColumnsAsync(IdentityModuleExtensionConsts.ModuleName,
IdentityModuleExtensionConsts.EntityNames.User));
return base.SetTableColumnsAsync();
await base.SetTableColumnsAsync();
}
protected override ValueTask SetToolbarItemsAsync()

2
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/CreateModal.cshtml

@ -24,7 +24,7 @@
<abp-input asp-for="Role.IsPublic" />
@foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<CreateModalModel.RoleInfoModel>())
@foreach (var propertyInfo in await ObjectExtensionManager.Instance.GetPropertiesAndCheckPolicyAsync<CreateModalModel.RoleInfoModel>(HttpContext.RequestServices))
{
if (!propertyInfo.Name.EndsWith("_Text"))
{

2
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Roles/EditModal.cshtml

@ -34,7 +34,7 @@
<abp-input asp-for="Role.IsPublic" />
@foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<CreateModalModel.RoleInfoModel>())
@foreach (var propertyInfo in await ObjectExtensionManager.Instance.GetPropertiesAndCheckPolicyAsync<CreateModalModel.RoleInfoModel>(HttpContext.RequestServices))
{
if (!propertyInfo.Name.EndsWith("_Text"))
{

2
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/CreateModal.cshtml

@ -39,7 +39,7 @@
<abp-input asp-for="UserInfo.IsActive" />
<abp-input asp-for="UserInfo.LockoutEnabled" />
@foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<CreateModalModel.UserInfoViewModel>())
@foreach (var propertyInfo in await ObjectExtensionManager.Instance.GetPropertiesAndCheckPolicyAsync<CreateModalModel.UserInfoViewModel>(HttpContext.RequestServices))
{
if (!propertyInfo.Name.EndsWith("_Text"))
{

2
modules/identity/src/Volo.Abp.Identity.Web/Pages/Identity/Users/EditModal.cshtml

@ -43,7 +43,7 @@
{
<abp-input asp-for="UserInfo.LockoutEnabled" />
}
@foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<EditModalModel.UserInfoViewModel>())
@foreach (var propertyInfo in await ObjectExtensionManager.Instance.GetPropertiesAndCheckPolicyAsync<EditModalModel.UserInfoViewModel>(HttpContext.RequestServices))
{
if (!propertyInfo.Name.EndsWith("_Text"))
{

6
modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor.cs

@ -102,7 +102,7 @@ public partial class TenantManagement
return base.SetEntityActionsAsync();
}
protected override ValueTask SetTableColumnsAsync()
protected override async ValueTask SetTableColumnsAsync()
{
TenantManagementTableColumns
.AddRange(new TableColumn[]
@ -120,11 +120,11 @@ public partial class TenantManagement
},
});
TenantManagementTableColumns.AddRange(GetExtensionTableColumns(
TenantManagementTableColumns.AddRange(await GetExtensionTableColumnsAsync(
TenantManagementModuleExtensionConsts.ModuleName,
TenantManagementModuleExtensionConsts.EntityNames.Tenant));
return base.SetTableColumnsAsync();
await base.SetTableColumnsAsync();
}
protected virtual void TogglePasswordVisibility()

Loading…
Cancel
Save