From ca452942ea3603f7627a3e9dc3d991a4f6e56b68 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Fri, 25 Aug 2023 13:43:35 +0200 Subject: [PATCH 01/42] User Accounts Deployment --- .../Deployment/AllUsersDeploymentSource.cs | 68 +++++++++++++++ .../Deployment/AllUsersDeploymentStep.cs | 15 ++++ .../AllUsersDeploymentStepDriver.cs | 23 +++++ .../OrchardCore.Users/Recipes/UsersStep.cs | 86 +++++++++++++++++++ .../OrchardCore.Users/Startup.cs | 14 +++ .../Items/AllUsersDeploymentStep.Edit.cshtml | 3 + .../AllUsersDeploymentStep.Summary.cshtml | 5 ++ .../AllUsersDeploymentStep.Thumbnail.cshtml | 4 + .../Views/_ViewImports.cshtml | 1 + 9 files changed, 219 insertions(+) create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Edit.cshtml create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Summary.cshtml create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs new file mode 100644 index 00000000000..eb7b310f3d6 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using OrchardCore.Deployment; +using OrchardCore.Users.Models; +using OrchardCore.Users.Recipes; +using YesSql; + +namespace OrchardCore.Users.Deployment +{ + public class AllUsersDeploymentSource : IDeploymentSource + { + private readonly ISession _session; + + public AllUsersDeploymentSource(ISession session) + { + _session = session; + } + + public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) + { + var allRolesStep = step as AllUsersDeploymentStep; + + if (allRolesStep == null) + { + return; + } + + // todo: Get all users + var allUsers = await _session.Query().ListAsync(); ; + var users = new JArray(); + var tasks = new List(); + + foreach (var user in allUsers) + { + /* + var currentRole = (Role)await _roleManager.FindByNameAsync(_roleManager.NormalizeKey(role.RoleName)); + + if (currentRole != null) + { + */ + users.Add(JObject.FromObject( + new UsersStepUserModel + { + UserName = user.UserName, + UserId = user.UserId, + Email = user.Email, + Id = user.Id, + EmailConfirmed = user.EmailConfirmed, + PasswordHash = user.PasswordHash, + IsEnabled = user.IsEnabled, + NormalizedEmail = user.NormalizedEmail, + NormalizedUserName = user.NormalizedUserName, + SecurityStamp = user.SecurityStamp, + ResetToken = user.ResetToken + //Permissions = currentRole.RoleClaims.Where(x => x.ClaimType == Permission.ClaimType).Select(x => x.ClaimValue).ToArray() + })); + + //} + } + + result.Steps.Add(new JObject( + new JProperty("name", "Users"), + new JProperty("Users", users) + )); + } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs new file mode 100644 index 00000000000..f8d63009a24 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs @@ -0,0 +1,15 @@ +using OrchardCore.Deployment; + +namespace OrchardCore.Users.Deployment +{ + /// + /// Adds users to a . + /// + public class AllUsersDeploymentStep : DeploymentStep + { + public AllUsersDeploymentStep() + { + Name = "AllUsers"; + } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs new file mode 100644 index 00000000000..fdc5a07c137 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs @@ -0,0 +1,23 @@ +using OrchardCore.Deployment; +using OrchardCore.DisplayManagement.Handlers; +using OrchardCore.DisplayManagement.Views; + +namespace OrchardCore.Users.Deployment +{ + public class AllUsersDeploymentStepDriver : DisplayDriver + { + public override IDisplayResult Display(AllUsersDeploymentStep step) + { + return + Combine( + View("AllUsersDeploymentStep_Summary", step).Location("Summary", "Content"), + View("AllUsersDeploymentStep_Thumbnail", step).Location("Thumbnail", "Content") + ); + } + + public override IDisplayResult Edit(AllUsersDeploymentStep step) + { + return View("AllUsersDeploymentStep_Edit", step).Location("Content"); + } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs new file mode 100644 index 00000000000..a9fe54e1b6b --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -0,0 +1,86 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Identity; +using OrchardCore.Recipes.Models; +using OrchardCore.Recipes.Services; +using OrchardCore.Users.Models; +using OrchardCore.Users.Services; +using YesSql; + +namespace OrchardCore.Users.Recipes +{ + public class UsersStep : IRecipeStepHandler { + private readonly UserManager _userManager; + private readonly IUserService _userService; + private ISession _session; + public UsersStep(UserManager userManager, IUserService userService, ISession session) + { + _userManager = userManager; + _userService = userService; + _session = session; + } + + public async Task ExecuteAsync(RecipeExecutionContext context) { + + if (!String.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) { + return; + } + + var model = context.Step.ToObject(); + + foreach (var importedUser in model.Users) { + if (String.IsNullOrWhiteSpace(importedUser.UserName)) + continue; + + var iUser = await _userManager.FindByIdAsync(importedUser.UserId); + User user; + var isNewUser = iUser == null; + + if (isNewUser) { + user = new User { UserId = importedUser.UserId }; + } else { + user = iUser as User; + } + + user.Email = importedUser.Email; + user.UserName = importedUser.UserName; + //user.Id = importedUser.Id; // This is problematic because it's an identity column + user.EmailConfirmed = importedUser.EmailConfirmed; + user.PasswordHash = importedUser.PasswordHash; + user.IsEnabled = importedUser.IsEnabled; + user.NormalizedEmail = importedUser.NormalizedEmail; + user.NormalizedUserName = importedUser.NormalizedUserName; + user.SecurityStamp = importedUser.SecurityStamp; + user.ResetToken = importedUser.ResetToken; + + if (isNewUser) { + _session.Save(user); + } else { + _session.Save(user); + } + } + } + + public class UsersStepModel { + public UsersStepUserModel[] Users { get; set; } + } + } + + public class UsersStepUserModel { + + public long Id { get; set; } + + public string UserId { get; set; } + + public string UserName { get; set; } + + public string Email { get; set; } + public string PasswordHash { get; set; } + public bool EmailConfirmed { get; set; } + public bool IsEnabled { get; set; } = true; + public string NormalizedEmail { get; set; } + public string NormalizedUserName { get; set; } + public string SecurityStamp { get; set; } + public string ResetToken { get; set; } + } +} \ No newline at end of file diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs index 7f6ae81d9b5..e44537fae82 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs @@ -16,6 +16,7 @@ using OrchardCore.Admin; using OrchardCore.Data; using OrchardCore.Data.Migration; +using OrchardCore.Deployment; using OrchardCore.DisplayManagement.Handlers; using OrchardCore.DisplayManagement.Theming; using OrchardCore.Environment.Commands; @@ -26,6 +27,7 @@ using OrchardCore.Modules; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Navigation; +using OrchardCore.Recipes; using OrchardCore.Recipes.Services; using OrchardCore.ResourceManagement; using OrchardCore.Security; @@ -36,11 +38,13 @@ using OrchardCore.Sms; using OrchardCore.Users.Commands; using OrchardCore.Users.Controllers; +using OrchardCore.Users.Deployment; using OrchardCore.Users.Drivers; using OrchardCore.Users.Handlers; using OrchardCore.Users.Indexes; using OrchardCore.Users.Liquid; using OrchardCore.Users.Models; +using OrchardCore.Users.Recipes; using OrchardCore.Users.Services; using OrchardCore.Users.ViewModels; using YesSql.Filters.Query; @@ -244,6 +248,8 @@ public override void ConfigureServices(IServiceCollection services) services.AddTransient(); services.AddTransient, UserOptionsConfiguration>(); + + services.AddRecipeExecutionStep(); } } @@ -493,4 +499,12 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(); } } + + public class UserDeploymentStartup : StartupBase { + public override void ConfigureServices(IServiceCollection services) { + services.AddTransient(); + services.AddSingleton(new DeploymentStepFactory()); + services.AddScoped, AllUsersDeploymentStepDriver>(); + } + } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Edit.cshtml new file mode 100644 index 00000000000..152d2fa2762 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Edit.cshtml @@ -0,0 +1,3 @@ +@model dynamic + +
@T["All Users"]
diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Summary.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Summary.cshtml new file mode 100644 index 00000000000..214ea63d18f --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Summary.cshtml @@ -0,0 +1,5 @@ +@model dynamic + +
@T["All Users"]
+ +@T["Adds all users to the plan."] diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml new file mode 100644 index 00000000000..d3654b3e39c --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml @@ -0,0 +1,4 @@ +@model dynamic + +

@T["All Users"]

+

@T["Exports every user."]

diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml index d03012077cb..a75d8a5a541 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml @@ -19,3 +19,4 @@ @using OrchardCore.Users.TimeZone @using OrchardCore.Users.TimeZone.ViewModels @using OrchardCore.Workflows.Helpers +@using OrchardCore.Users.Deployment \ No newline at end of file From 0f80b89b91b993a9f9b8f47940a6726ece7efdec Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Fri, 25 Aug 2023 14:10:24 +0200 Subject: [PATCH 02/42] CustomUserSettings deployment --- .../CustomUserSettingsDeploymentSource.cs | 67 +++++++++ .../CustomUserSettingsDeploymentStep.cs | 16 +++ .../CustomUserSettingsDeploymentStepDriver.cs | 59 ++++++++ .../Recipes/CustomUserSettingsStep.cs | 64 +++++++++ .../Services/CustomUserSettingsService.cs | 136 ++++++++++++++++++ .../OrchardCore.Users/Startup.cs | 7 + ...stomUserSettingsDeploymentStepViewModel.cs | 9 ++ ...rSettingsDeploymentStep.Fields.Edit.cshtml | 62 ++++++++ ...ttingsDeploymentStep.Fields.Summary.cshtml | 24 ++++ ...ingsDeploymentStep.Fields.Thumbnail.cshtml | 4 + .../Views/_ViewImports.cshtml | 2 +- 11 files changed, 449 insertions(+), 1 deletion(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Summary.cshtml create mode 100644 src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs new file mode 100644 index 00000000000..a60765a785f --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs @@ -0,0 +1,67 @@ +using System.Linq; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using OrchardCore.Deployment; +using OrchardCore.Users.Models; +using OrchardCore.Users.Services; +using YesSql; + +namespace OrchardCore.Users.Deployment +{ + public class CustomUserSettingsDeploymentSource : IDeploymentSource + { + private readonly CustomUserSettingsService _customUserSettingsService; + private readonly ISession _session; + + public CustomUserSettingsDeploymentSource(CustomUserSettingsService customUserSettingsService, ISession session) + { + _customUserSettingsService = customUserSettingsService; + _session = session; + } + + public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) + { + var customUserSettingsStep = step as CustomUserSettingsDeploymentStep; + if (customUserSettingsStep == null) + { + return; + } + + var settingsTypes = customUserSettingsStep.IncludeAll + ? _customUserSettingsService.GetAllSettingsTypes().ToArray() + : _customUserSettingsService.GetSettingsTypes(customUserSettingsStep.SettingsTypeNames).ToArray(); + + foreach (var settingsType in settingsTypes) + { + if (!await _customUserSettingsService.CanUserCreateSettingsAsync(settingsType)) + { + return; + } + } + + var bigArray = new JArray(); + + var allUsers = await _session.Query().ListAsync(); + + foreach (var user in allUsers) + { + var myArray = new JArray(); + foreach (var settingsType in settingsTypes) + { + var userSetting = await _customUserSettingsService.GetSettingsAsync(user, settingsType); + myArray.Add(JObject.FromObject(userSetting)); + } + + bigArray.Add(new JObject( + new JProperty("userId", user.UserId), + new JProperty("user-custom-user-settings", myArray) + )); + } + + // Adding custom user settings + result.Steps.Add(new JObject( + new JProperty("name", "custom-user-settings"), + new JProperty("custom-user-settings", bigArray))); + } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs new file mode 100644 index 00000000000..b83506f5b97 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs @@ -0,0 +1,16 @@ +using OrchardCore.Deployment; + +namespace OrchardCore.Users.Deployment +{ + public class CustomUserSettingsDeploymentStep : DeploymentStep + { + public CustomUserSettingsDeploymentStep() + { + Name = "CustomUserSettings"; + } + + public bool IncludeAll { get; set; } = true; + + public string[] SettingsTypeNames { get; set; } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs new file mode 100644 index 00000000000..813cffeb3e4 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs @@ -0,0 +1,59 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using OrchardCore.Deployment; +using OrchardCore.DisplayManagement.Handlers; +using OrchardCore.DisplayManagement.ModelBinding; +using OrchardCore.DisplayManagement.Views; +using OrchardCore.Users.Services; +using OrchardCore.Users.ViewModels; + +namespace OrchardCore.Users.Deployment +{ + public class CustomUserSettingsDeploymentStepDriver : DisplayDriver + { + private readonly CustomUserSettingsService _customUserSettingsService; + + public CustomUserSettingsDeploymentStepDriver(CustomUserSettingsService customUserSettingsService) + { + _customUserSettingsService = customUserSettingsService; + } + + public override IDisplayResult Display(CustomUserSettingsDeploymentStep step) + { + return + Combine( + View("CustomUserSettingsDeploymentStep_Fields_Summary", step).Location("Summary", "Content"), + View("CustomUserSettingsDeploymentStep_Fields_Thumbnail", step).Location("Thumbnail", "Content") + ); + } + + public override IDisplayResult Edit(CustomUserSettingsDeploymentStep step) + { + return Initialize("CustomUserSettingsDeploymentStep_Fields_Edit", model => + { + model.IncludeAll = step.IncludeAll; + model.SettingsTypeNames = step.SettingsTypeNames; + model.AllSettingsTypeNames = _customUserSettingsService.GetAllSettingsTypeNames().ToArray(); + }).Location("Content"); + } + + public override async Task UpdateAsync(CustomUserSettingsDeploymentStep step, IUpdateModel updater) + { + step.SettingsTypeNames = Array.Empty(); + + await updater.TryUpdateModelAsync(step, + Prefix, + x => x.SettingsTypeNames, + x => x.IncludeAll); + + // don't have the selected option if include all + if (step.IncludeAll) + { + step.SettingsTypeNames = Array.Empty(); + } + + return Edit(step); + } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs new file mode 100644 index 00000000000..5b7c3447351 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -0,0 +1,64 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using OrchardCore.ContentManagement; +using OrchardCore.Recipes.Models; +using OrchardCore.Recipes.Services; +using OrchardCore.Users.Models; +using YesSql; + +namespace OrchardCore.Users.Recipes +{ + /// + /// This recipe step updates the custom user settings. + /// + public class CustomUserSettingsStep : IRecipeStepHandler + { + private ISession _session; + + public CustomUserSettingsStep(ISession session) + { + _session = session; + } + + public async Task ExecuteAsync(RecipeExecutionContext context) + { + if (!String.Equals(context.Name, "custom-user-settings", StringComparison.OrdinalIgnoreCase)) + { + return; + } + + var model = context.Step; + + var customUserSettingsList = (JArray)(from property in model.Properties() + where property.Name != "name" + select property).FirstOrDefault().Value; + + var allUsers = (await _session.Query().ListAsync()); + + foreach (JObject userCustomUserSettings in customUserSettingsList) + { + var userId = userCustomUserSettings.Properties().FirstOrDefault(p => p.Name == "userId").Value.ToString(); + + var iUser = allUsers.FirstOrDefault(u => u.UserId == userId); + if (iUser == null) + { + continue; + } + + var user = iUser as User; + var userSettings = (JArray)userCustomUserSettings.Properties().FirstOrDefault(p => p.Name == "user-custom-user-settings").Value; + + foreach (JObject userSetting in userSettings) + { + var ci = userSetting.ToObject(); + user.Properties[ci.ContentType] = userSetting; + + } + + _session.Save(user); + } + } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs new file mode 100644 index 00000000000..5b0edfb4fc1 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Newtonsoft.Json.Linq; +using OrchardCore.ContentManagement; +using OrchardCore.ContentManagement.Metadata; +using OrchardCore.ContentManagement.Metadata.Models; +using OrchardCore.Settings; +using OrchardCore.Users.Models; +using YesSql; + +namespace OrchardCore.Users.Services +{ + public class CustomUserSettingsService + { + private readonly IContentManager _contentManager; + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IAuthorizationService _authorizationService; + private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly Lazy> _settingsTypes; + private readonly YesSql.ISession _session; + + public CustomUserSettingsService( + ISiteService siteService, + IContentManager contentManager, + IHttpContextAccessor httpContextAccessor, + IAuthorizationService authorizationService, + IContentDefinitionManager contentDefinitionManager, + YesSql.ISession session) + { + _contentManager = contentManager; + _httpContextAccessor = httpContextAccessor; + _authorizationService = authorizationService; + _contentDefinitionManager = contentDefinitionManager; + _settingsTypes = new Lazy>( + () => _contentDefinitionManager + .ListTypeDefinitions() + .Where(x => x.GetStereotype() == "CustomUserSettings") + .ToDictionary(x => x.Name)); + _session = session; + } + + public IEnumerable GetAllSettingsTypeNames() + { + return _settingsTypes.Value.Keys; + } + + public IEnumerable GetAllSettingsTypes() + { + return _settingsTypes.Value.Values; + } + + public IEnumerable GetSettingsTypes(params string[] settingsTypeNames) + { + foreach (var settingsTypeName in settingsTypeNames) + { + ContentTypeDefinition settingsType; + if (_settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType)) + { + yield return settingsType; + } + } + } + + public ContentTypeDefinition GetSettingsType(string settingsTypeName) + { + ContentTypeDefinition settingsType; + + _settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType); + + return settingsType; + } + + public async Task CanUserCreateSettingsAsync(ContentTypeDefinition settingsType) + { + var user = _httpContextAccessor.HttpContext?.User; + + // todo: + // return _authorizationService.AuthorizeAsync(user, Permissions.CreatePermissionForType(settingsType)); + await Task.Delay(0); + return true; + } + + public Task> GetSettingsAsync(string settingsTypeName, Action isNew = null) + { + var settingsType = GetSettingsType(settingsTypeName); + if (settingsType == null) + { + return Task.FromResult>(null); + } + + return GetSettingsAsync(settingsType, isNew); + } + + public async Task> GetSettingsAsync(ContentTypeDefinition settingsType, Action isNew = null) + { + // foreach user get settings + var users = await _session.Query().ListAsync(); + var ct = new Dictionary(); + foreach (var user in users){ + var item = await GetSettingsAsync(user, settingsType, isNew); + if (item != null) + { + ct.Add(user.UserId, item); + } + } + + return ct; + } + + public async Task GetSettingsAsync(User user, ContentTypeDefinition settingsType, Action isNew = null) + { + JToken property; + ContentItem contentItem; + + if (user.Properties.TryGetValue(settingsType.Name, out property)) + { + var existing = property.ToObject(); + + // Create a new item to take into account the current type definition. + contentItem = await _contentManager.NewAsync(existing.ContentType); + contentItem.Merge(existing); + } + else + { + contentItem = await _contentManager.NewAsync(settingsType.Name); + isNew?.Invoke(); + } + + return contentItem; + } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs index e44537fae82..31f2f315636 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs @@ -250,6 +250,9 @@ public override void ConfigureServices(IServiceCollection services) services.AddTransient, UserOptionsConfiguration>(); services.AddRecipeExecutionStep(); + + services.AddScoped(); + services.AddRecipeExecutionStep(); } } @@ -497,6 +500,10 @@ public override void ConfigureServices(IServiceCollection services) { services.AddScoped, CustomUserSettingsDisplayDriver>(); services.AddScoped(); + + services.AddTransient(); + services.AddSingleton(new DeploymentStepFactory()); + services.AddScoped, CustomUserSettingsDeploymentStepDriver>(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs new file mode 100644 index 00000000000..e71b2bc2f20 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs @@ -0,0 +1,9 @@ +namespace OrchardCore.Users.ViewModels +{ + public class CustomUserSettingsDeploymentStepViewModel + { + public bool IncludeAll { get; set; } + public string[] SettingsTypeNames { get; set; } + public string[] AllSettingsTypeNames { get; set; } + } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml new file mode 100644 index 00000000000..9d947c18245 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml @@ -0,0 +1,62 @@ +@model CustomUserSettingsDeploymentStepViewModel + +@{ + var settingsTypeNames = Model.SettingsTypeNames; + var allSettingsTypeNames = Model.AllSettingsTypeNames; +} + +
@T["Custom User Settings"]
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+ @T["The custom user settings to add as part of the plan."] +
+
+
+
+
    + @foreach (var settingsTypeName in allSettingsTypeNames) + { + var checkd = settingsTypeNames?.Contains(settingsTypeName); + +
  • +
    + +
    +
  • + } +
+
+
+
+ + diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Summary.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Summary.cshtml new file mode 100644 index 00000000000..d9a46e4aa04 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Summary.cshtml @@ -0,0 +1,24 @@ +@model ShapeViewModel + +@{ + var includeAll = Model.Value.IncludeAll; + var settingsTypeNames = Model.Value.SettingsTypeNames; +} + +
@T["Custom User Settings"]
+ +@if (includeAll) +{ + @T["All"] +} +else if (settingsTypeNames?.Length > 0) +{ + foreach (var settingsTypeName in settingsTypeNames) + { + @settingsTypeName + } +} +else +{ + @T["No custom user settings selected."] +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml new file mode 100644 index 00000000000..898d64e61cb --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml @@ -0,0 +1,4 @@ +@model dynamic + +

@T["Custom User Settings"]

+

@T["Exports all or specified custom user settings."]

diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml index a75d8a5a541..904487cf470 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/_ViewImports.cshtml @@ -19,4 +19,4 @@ @using OrchardCore.Users.TimeZone @using OrchardCore.Users.TimeZone.ViewModels @using OrchardCore.Workflows.Helpers -@using OrchardCore.Users.Deployment \ No newline at end of file +@using OrchardCore.Users.Deployment From 2e38e17c2410a9d8270c8c1a986617dc8f96f1a3 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Fri, 25 Aug 2023 17:31:35 +0200 Subject: [PATCH 03/42] Cleanup --- .../Deployment/AllUsersDeploymentSource.cs | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs index eb7b310f3d6..d1a93df7d28 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs @@ -26,37 +26,30 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - // todo: Get all users + // Get all users var allUsers = await _session.Query().ListAsync(); ; var users = new JArray(); var tasks = new List(); foreach (var user in allUsers) { - /* - var currentRole = (Role)await _roleManager.FindByNameAsync(_roleManager.NormalizeKey(role.RoleName)); - - if (currentRole != null) - { - */ - users.Add(JObject.FromObject( - new UsersStepUserModel - { - UserName = user.UserName, - UserId = user.UserId, - Email = user.Email, - Id = user.Id, - EmailConfirmed = user.EmailConfirmed, - PasswordHash = user.PasswordHash, - IsEnabled = user.IsEnabled, - NormalizedEmail = user.NormalizedEmail, - NormalizedUserName = user.NormalizedUserName, - SecurityStamp = user.SecurityStamp, - ResetToken = user.ResetToken - //Permissions = currentRole.RoleClaims.Where(x => x.ClaimType == Permission.ClaimType).Select(x => x.ClaimValue).ToArray() - })); - - //} + // TODO: check if user has permission to export users + users.Add(JObject.FromObject( + new UsersStepUserModel + { + UserName = user.UserName, + UserId = user.UserId, + Email = user.Email, + Id = user.Id, + EmailConfirmed = user.EmailConfirmed, + PasswordHash = user.PasswordHash, + IsEnabled = user.IsEnabled, + NormalizedEmail = user.NormalizedEmail, + NormalizedUserName = user.NormalizedUserName, + SecurityStamp = user.SecurityStamp, + ResetToken = user.ResetToken + //Permissions = currentRole.RoleClaims.Where(x => x.ClaimType == Permission.ClaimType).Select(x => x.ClaimValue).ToArray() + })); } result.Steps.Add(new JObject( From 69a2eb3b49a2f8250eba817b59bf64ee00fcebbd Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Mon, 28 Aug 2023 17:18:49 +0200 Subject: [PATCH 04/42] Code review changes --- .../Deployment/AllUsersDeploymentSource.cs | 88 +++++---- .../Deployment/AllUsersDeploymentStep.cs | 16 +- .../AllUsersDeploymentStepDriver.cs | 27 ++- .../CustomUserSettingsDeploymentSource.cs | 79 ++++---- .../CustomUserSettingsDeploymentStep.cs | 17 +- .../CustomUserSettingsDeploymentStepDriver.cs | 1 - .../OrchardCore.Users/Recipes/UsersStep.cs | 133 +++++++------ .../Services/CustomUserSettingsService.cs | 186 +++++++++--------- 8 files changed, 271 insertions(+), 276 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs index d1a93df7d28..cad03322055 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs @@ -6,56 +6,58 @@ using OrchardCore.Users.Recipes; using YesSql; -namespace OrchardCore.Users.Deployment +namespace OrchardCore.Users.Deployment; + +public class AllUsersDeploymentSource : IDeploymentSource { - public class AllUsersDeploymentSource : IDeploymentSource + private readonly ISession _session; + + public AllUsersDeploymentSource(ISession session) { - private readonly ISession _session; + _session = session; + } - public AllUsersDeploymentSource(ISession session) + public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) + { + var allRolesStep = step as AllUsersDeploymentStep; + + if (allRolesStep == null) { - _session = session; + return; } - public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) + var allUsers = await _session.Query().ListAsync(); + var users = new JArray(); + var tasks = new List(); + + foreach (var user in allUsers) { - var allRolesStep = step as AllUsersDeploymentStep; - - if (allRolesStep == null) - { - return; - } - - // Get all users - var allUsers = await _session.Query().ListAsync(); ; - var users = new JArray(); - var tasks = new List(); - - foreach (var user in allUsers) - { - // TODO: check if user has permission to export users - users.Add(JObject.FromObject( - new UsersStepUserModel - { - UserName = user.UserName, - UserId = user.UserId, - Email = user.Email, - Id = user.Id, - EmailConfirmed = user.EmailConfirmed, - PasswordHash = user.PasswordHash, - IsEnabled = user.IsEnabled, - NormalizedEmail = user.NormalizedEmail, - NormalizedUserName = user.NormalizedUserName, - SecurityStamp = user.SecurityStamp, - ResetToken = user.ResetToken - //Permissions = currentRole.RoleClaims.Where(x => x.ClaimType == Permission.ClaimType).Select(x => x.ClaimValue).ToArray() - })); - } - - result.Steps.Add(new JObject( - new JProperty("name", "Users"), - new JProperty("Users", users) - )); + users.Add(JObject.FromObject( + new UsersStepUserModel + { + UserName = user.UserName, + UserId = user.UserId, + Id = user.Id, + Email = user.Email, + EmailConfirmed = user.EmailConfirmed, + PasswordHash = user.PasswordHash, + IsEnabled = user.IsEnabled, + NormalizedEmail = user.NormalizedEmail, + NormalizedUserName = user.NormalizedUserName, + SecurityStamp = user.SecurityStamp, + ResetToken = user.ResetToken, + PhoneNumber = user.PhoneNumber, + PhoneNumberConfirmed = user.PhoneNumberConfirmed, + TwoFactorEnabled = user.TwoFactorEnabled, + IsLockoutEnabled = user.IsLockoutEnabled, + AccessFailedCount = user.AccessFailedCount, + RoleNames = user.RoleNames, + })); } + + result.Steps.Add(new JObject( + new JProperty("name", "Users"), + new JProperty("Users", users) + )); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs index f8d63009a24..9fc2cb61756 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs @@ -1,15 +1,13 @@ using OrchardCore.Deployment; -namespace OrchardCore.Users.Deployment +namespace OrchardCore.Users.Deployment; +/// +/// Adds users to a . +/// +public class AllUsersDeploymentStep : DeploymentStep { - /// - /// Adds users to a . - /// - public class AllUsersDeploymentStep : DeploymentStep + public AllUsersDeploymentStep() { - public AllUsersDeploymentStep() - { - Name = "AllUsers"; - } + Name = "AllUsers"; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs index fdc5a07c137..e3da646418c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs @@ -2,22 +2,21 @@ using OrchardCore.DisplayManagement.Handlers; using OrchardCore.DisplayManagement.Views; -namespace OrchardCore.Users.Deployment +namespace OrchardCore.Users.Deployment; + +public class AllUsersDeploymentStepDriver : DisplayDriver { - public class AllUsersDeploymentStepDriver : DisplayDriver + public override IDisplayResult Display(AllUsersDeploymentStep step) { - public override IDisplayResult Display(AllUsersDeploymentStep step) - { - return - Combine( - View("AllUsersDeploymentStep_Summary", step).Location("Summary", "Content"), - View("AllUsersDeploymentStep_Thumbnail", step).Location("Thumbnail", "Content") - ); - } + return + Combine( + View("AllUsersDeploymentStep_Summary", step).Location("Summary", "Content"), + View("AllUsersDeploymentStep_Thumbnail", step).Location("Thumbnail", "Content") + ); + } - public override IDisplayResult Edit(AllUsersDeploymentStep step) - { - return View("AllUsersDeploymentStep_Edit", step).Location("Content"); - } + public override IDisplayResult Edit(AllUsersDeploymentStep step) + { + return View("AllUsersDeploymentStep_Edit", step).Location("Content"); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs index a60765a785f..dfa360a1263 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs @@ -6,62 +6,61 @@ using OrchardCore.Users.Services; using YesSql; -namespace OrchardCore.Users.Deployment +namespace OrchardCore.Users.Deployment; + +public class CustomUserSettingsDeploymentSource : IDeploymentSource { - public class CustomUserSettingsDeploymentSource : IDeploymentSource + private readonly CustomUserSettingsService _customUserSettingsService; + private readonly ISession _session; + + public CustomUserSettingsDeploymentSource(CustomUserSettingsService customUserSettingsService, ISession session) { - private readonly CustomUserSettingsService _customUserSettingsService; - private readonly ISession _session; + _customUserSettingsService = customUserSettingsService; + _session = session; + } - public CustomUserSettingsDeploymentSource(CustomUserSettingsService customUserSettingsService, ISession session) + public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) + { + var customUserSettingsStep = step as CustomUserSettingsDeploymentStep; + if (customUserSettingsStep == null) { - _customUserSettingsService = customUserSettingsService; - _session = session; + return; } - public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) + var settingsTypes = customUserSettingsStep.IncludeAll + ? _customUserSettingsService.GetAllSettingsTypes().ToArray() + : _customUserSettingsService.GetSettingsTypes(customUserSettingsStep.SettingsTypeNames).ToArray(); + + foreach (var settingsType in settingsTypes) { - var customUserSettingsStep = step as CustomUserSettingsDeploymentStep; - if (customUserSettingsStep == null) + if (!await _customUserSettingsService.CanUserCreateSettingsAsync(settingsType)) { return; } + } + + var bigArray = new JArray(); - var settingsTypes = customUserSettingsStep.IncludeAll - ? _customUserSettingsService.GetAllSettingsTypes().ToArray() - : _customUserSettingsService.GetSettingsTypes(customUserSettingsStep.SettingsTypeNames).ToArray(); + var allUsers = await _session.Query().ListAsync(); + foreach (var user in allUsers) + { + var myArray = new JArray(); foreach (var settingsType in settingsTypes) { - if (!await _customUserSettingsService.CanUserCreateSettingsAsync(settingsType)) - { - return; - } + var userSetting = await _customUserSettingsService.GetSettingsAsync(user, settingsType); + myArray.Add(JObject.FromObject(userSetting)); } - - var bigArray = new JArray(); - var allUsers = await _session.Query().ListAsync(); - - foreach (var user in allUsers) - { - var myArray = new JArray(); - foreach (var settingsType in settingsTypes) - { - var userSetting = await _customUserSettingsService.GetSettingsAsync(user, settingsType); - myArray.Add(JObject.FromObject(userSetting)); - } - - bigArray.Add(new JObject( - new JProperty("userId", user.UserId), - new JProperty("user-custom-user-settings", myArray) - )); - } - - // Adding custom user settings - result.Steps.Add(new JObject( - new JProperty("name", "custom-user-settings"), - new JProperty("custom-user-settings", bigArray))); + bigArray.Add(new JObject( + new JProperty("userId", user.UserId), + new JProperty("user-custom-user-settings", myArray) + )); } + + // Adding custom user settings + result.Steps.Add(new JObject( + new JProperty("name", "custom-user-settings"), + new JProperty("custom-user-settings", bigArray))); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs index b83506f5b97..b77cdfb558a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStep.cs @@ -1,16 +1,15 @@ using OrchardCore.Deployment; -namespace OrchardCore.Users.Deployment +namespace OrchardCore.Users.Deployment; + +public class CustomUserSettingsDeploymentStep : DeploymentStep { - public class CustomUserSettingsDeploymentStep : DeploymentStep + public CustomUserSettingsDeploymentStep() { - public CustomUserSettingsDeploymentStep() - { - Name = "CustomUserSettings"; - } + Name = "CustomUserSettings"; + } - public bool IncludeAll { get; set; } = true; + public bool IncludeAll { get; set; } = true; - public string[] SettingsTypeNames { get; set; } - } + public string[] SettingsTypeNames { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs index 813cffeb3e4..4718eaafd39 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs @@ -47,7 +47,6 @@ await updater.TryUpdateModelAsync(step, x => x.SettingsTypeNames, x => x.IncludeAll); - // don't have the selected option if include all if (step.IncludeAll) { step.SettingsTypeNames = Array.Empty(); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index a9fe54e1b6b..348678932a6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -1,86 +1,89 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; using OrchardCore.Users.Models; -using OrchardCore.Users.Services; using YesSql; -namespace OrchardCore.Users.Recipes +namespace OrchardCore.Users.Recipes; + +public class UsersStep : IRecipeStepHandler { - public class UsersStep : IRecipeStepHandler { - private readonly UserManager _userManager; - private readonly IUserService _userService; - private ISession _session; - public UsersStep(UserManager userManager, IUserService userService, ISession session) + private readonly UserManager _userManager; + private readonly ISession _session; + + public UsersStep( + UserManager userManager, + ISession session) + { + _userManager = userManager; + _session = session; + } + + public async Task ExecuteAsync(RecipeExecutionContext context) + { + if (!String.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) { - _userManager = userManager; - _userService = userService; - _session = session; + return; } - - public async Task ExecuteAsync(RecipeExecutionContext context) { - - if (!String.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) { - return; - } - var model = context.Step.ToObject(); + var model = context.Step.ToObject(); - foreach (var importedUser in model.Users) { - if (String.IsNullOrWhiteSpace(importedUser.UserName)) - continue; - - var iUser = await _userManager.FindByIdAsync(importedUser.UserId); - User user; - var isNewUser = iUser == null; - - if (isNewUser) { - user = new User { UserId = importedUser.UserId }; - } else { - user = iUser as User; - } + foreach (var importedUser in model.Users) + { + if (String.IsNullOrWhiteSpace(importedUser.UserName)) + continue; - user.Email = importedUser.Email; - user.UserName = importedUser.UserName; - //user.Id = importedUser.Id; // This is problematic because it's an identity column - user.EmailConfirmed = importedUser.EmailConfirmed; - user.PasswordHash = importedUser.PasswordHash; - user.IsEnabled = importedUser.IsEnabled; - user.NormalizedEmail = importedUser.NormalizedEmail; - user.NormalizedUserName = importedUser.NormalizedUserName; - user.SecurityStamp = importedUser.SecurityStamp; - user.ResetToken = importedUser.ResetToken; + var iUser = await _userManager.FindByIdAsync(importedUser.UserId); - if (isNewUser) { - _session.Save(user); - } else { - _session.Save(user); - } + if (iUser is not User user) + { + user = new User { UserId = importedUser.UserId }; } - } + else + { + user = iUser as User; + } + + user.Email = importedUser.Email; + user.UserName = importedUser.UserName; + user.EmailConfirmed = importedUser.EmailConfirmed; + user.PasswordHash = importedUser.PasswordHash; + user.IsEnabled = importedUser.IsEnabled; + user.NormalizedEmail = importedUser.NormalizedEmail; + user.NormalizedUserName = importedUser.NormalizedUserName; + user.SecurityStamp = importedUser.SecurityStamp; + user.ResetToken = importedUser.ResetToken; - public class UsersStepModel { - public UsersStepUserModel[] Users { get; set; } + _session.Save(user); } } - public class UsersStepUserModel { - - public long Id { get; set; } - - public string UserId { get; set; } - - public string UserName { get; set; } - - public string Email { get; set; } - public string PasswordHash { get; set; } - public bool EmailConfirmed { get; set; } - public bool IsEnabled { get; set; } = true; - public string NormalizedEmail { get; set; } - public string NormalizedUserName { get; set; } - public string SecurityStamp { get; set; } - public string ResetToken { get; set; } + public class UsersStepModel + { + public UsersStepUserModel[] Users { get; set; } } -} \ No newline at end of file +} + +public class UsersStepUserModel +{ + public long Id { get; set; } + public string UserId { get; set; } + public string UserName { get; set; } + public string Email { get; set; } + public string PasswordHash { get; set; } + public bool EmailConfirmed { get; set; } + public bool IsEnabled { get; set; } = true; + public string NormalizedEmail { get; set; } + public string NormalizedUserName { get; set; } + public string SecurityStamp { get; set; } + public string ResetToken { get; set; } + public string PhoneNumber { get; internal set; } + public bool PhoneNumberConfirmed { get; internal set; } + public bool TwoFactorEnabled { get; internal set; } + public bool IsLockoutEnabled { get; internal set; } + public int AccessFailedCount { get; internal set; } + public IList RoleNames { get; internal set; } +} diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs index 5b0edfb4fc1..c022a651247 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs @@ -12,125 +12,121 @@ using OrchardCore.Users.Models; using YesSql; -namespace OrchardCore.Users.Services +namespace OrchardCore.Users.Services; +public class CustomUserSettingsService { - public class CustomUserSettingsService + private readonly IContentManager _contentManager; + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IAuthorizationService _authorizationService; + private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly Lazy> _settingsTypes; + private readonly YesSql.ISession _session; + + public CustomUserSettingsService( + ISiteService siteService, + IContentManager contentManager, + IHttpContextAccessor httpContextAccessor, + IAuthorizationService authorizationService, + IContentDefinitionManager contentDefinitionManager, + YesSql.ISession session) { - private readonly IContentManager _contentManager; - private readonly IHttpContextAccessor _httpContextAccessor; - private readonly IAuthorizationService _authorizationService; - private readonly IContentDefinitionManager _contentDefinitionManager; - private readonly Lazy> _settingsTypes; - private readonly YesSql.ISession _session; - - public CustomUserSettingsService( - ISiteService siteService, - IContentManager contentManager, - IHttpContextAccessor httpContextAccessor, - IAuthorizationService authorizationService, - IContentDefinitionManager contentDefinitionManager, - YesSql.ISession session) - { - _contentManager = contentManager; - _httpContextAccessor = httpContextAccessor; - _authorizationService = authorizationService; - _contentDefinitionManager = contentDefinitionManager; - _settingsTypes = new Lazy>( - () => _contentDefinitionManager - .ListTypeDefinitions() - .Where(x => x.GetStereotype() == "CustomUserSettings") - .ToDictionary(x => x.Name)); - _session = session; - } + _contentManager = contentManager; + _httpContextAccessor = httpContextAccessor; + _authorizationService = authorizationService; + _contentDefinitionManager = contentDefinitionManager; + _settingsTypes = new Lazy>( + () => _contentDefinitionManager + .ListTypeDefinitions() + .Where(x => x.GetStereotype() == "CustomUserSettings") + .ToDictionary(x => x.Name)); + _session = session; + } - public IEnumerable GetAllSettingsTypeNames() - { - return _settingsTypes.Value.Keys; - } + public IEnumerable GetAllSettingsTypeNames() + { + return _settingsTypes.Value.Keys; + } - public IEnumerable GetAllSettingsTypes() - { - return _settingsTypes.Value.Values; - } + public IEnumerable GetAllSettingsTypes() + { + return _settingsTypes.Value.Values; + } - public IEnumerable GetSettingsTypes(params string[] settingsTypeNames) + public IEnumerable GetSettingsTypes(params string[] settingsTypeNames) + { + foreach (var settingsTypeName in settingsTypeNames) { - foreach (var settingsTypeName in settingsTypeNames) + ContentTypeDefinition settingsType; + if (_settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType)) { - ContentTypeDefinition settingsType; - if (_settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType)) - { - yield return settingsType; - } + yield return settingsType; } } + } - public ContentTypeDefinition GetSettingsType(string settingsTypeName) - { - ContentTypeDefinition settingsType; + public ContentTypeDefinition GetSettingsType(string settingsTypeName) + { + ContentTypeDefinition settingsType; + _settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType); + return settingsType; + } - _settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType); + public async Task CanUserCreateSettingsAsync(ContentTypeDefinition settingsType) + { + var user = _httpContextAccessor.HttpContext?.User; - return settingsType; - } + // todo: + // return _authorizationService.AuthorizeAsync(user, Permissions.CreatePermissionForType(settingsType)); + await Task.Delay(0); + return true; + } - public async Task CanUserCreateSettingsAsync(ContentTypeDefinition settingsType) + public Task> GetSettingsAsync(string settingsTypeName, Action isNew = null) + { + var settingsType = GetSettingsType(settingsTypeName); + if (settingsType == null) { - var user = _httpContextAccessor.HttpContext?.User; - - // todo: - // return _authorizationService.AuthorizeAsync(user, Permissions.CreatePermissionForType(settingsType)); - await Task.Delay(0); - return true; + return Task.FromResult>(null); } - public Task> GetSettingsAsync(string settingsTypeName, Action isNew = null) - { - var settingsType = GetSettingsType(settingsTypeName); - if (settingsType == null) + return GetSettingsAsync(settingsType, isNew); + } + + public async Task> GetSettingsAsync(ContentTypeDefinition settingsType, Action isNew = null) + { + // foreach user get settings + var users = await _session.Query().ListAsync(); + var contentItems = new Dictionary(); + foreach (var user in users){ + var item = await GetSettingsAsync(user, settingsType, isNew); + if (item != null) { - return Task.FromResult>(null); + contentItems.Add(user.UserId, item); } - - return GetSettingsAsync(settingsType, isNew); } - public async Task> GetSettingsAsync(ContentTypeDefinition settingsType, Action isNew = null) - { - // foreach user get settings - var users = await _session.Query().ListAsync(); - var ct = new Dictionary(); - foreach (var user in users){ - var item = await GetSettingsAsync(user, settingsType, isNew); - if (item != null) - { - ct.Add(user.UserId, item); - } - } + return contentItems; + } - return ct; - } + public async Task GetSettingsAsync(User user, ContentTypeDefinition settingsType, Action isNew = null) + { + JToken property; + ContentItem contentItem; - public async Task GetSettingsAsync(User user, ContentTypeDefinition settingsType, Action isNew = null) + if (user.Properties.TryGetValue(settingsType.Name, out property)) { - JToken property; - ContentItem contentItem; - - if (user.Properties.TryGetValue(settingsType.Name, out property)) - { - var existing = property.ToObject(); - - // Create a new item to take into account the current type definition. - contentItem = await _contentManager.NewAsync(existing.ContentType); - contentItem.Merge(existing); - } - else - { - contentItem = await _contentManager.NewAsync(settingsType.Name); - isNew?.Invoke(); - } + var existing = property.ToObject(); - return contentItem; + // Create a new item to take into account the current type definition. + contentItem = await _contentManager.NewAsync(existing.ContentType); + contentItem.Merge(existing); } + else + { + contentItem = await _contentManager.NewAsync(settingsType.Name); + isNew?.Invoke(); + } + + return contentItem; } } From 40a490fcad32ec2176ea24d682e5f1b06867866f Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Mon, 28 Aug 2023 17:24:36 +0200 Subject: [PATCH 05/42] Further changes --- .../OrchardCore.Users/Recipes/UsersStep.cs | 4 ++-- .../OrchardCore.Users/Services/CustomUserSettingsService.cs | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index 348678932a6..3f5aa6dccab 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -21,7 +21,7 @@ public UsersStep( _userManager = userManager; _session = session; } - + public async Task ExecuteAsync(RecipeExecutionContext context) { if (!String.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) @@ -61,7 +61,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } } - public class UsersStepModel + public class UsersStepModel { public UsersStepUserModel[] Users { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs index c022a651247..2aed13f30cd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs @@ -56,9 +56,7 @@ public IEnumerable GetSettingsTypes(params string[] setti { foreach (var settingsTypeName in settingsTypeNames) { - ContentTypeDefinition settingsType; - if (_settingsTypes.Value.TryGetValue(settingsTypeName, out settingsType)) - { + if (_settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType)) yield return settingsType; } } @@ -66,7 +64,6 @@ public IEnumerable GetSettingsTypes(params string[] setti public ContentTypeDefinition GetSettingsType(string settingsTypeName) { - ContentTypeDefinition settingsType; _settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType); return settingsType; } From 0625ffcc9800bd203fcaa034542743767ebccc61 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Mon, 28 Aug 2023 18:30:47 +0200 Subject: [PATCH 06/42] Formatting and bracket --- .../Services/CustomUserSettingsService.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs index 2aed13f30cd..327d4e28e3e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs @@ -8,11 +8,11 @@ using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Metadata.Models; -using OrchardCore.Settings; using OrchardCore.Users.Models; using YesSql; namespace OrchardCore.Users.Services; + public class CustomUserSettingsService { private readonly IContentManager _contentManager; @@ -23,7 +23,6 @@ public class CustomUserSettingsService private readonly YesSql.ISession _session; public CustomUserSettingsService( - ISiteService siteService, IContentManager contentManager, IHttpContextAccessor httpContextAccessor, IAuthorizationService authorizationService, @@ -56,9 +55,8 @@ public IEnumerable GetSettingsTypes(params string[] setti { foreach (var settingsTypeName in settingsTypeNames) { - if (_settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType)) + if (_settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType)) yield return settingsType; - } } } @@ -94,7 +92,8 @@ public async Task> GetSettingsAsync(ContentTypeD // foreach user get settings var users = await _session.Query().ListAsync(); var contentItems = new Dictionary(); - foreach (var user in users){ + foreach (var user in users) + { var item = await GetSettingsAsync(user, settingsType, isNew); if (item != null) { From e5476a61b0866a3b4bdbd9ff2fc6df879adcf1a5 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Mon, 28 Aug 2023 19:09:40 +0200 Subject: [PATCH 07/42] Further refactor --- .../Deployment/AllUsersDeploymentSource.cs | 5 +-- .../Deployment/AllUsersDeploymentStep.cs | 1 + .../AllUsersDeploymentStepDriver.cs | 6 +-- .../CustomUserSettingsDeploymentSource.cs | 5 +-- .../CustomUserSettingsDeploymentStepDriver.cs | 18 ++++----- .../Recipes/CustomUserSettingsStep.cs | 39 +++++++++++-------- .../OrchardCore.Users/Recipes/UsersStep.cs | 19 +++++---- .../Services/CustomUserSettingsService.cs | 2 + ...stomUserSettingsDeploymentStepViewModel.cs | 13 +++---- .../CustomUserSettingsEditViewModel.cs | 9 ++--- 10 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs index cad03322055..e5df6d1cd0c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Threading.Tasks; using Newtonsoft.Json.Linq; using OrchardCore.Deployment; @@ -28,7 +27,6 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan var allUsers = await _session.Query().ListAsync(); var users = new JArray(); - var tasks = new List(); foreach (var user in allUsers) { @@ -57,7 +55,6 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan result.Steps.Add(new JObject( new JProperty("name", "Users"), - new JProperty("Users", users) - )); + new JProperty("Users", users))); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs index 9fc2cb61756..f77a800658a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStep.cs @@ -1,6 +1,7 @@ using OrchardCore.Deployment; namespace OrchardCore.Users.Deployment; + /// /// Adds users to a . /// diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs index e3da646418c..85d7aee4016 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentStepDriver.cs @@ -8,11 +8,9 @@ public class AllUsersDeploymentStepDriver : DisplayDriver().ListAsync(); @@ -54,8 +54,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan bigArray.Add(new JObject( new JProperty("userId", user.UserId), - new JProperty("user-custom-user-settings", myArray) - )); + new JProperty("user-custom-user-settings", myArray))); } // Adding custom user settings diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs index 4718eaafd39..56d32db00cc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentStepDriver.cs @@ -21,11 +21,9 @@ public CustomUserSettingsDeploymentStepDriver(CustomUserSettingsService customUs public override IDisplayResult Display(CustomUserSettingsDeploymentStep step) { - return - Combine( + return Combine( View("CustomUserSettingsDeploymentStep_Fields_Summary", step).Location("Summary", "Content"), - View("CustomUserSettingsDeploymentStep_Fields_Thumbnail", step).Location("Thumbnail", "Content") - ); + View("CustomUserSettingsDeploymentStep_Fields_Thumbnail", step).Location("Thumbnail", "Content")); } public override IDisplayResult Edit(CustomUserSettingsDeploymentStep step) @@ -35,17 +33,19 @@ public override IDisplayResult Edit(CustomUserSettingsDeploymentStep step) model.IncludeAll = step.IncludeAll; model.SettingsTypeNames = step.SettingsTypeNames; model.AllSettingsTypeNames = _customUserSettingsService.GetAllSettingsTypeNames().ToArray(); - }).Location("Content"); + }) + .Location("Content"); } public override async Task UpdateAsync(CustomUserSettingsDeploymentStep step, IUpdateModel updater) { step.SettingsTypeNames = Array.Empty(); - await updater.TryUpdateModelAsync(step, - Prefix, - x => x.SettingsTypeNames, - x => x.IncludeAll); + await updater.TryUpdateModelAsync( + step, + Prefix, + x => x.SettingsTypeNames, + x => x.IncludeAll); if (step.IncludeAll) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs index 5b7c3447351..cf00f418bb2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -24,39 +24,46 @@ public CustomUserSettingsStep(ISession session) public async Task ExecuteAsync(RecipeExecutionContext context) { - if (!String.Equals(context.Name, "custom-user-settings", StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(context.Name, "custom-user-settings", StringComparison.OrdinalIgnoreCase)) { return; } var model = context.Step; - var customUserSettingsList = (JArray)(from property in model.Properties() - where property.Name != "name" - select property).FirstOrDefault().Value; + var customUserSettingsList = (JArray)model + .Properties() + .Where(p => p.Name != "name") + .FirstOrDefault() + ?.Value; - var allUsers = (await _session.Query().ListAsync()); + var allUsers = await _session.Query().ListAsync(); - foreach (JObject userCustomUserSettings in customUserSettingsList) + foreach (JObject userCustomUserSettings in customUserSettingsList.Cast()) { - var userId = userCustomUserSettings.Properties().FirstOrDefault(p => p.Name == "userId").Value.ToString(); - + var userId = userCustomUserSettings + .Properties() + .FirstOrDefault(p => p.Name == "userId")? + .Value + ?.ToString(); + var iUser = allUsers.FirstOrDefault(u => u.UserId == userId); - if (iUser == null) + if (iUser is not User user) { continue; } - var user = iUser as User; - var userSettings = (JArray)userCustomUserSettings.Properties().FirstOrDefault(p => p.Name == "user-custom-user-settings").Value; + var userSettings = (JArray)userCustomUserSettings + .Properties() + .FirstOrDefault(p => p.Name == "user-custom-user-settings") + ?.Value; - foreach (JObject userSetting in userSettings) + foreach (JObject userSetting in userSettings.Cast()) { - var ci = userSetting.ToObject(); - user.Properties[ci.ContentType] = userSetting; - + var contentItem = userSetting.ToObject(); + user.Properties[contentItem.ContentType] = userSetting; } - + _session.Save(user); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index 3f5aa6dccab..44f5f8f4680 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Identity; using OrchardCore.Recipes.Models; using OrchardCore.Recipes.Services; +using OrchardCore.Sms; using OrchardCore.Users.Models; using YesSql; @@ -24,7 +25,7 @@ public UsersStep( public async Task ExecuteAsync(RecipeExecutionContext context) { - if (!String.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) { return; } @@ -33,8 +34,10 @@ public async Task ExecuteAsync(RecipeExecutionContext context) foreach (var importedUser in model.Users) { - if (String.IsNullOrWhiteSpace(importedUser.UserName)) + if (string.IsNullOrWhiteSpace(importedUser.UserName)) + { continue; + } var iUser = await _userManager.FindByIdAsync(importedUser.UserId); @@ -80,10 +83,10 @@ public class UsersStepUserModel public string NormalizedUserName { get; set; } public string SecurityStamp { get; set; } public string ResetToken { get; set; } - public string PhoneNumber { get; internal set; } - public bool PhoneNumberConfirmed { get; internal set; } - public bool TwoFactorEnabled { get; internal set; } - public bool IsLockoutEnabled { get; internal set; } - public int AccessFailedCount { get; internal set; } - public IList RoleNames { get; internal set; } + public string PhoneNumber { get; set; } + public bool PhoneNumberConfirmed { get; set; } + public bool TwoFactorEnabled { get; set; } + public bool IsLockoutEnabled { get; set; } + public int AccessFailedCount { get; set; } + public IList RoleNames { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs index 327d4e28e3e..7af2de51057 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs @@ -56,7 +56,9 @@ public IEnumerable GetSettingsTypes(params string[] setti foreach (var settingsTypeName in settingsTypeNames) { if (_settingsTypes.Value.TryGetValue(settingsTypeName, out ContentTypeDefinition settingsType)) + { yield return settingsType; + } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs index e71b2bc2f20..6a8da1ddf6c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs @@ -1,9 +1,8 @@ -namespace OrchardCore.Users.ViewModels +namespace OrchardCore.Users.ViewModels; + +public class CustomUserSettingsDeploymentStepViewModel { - public class CustomUserSettingsDeploymentStepViewModel - { - public bool IncludeAll { get; set; } - public string[] SettingsTypeNames { get; set; } - public string[] AllSettingsTypeNames { get; set; } - } + public bool IncludeAll { get; set; } + public string[] SettingsTypeNames { get; set; } + public string[] AllSettingsTypeNames { get; set; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsEditViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsEditViewModel.cs index e5d6110c732..8abde3f17f1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsEditViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsEditViewModel.cs @@ -1,7 +1,6 @@ -namespace OrchardCore.Users.ViewModels +namespace OrchardCore.Users.ViewModels; + +public class CustomUserSettingsEditViewModel { - public class CustomUserSettingsEditViewModel - { - public dynamic Editor { get; set; } - } + public dynamic Editor { get; set; } } From 6c7a4f805e5a7d40ddcf92ad85678d09f40bd6cd Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Mon, 28 Aug 2023 19:21:21 +0200 Subject: [PATCH 08/42] Registration --- src/OrchardCore.Modules/OrchardCore.Users/Startup.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs index 31f2f315636..070245359e6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Startup.cs @@ -502,15 +502,17 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(); services.AddTransient(); - services.AddSingleton(new DeploymentStepFactory()); + services.AddSingleton>(); services.AddScoped, CustomUserSettingsDeploymentStepDriver>(); } } - public class UserDeploymentStartup : StartupBase { - public override void ConfigureServices(IServiceCollection services) { + public class UserDeploymentStartup : StartupBase + { + public override void ConfigureServices(IServiceCollection services) + { services.AddTransient(); - services.AddSingleton(new DeploymentStepFactory()); + services.AddSingleton>(); services.AddScoped, AllUsersDeploymentStepDriver>(); } } From 153473cc2664369b5d8270c18bcc74947a9844a0 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Mon, 28 Aug 2023 20:03:26 +0200 Subject: [PATCH 09/42] User roles import --- .../OrchardCore.Users/Recipes/UsersStep.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index 44f5f8f4680..da852f38c38 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -59,6 +59,12 @@ public async Task ExecuteAsync(RecipeExecutionContext context) user.NormalizedUserName = importedUser.NormalizedUserName; user.SecurityStamp = importedUser.SecurityStamp; user.ResetToken = importedUser.ResetToken; + user.AccessFailedCount = importedUser.AccessFailedCount; + user.IsLockoutEnabled = importedUser.IsLockoutEnabled; + user.TwoFactorEnabled = importedUser.TwoFactorEnabled; + user.PhoneNumber = importedUser.PhoneNumber; + user.PhoneNumberConfirmed = importedUser.PhoneNumberConfirmed; + user.RoleNames = importedUser.RoleNames; _session.Save(user); } From 9044980bd83a31e4de057154e13e90c2a50e7269 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Mon, 28 Aug 2023 20:06:01 +0200 Subject: [PATCH 10/42] Vanilla js --- ...tomUserSettingsDeploymentStep.Fields.Edit.cshtml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml index 9d947c18245..4fb4c35c362 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml @@ -49,14 +49,17 @@ From d2a650c647a46dc026119c641a77b5bfba4b92cc Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Tue, 29 Aug 2023 11:51:16 +0200 Subject: [PATCH 11/42] Update src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml Co-authored-by: Mike Alhayek --- .../CustomUserSettingsDeploymentStep.Fields.Edit.cshtml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml index 4fb4c35c362..dddef7d2802 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml @@ -52,9 +52,8 @@ window.addEventListener('DOMContentLoaded', function() { var toggles = document.querySelectorAll('[data-reversetoggle]'); for (var i = 0; i < toggles.length; i++) { - toggles[i].addEventListener('click', function() { - var state = this.checked; - if (state) { + toggles[i].addEventListener('click', (e) => { + if (e.target.checked) { document.querySelector(this.getAttribute('data-reversetoggle')).classList.remove('show'); } else { document.querySelector(this.getAttribute('data-reversetoggle')).classList.add('show'); From f41f59b4f5b3d04efd1c748c7089466eeeda101b Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Tue, 29 Aug 2023 11:51:46 +0200 Subject: [PATCH 12/42] Update src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml Co-authored-by: Mike Alhayek --- .../Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml index dddef7d2802..3b17842aade 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Edit.cshtml @@ -49,7 +49,7 @@ diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml index 898d64e61cb..464e1434a7b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/CustomUserSettingsDeploymentStep.Fields.Thumbnail.cshtml @@ -1,4 +1,2 @@ -@model dynamic -

@T["Custom User Settings"]

@T["Exports all or specified custom user settings."]

From 1fc8b05cefa7e16b94aab72f766d003b363f3fb1 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Thu, 28 Sep 2023 14:55:11 +0200 Subject: [PATCH 18/42] CR changes --- .../OrchardCore.Users/Recipes/CustomUserSettingsStep.cs | 2 +- .../OrchardCore.Users/Recipes/UsersStep.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs index d2e20c5d3f0..020ca9d8cb9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -24,7 +24,7 @@ public CustomUserSettingsStep(ISession session) public async Task ExecuteAsync(RecipeExecutionContext context) { - if (!String.Equals(context.Name, "custom-user-settings", StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(context.Name, "custom-user-settings", StringComparison.OrdinalIgnoreCase)) { return; } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index 9cc30ad2cb7..64763e6c886 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -23,7 +23,7 @@ public UsersStep( public async Task ExecuteAsync(RecipeExecutionContext context) { - if (!String.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(context.Name, "Users", StringComparison.OrdinalIgnoreCase)) { return; } @@ -32,7 +32,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) foreach (var importedUser in model.Users) { - if (String.IsNullOrWhiteSpace(importedUser.UserName)) + if (string.IsNullOrWhiteSpace(importedUser.UserName)) { continue; } From f7a953849312b9281c8d18de408d2a5a07c87c2d Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Thu, 28 Sep 2023 15:00:57 +0200 Subject: [PATCH 19/42] CR Changes --- .../CustomUserSettingsDeploymentSource.cs | 4 +- .../Recipes/CustomUserSettingsStep.cs | 87 +++++++++---------- .../AllUsersDeploymentStep.Thumbnail.cshtml | 2 - 3 files changed, 45 insertions(+), 48 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs index ff9db749f2a..f1ac4aa07a9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/CustomUserSettingsDeploymentSource.cs @@ -28,8 +28,8 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan } var settingsTypes = customUserSettingsStep.IncludeAll - ? _customUserSettingsService.GetAllSettingsTypes().ToArray() - : _customUserSettingsService.GetSettingsTypes(customUserSettingsStep.SettingsTypeNames).ToArray(); + ? _customUserSettingsService.GetAllSettingsTypes().ToList() + : _customUserSettingsService.GetSettingsTypes(customUserSettingsStep.SettingsTypeNames).ToList(); // Todo: check permissions for each settings type var userData = new JArray(); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs index 020ca9d8cb9..5709443275d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -8,64 +8,63 @@ using OrchardCore.Users.Models; using YesSql; -namespace OrchardCore.Users.Recipes +namespace OrchardCore.Users.Recipes; + +/// +/// This recipe step updates the custom user settings. +/// +public class CustomUserSettingsStep : IRecipeStepHandler { - /// - /// This recipe step updates the custom user settings. - /// - public class CustomUserSettingsStep : IRecipeStepHandler + private readonly ISession _session; + + public CustomUserSettingsStep(ISession session) { - private readonly ISession _session; + _session = session; + } - public CustomUserSettingsStep(ISession session) + public async Task ExecuteAsync(RecipeExecutionContext context) + { + if (!string.Equals(context.Name, "custom-user-settings", StringComparison.OrdinalIgnoreCase)) { - _session = session; + return; } - public async Task ExecuteAsync(RecipeExecutionContext context) - { - if (!string.Equals(context.Name, "custom-user-settings", StringComparison.OrdinalIgnoreCase)) - { - return; - } + var model = context.Step; - var model = context.Step; + var customUserSettingsList = (JArray)model + .Properties() + .Where(p => p.Name != "name") + .FirstOrDefault() + ?.Value; - var customUserSettingsList = (JArray)model - .Properties() - .Where(p => p.Name != "name") - .FirstOrDefault() - ?.Value; + var allUsers = await _session.Query().ListAsync(); - var allUsers = await _session.Query().ListAsync(); + foreach (JObject userCustomUserSettings in customUserSettingsList.Cast()) + { + var userId = userCustomUserSettings + .Properties() + .FirstOrDefault(p => p.Name == "userId")? + .Value + ?.ToString(); - foreach (JObject userCustomUserSettings in customUserSettingsList.Cast()) + var iUser = allUsers.FirstOrDefault(u => u.UserId == userId); + if (iUser is not User user) { - var userId = userCustomUserSettings - .Properties() - .FirstOrDefault(p => p.Name == "userId")? - .Value - ?.ToString(); - - var iUser = allUsers.FirstOrDefault(u => u.UserId == userId); - if (iUser is not User user) - { - continue; - } - - var userSettings = (JArray)userCustomUserSettings - .Properties() - .FirstOrDefault(p => p.Name == "user-custom-user-settings") - ?.Value; + continue; + } - foreach (JObject userSetting in userSettings.Cast()) - { - var contentItem = userSetting.ToObject(); - user.Properties[contentItem.ContentType] = userSetting; - } + var userSettings = (JArray)userCustomUserSettings + .Properties() + .FirstOrDefault(p => p.Name == "user-custom-user-settings") + ?.Value; - _session.Save(user); + foreach (JObject userSetting in userSettings.Cast()) + { + var contentItem = userSetting.ToObject(); + user.Properties[contentItem.ContentType] = userSetting; } + + _session.Save(user); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml index d3654b3e39c..93e48763505 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Items/AllUsersDeploymentStep.Thumbnail.cshtml @@ -1,4 +1,2 @@ -@model dynamic -

@T["All Users"]

@T["Exports every user."]

From 94050b0aff79f10c55156ab2da52a5014608f136 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Thu, 28 Sep 2023 18:17:30 +0200 Subject: [PATCH 20/42] Quick refactor --- .../OrchardCore.Users/Recipes/CustomUserSettingsStep.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs index 5709443275d..ef64f821952 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -54,9 +54,9 @@ public async Task ExecuteAsync(RecipeExecutionContext context) } var userSettings = (JArray)userCustomUserSettings - .Properties() - .FirstOrDefault(p => p.Name == "user-custom-user-settings") - ?.Value; + .Properties() + .FirstOrDefault(p => p.Name == "user-custom-user-settings") + ?.Value; foreach (JObject userSetting in userSettings.Cast()) { From bf4b21cf00a13dd7496196069c9ff3a4c6f05a5f Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Thu, 28 Sep 2023 19:33:41 +0200 Subject: [PATCH 21/42] CR cleanup --- .../Recipes/CustomUserSettingsStep.cs | 10 +++++----- .../Services/CustomUserSettingsService.cs | 12 +++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs index ef64f821952..2101a11eaae 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -32,10 +32,10 @@ public async Task ExecuteAsync(RecipeExecutionContext context) var model = context.Step; var customUserSettingsList = (JArray)model - .Properties() - .Where(p => p.Name != "name") - .FirstOrDefault() - ?.Value; + .Properties() + .Where(p => p.Name != "name") + .FirstOrDefault() + ?.Value; var allUsers = await _session.Query().ListAsync(); @@ -48,7 +48,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) ?.ToString(); var iUser = allUsers.FirstOrDefault(u => u.UserId == userId); - if (iUser is not User user) + if (iUser is not User _) { continue; } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs index 75c08edbad5..f4b923f946b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/CustomUserSettingsService.cs @@ -35,16 +35,14 @@ public CustomUserSettingsService( _contentDefinitionManager = contentDefinitionManager; _settingsTypes = new Lazy>( () => _contentDefinitionManager - .ListTypeDefinitions() - .Where(x => x.StereotypeEquals("CustomUserSettings")) - .ToDictionary(x => x.Name)); + .ListTypeDefinitions() + .Where(x => x.StereotypeEquals("CustomUserSettings")) + .ToDictionary(x => x.Name)); + _session = session; } - public IEnumerable GetAllSettingsTypeNames() - { - return _settingsTypes.Value.Keys; - } + public IEnumerable GetAllSettingsTypeNames() => _settingsTypes.Value.Keys; public IEnumerable GetAllSettingsTypes() { From 173c933bb84f318768e1e7ab072bfd615d67cd85 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Thu, 28 Sep 2023 21:24:12 +0200 Subject: [PATCH 22/42] CR cleanup --- .../OrchardCore.Users/Recipes/CustomUserSettingsStep.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs index 2101a11eaae..58e73950933 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/CustomUserSettingsStep.cs @@ -47,8 +47,8 @@ public async Task ExecuteAsync(RecipeExecutionContext context) .Value ?.ToString(); - var iUser = allUsers.FirstOrDefault(u => u.UserId == userId); - if (iUser is not User _) + var user = allUsers.FirstOrDefault(u => u.UserId == userId); + if (user is not User _) { continue; } From 55e81e465a890722d5d7a8e6eee1e2c1f9064df5 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:06:06 +0300 Subject: [PATCH 23/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 4253e1d62ca..4b5ff2c7e6f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -10,7 +10,8 @@ public class UsersStepUserModel public string Email { get; set; } public string PasswordHash { get; set; } public bool EmailConfirmed { get; set; } - public bool IsEnabled { get; set; } = true; + public bool Enabled { get; set; } = true; + public string NormalizedEmail { get; set; } public string NormalizedUserName { get; set; } public string SecurityStamp { get; set; } From 60fa9d4b34f8a56434b2cb10a30bbfadfa9ee04f Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:07:23 +0300 Subject: [PATCH 24/42] Update src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs --- src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index 64763e6c886..ee5794ef6bd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -48,7 +48,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) user.UserName = importedUser.UserName; user.EmailConfirmed = importedUser.EmailConfirmed; user.PasswordHash = importedUser.PasswordHash; - user.IsEnabled = importedUser.IsEnabled; + user.Enabled = importedUser.Enabled; user.NormalizedEmail = importedUser.NormalizedEmail; user.NormalizedUserName = importedUser.NormalizedUserName; user.SecurityStamp = importedUser.SecurityStamp; From fddb800c7a2790f24010d4a38b54e661fd585f6a Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:08:05 +0300 Subject: [PATCH 25/42] Update src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs --- .../ViewModels/CustomUserSettingsDeploymentStepViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs index 6a8da1ddf6c..faa9d1f73dd 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs @@ -3,6 +3,7 @@ namespace OrchardCore.Users.ViewModels; public class CustomUserSettingsDeploymentStepViewModel { public bool IncludeAll { get; set; } + public string[] SettingsTypeNames { get; set; } public string[] AllSettingsTypeNames { get; set; } } From fc587429db434031e70235fe46fa492b2fc083aa Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:10:17 +0300 Subject: [PATCH 26/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 4b5ff2c7e6f..89d62517d18 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -20,6 +20,7 @@ public class UsersStepUserModel public bool PhoneNumberConfirmed { get; set; } public bool TwoFactorEnabled { get; set; } public bool IsLockoutEnabled { get; set; } + public int AccessFailedCount { get; set; } public IList RoleNames { get; set; } } From b51dc2c2a9e908a79abd1e9c37ec4b44a257e1fd Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:12:21 +0300 Subject: [PATCH 27/42] Update src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs --- .../ViewModels/CustomUserSettingsDeploymentStepViewModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs index faa9d1f73dd..6f77a0449fe 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/CustomUserSettingsDeploymentStepViewModel.cs @@ -5,5 +5,6 @@ public class CustomUserSettingsDeploymentStepViewModel public bool IncludeAll { get; set; } public string[] SettingsTypeNames { get; set; } + public string[] AllSettingsTypeNames { get; set; } } From 480e01da5af0e5a94fdbb0db914f5c3198c50a46 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:13:03 +0300 Subject: [PATCH 28/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 89d62517d18..ec23d828b7c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -5,6 +5,7 @@ namespace OrchardCore.Users.Models; public class UsersStepUserModel { public long Id { get; set; } + public string UserId { get; set; } public string UserName { get; set; } public string Email { get; set; } From 28ac1df21deec26d8303fcc77467e8344eb9425e Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:17:51 +0200 Subject: [PATCH 29/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index ec23d828b7c..7507758846f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -7,6 +7,7 @@ public class UsersStepUserModel public long Id { get; set; } public string UserId { get; set; } + public string UserName { get; set; } public string Email { get; set; } public string PasswordHash { get; set; } From b37e14e34571b4e9411c12f40e2507c06009ba98 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:18:27 +0200 Subject: [PATCH 30/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 7507758846f..5c23c050c8a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -21,6 +21,7 @@ public class UsersStepUserModel public string PhoneNumber { get; set; } public bool PhoneNumberConfirmed { get; set; } public bool TwoFactorEnabled { get; set; } + public bool IsLockoutEnabled { get; set; } public int AccessFailedCount { get; set; } From 89d358920135fa8ed193bc2147af276e0dbde1c0 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:18:37 +0200 Subject: [PATCH 31/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 5c23c050c8a..1a59ebcb461 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -19,6 +19,7 @@ public class UsersStepUserModel public string SecurityStamp { get; set; } public string ResetToken { get; set; } public string PhoneNumber { get; set; } + public bool PhoneNumberConfirmed { get; set; } public bool TwoFactorEnabled { get; set; } From f126fa9521ef896a159c46e6872668c66a41ec0f Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:18:48 +0300 Subject: [PATCH 32/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 1a59ebcb461..82f774bfa18 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -21,6 +21,7 @@ public class UsersStepUserModel public string PhoneNumber { get; set; } public bool PhoneNumberConfirmed { get; set; } + public bool TwoFactorEnabled { get; set; } public bool IsLockoutEnabled { get; set; } From 5cd5a0c2dd896471b1598fb1428063a417ba4a3d Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:19:32 +0200 Subject: [PATCH 33/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 82f774bfa18..96f5edf44ff 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -9,6 +9,7 @@ public class UsersStepUserModel public string UserId { get; set; } public string UserName { get; set; } + public string Email { get; set; } public string PasswordHash { get; set; } public bool EmailConfirmed { get; set; } From b1ac1e1aabae06f7307fe4d815a2e93a8c0fe5b1 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:19:54 +0200 Subject: [PATCH 34/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 96f5edf44ff..a74264f9620 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -11,6 +11,7 @@ public class UsersStepUserModel public string UserName { get; set; } public string Email { get; set; } + public string PasswordHash { get; set; } public bool EmailConfirmed { get; set; } public bool Enabled { get; set; } = true; From 2cef4ed220fafa3936781048c4c7c6eadfcba293 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:20:09 +0200 Subject: [PATCH 35/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index a74264f9620..fea4b76ab5d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -13,6 +13,7 @@ public class UsersStepUserModel public string Email { get; set; } public string PasswordHash { get; set; } + public bool EmailConfirmed { get; set; } public bool Enabled { get; set; } = true; From ed777b7de1d4ced39af63af55f909fd7d62ed7c2 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:20:35 +0200 Subject: [PATCH 36/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index fea4b76ab5d..ab29dd85d4a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -15,6 +15,7 @@ public class UsersStepUserModel public string PasswordHash { get; set; } public bool EmailConfirmed { get; set; } + public bool Enabled { get; set; } = true; public string NormalizedEmail { get; set; } From 090d2d921d28b87541ed4d1db99ba40dac253530 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:20:59 +0200 Subject: [PATCH 37/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index ab29dd85d4a..cd565333cc4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -31,5 +31,6 @@ public class UsersStepUserModel public bool IsLockoutEnabled { get; set; } public int AccessFailedCount { get; set; } + public IList RoleNames { get; set; } } From 683d429395b3773417296614eae23e58935998cd Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:21:16 +0200 Subject: [PATCH 38/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index cd565333cc4..674bd7df748 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -20,6 +20,7 @@ public class UsersStepUserModel public string NormalizedEmail { get; set; } public string NormalizedUserName { get; set; } + public string SecurityStamp { get; set; } public string ResetToken { get; set; } public string PhoneNumber { get; set; } From 5fea5d89620ba49d336429a8eeb3a36702f9cb3b Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:21:38 +0200 Subject: [PATCH 39/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 674bd7df748..bb55edd1aa6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -22,6 +22,7 @@ public class UsersStepUserModel public string NormalizedUserName { get; set; } public string SecurityStamp { get; set; } + public string ResetToken { get; set; } public string PhoneNumber { get; set; } From 5bd124f00217f2e4383c98e18aa0d0efe6c0abf3 Mon Sep 17 00:00:00 2001 From: Szymon Seliga Date: Sat, 21 Oct 2023 10:22:14 +0200 Subject: [PATCH 40/42] Update src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index bb55edd1aa6..6849965e65d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -19,6 +19,7 @@ public class UsersStepUserModel public bool Enabled { get; set; } = true; public string NormalizedEmail { get; set; } + public string NormalizedUserName { get; set; } public string SecurityStamp { get; set; } From bf483bc1a9f550e2f236e3c08a89af79aa12a0c5 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:29:34 +0300 Subject: [PATCH 41/42] Update src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs --- .../OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs index b20349e2193..6c5dad3f324 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs @@ -37,7 +37,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan Email = user.Email, EmailConfirmed = user.EmailConfirmed, PasswordHash = user.PasswordHash, - IsEnabled = user.IsEnabled, + Enabled = user.Enabled, NormalizedEmail = user.NormalizedEmail, NormalizedUserName = user.NormalizedUserName, SecurityStamp = user.SecurityStamp, From 9cd2372e96c914220dc01713eb84aa066d2617f0 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 21 Oct 2023 11:36:42 +0300 Subject: [PATCH 42/42] Apply suggestions from code review --- .../OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs | 2 +- .../OrchardCore.Users/Models/UsersStepUserModel.cs | 2 +- src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs index 6c5dad3f324..b20349e2193 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Deployment/AllUsersDeploymentSource.cs @@ -37,7 +37,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan Email = user.Email, EmailConfirmed = user.EmailConfirmed, PasswordHash = user.PasswordHash, - Enabled = user.Enabled, + IsEnabled = user.IsEnabled, NormalizedEmail = user.NormalizedEmail, NormalizedUserName = user.NormalizedUserName, SecurityStamp = user.SecurityStamp, diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs index 6849965e65d..5b38e5be2bc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Models/UsersStepUserModel.cs @@ -16,7 +16,7 @@ public class UsersStepUserModel public bool EmailConfirmed { get; set; } - public bool Enabled { get; set; } = true; + public bool IsEnabled { get; set; } = true; public string NormalizedEmail { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs index ee5794ef6bd..64763e6c886 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Recipes/UsersStep.cs @@ -48,7 +48,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context) user.UserName = importedUser.UserName; user.EmailConfirmed = importedUser.EmailConfirmed; user.PasswordHash = importedUser.PasswordHash; - user.Enabled = importedUser.Enabled; + user.IsEnabled = importedUser.IsEnabled; user.NormalizedEmail = importedUser.NormalizedEmail; user.NormalizedUserName = importedUser.NormalizedUserName; user.SecurityStamp = importedUser.SecurityStamp;