From 3e578479fb345263690c0628551e794e7eca67fd Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 22 Sep 2022 17:38:56 +0300 Subject: [PATCH 1/3] Implement conditional editing for PersonalInfo page --- .../PersonalInfo/Default.cshtml | 52 +++++++++++-------- .../IdentityModuleExtensionConsts.cs | 5 ++ 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml index b9b0783ab9..7df1715b2b 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml @@ -28,28 +28,36 @@ StringComparison.OrdinalIgnoreCase); } -

@L["PersonalSettings"]


+

@L["PersonalSettings"]

+
- + - + - + - + - + - + @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { + var isAllowed = propertyInfo.Configuration.GetOrDefault("AllowUserToEdit"); + + if(isAllowed == null || !isAllowed.Equals(true)) + { + continue; + } + if (!propertyInfo.Name.EndsWith("_Text")) { if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty()) @@ -59,28 +67,28 @@ Model.ExtraProperties.ToEnum(propertyInfo.Name, propertyInfo.Type); } + name="ExtraProperties.@propertyInfo.Name" + label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)" + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-selected-item-name="@Model.GetProperty(propertyInfo.Name + "_Text")" + autocomplete-selected-item-value="@Model.GetProperty(propertyInfo.Name)" + autocomplete-filter-param-name="@propertyInfo.Lookup.FilterParamName" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { + asp-for="ExtraProperties[propertyInfo.Name]" + name="ExtraProperties.@propertyInfo.Name" + label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)" + asp-format="@propertyInfo.GetInputFormatOrNull()" + value="@propertyInfo.GetInputValueOrNull(Model.GetProperty(propertyInfo.Name))" /> } } } - + \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs index a9a150aa6d..5135cf22b8 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/ObjectExtending/IdentityModuleExtensionConsts.cs @@ -14,4 +14,9 @@ public static class IdentityModuleExtensionConsts public const string OrganizationUnit = "OrganizationUnit"; } + + public static class ConfigurationNames + { + public const string AllowUserToEdit = "AllowUserToEdit"; + } } From 3dae44999641c2df83e2a5ee931a69903c6c1a53 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 22 Sep 2022 17:41:39 +0300 Subject: [PATCH 2/3] Update MyProjectNameModuleExtensionConfigurator.cs --- ...yProjectNameModuleExtensionConfigurator.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameModuleExtensionConfigurator.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameModuleExtensionConfigurator.cs index 2a6eddf60f..904874cc23 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameModuleExtensionConfigurator.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain.Shared/MyProjectNameModuleExtensionConfigurator.cs @@ -37,6 +37,26 @@ public static class MyProjectNameModuleExtensionConfigurator private static void ConfigureExtraProperties() { + ObjectExtensionManager.Instance.Modules() + .ConfigureIdentity(identity => + { + identity.ConfigureUser(user => + { + user.AddOrUpdateProperty( //property type: string + "SocialSecurityNumber", //property name + property => + { + //validation rules + property.Attributes.Add(new RequiredAttribute()); + property.Attributes.Add(new StringLengthAttribute(64) {MinimumLength = 4}); + + //...other configurations for this property + // property.Configuration[IdentityModuleExtensionConsts.ConfigurationNames.AllowUserToEdit] = true; + } + ); + }); + }); + /* You can configure extra properties for the * entities defined in the modules used by your application. * @@ -57,6 +77,8 @@ public static class MyProjectNameModuleExtensionConfigurator //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 } From 905a8e06824af4c0469d36254982a38976fbb458 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 22 Sep 2022 17:43:59 +0300 Subject: [PATCH 3/3] Fix formatting --- .../PersonalInfo/Default.cshtml | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml index 7df1715b2b..025aa11142 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.cshtml @@ -51,9 +51,9 @@ @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties()) { - var isAllowed = propertyInfo.Configuration.GetOrDefault("AllowUserToEdit"); + var isAllowed = propertyInfo.Configuration.GetOrDefault(IdentityModuleExtensionConsts.ConfigurationNames.AllowUserToEdit); - if(isAllowed == null || !isAllowed.Equals(true)) + if (isAllowed == null || !isAllowed.Equals(true)) { continue; } @@ -67,25 +67,25 @@ Model.ExtraProperties.ToEnum(propertyInfo.Name, propertyInfo.Type); } + name="ExtraProperties.@propertyInfo.Name" + label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)" + autocomplete-api-url="@propertyInfo.Lookup.Url" + autocomplete-selected-item-name="@Model.GetProperty(propertyInfo.Name + "_Text")" + autocomplete-selected-item-value="@Model.GetProperty(propertyInfo.Name)" + autocomplete-filter-param-name="@propertyInfo.Lookup.FilterParamName" + autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName" + autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName" + autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"> } else { + asp-for="ExtraProperties[propertyInfo.Name]" + name="ExtraProperties.@propertyInfo.Name" + label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)" + asp-format="@propertyInfo.GetInputFormatOrNull()" + value="@propertyInfo.GetInputValueOrNull(Model.GetProperty(propertyInfo.Name))" /> } } }