Skip to content

Commit

Permalink
Add ExtensionPropertyPolicy test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
maliming committed Jul 25, 2024
1 parent 991fe6d commit 64126e8
Show file tree
Hide file tree
Showing 5 changed files with 2,097 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectExtending.Modularity;
using Volo.Abp.Threading;

namespace MyCompanyName.MyProjectName;
Expand Down Expand Up @@ -37,6 +38,44 @@ private static void ConfigureExistingProperties()

private static void ConfigureExtraProperties()
{

ObjectExtensionManager.Instance.Modules()
.ConfigureIdentity(identity =>
{
identity.ConfigureUser(user =>
{
user.AddOrUpdateProperty<string>( //property type: string
"SocialSecurityNumber", //property name
property =>
{
//validation rules
property.Attributes.Add(new RequiredAttribute());
property.Attributes.Add(new StringLengthAttribute(128) {MinimumLength = 3});
// property.Policy.GlobalFeatures = new ExtensionPropertyGlobalFeaturePolicyConfiguration()
// {
// Features = new[] {"abc", "def"},
// RequiresAll = true
// };
// property.Policy.Features = new ExtensionPropertyFeaturePolicyConfiguration()
// {
// Features = new[] {"abc", "def"},
// RequiresAll = false
// };
property.Policy.Permissions = new ExtensionPropertyPermissionPolicyConfiguration()
{
PermissionNames = new[] {"AbpTenantManagement.Tenants.Update", "AbpTenantManagement.Tenants.Delete"},
RequiresAll = false
};
//...other configurations for this property
}
);
});
});

/* You can configure extra properties for the
* entities defined in the modules used by your application.
*
Expand All @@ -57,7 +96,7 @@ private static void ConfigureExtraProperties()
//validation rules
property.Attributes.Add(new RequiredAttribute());
property.Attributes.Add(new StringLengthAttribute(64) {MinimumLength = 4});
property.Configuration[IdentityModuleExtensionConsts.ConfigurationNames.AllowUserToEdit] = true;
//...other configurations for this property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public static void Configure()
* See the documentation for more:
* https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities
*/
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, string>(
"SocialSecurityNumber",
(entityBuilder, propertyBuilder) =>
{
propertyBuilder.HasMaxLength(128);
}
);
});
}
}
Loading

0 comments on commit 64126e8

Please sign in to comment.