From 9bb48218868c5c25c730826d3da43963d3a02fbe Mon Sep 17 00:00:00 2001 From: Aleksandr Andreev Date: Tue, 28 May 2019 15:37:27 +0300 Subject: [PATCH 1/3] add and use NonEditableUsers setting --- .../PlatformConstants.cs | 12 ++++++++-- VirtoCommerce.Platform.Web/Startup.cs | 22 +++++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/VirtoCommerce.Platform.Core/PlatformConstants.cs b/VirtoCommerce.Platform.Core/PlatformConstants.cs index a0e7a8120..091b0af3f 100644 --- a/VirtoCommerce.Platform.Core/PlatformConstants.cs +++ b/VirtoCommerce.Platform.Core/PlatformConstants.cs @@ -125,7 +125,6 @@ public static class Setup ValueType = SettingValueType.ShortText, DefaultValue = null }; - public static SettingDescriptor SampleDataState = new SettingDescriptor { Name = "VirtoCommerce.SampleDataState", @@ -140,7 +139,6 @@ public static class Setup ValueType = SettingValueType.ShortText, DefaultValue = AutoInstallState.Undefined }; - public static SettingDescriptor ModulesAutoInstalled = new SettingDescriptor { Name = "VirtoCommerce.ModulesAutoInstalled", @@ -148,6 +146,15 @@ public static class Setup ValueType = SettingValueType.Boolean, DefaultValue = false }; + public static SettingDescriptor NonEditableUsers = new SettingDescriptor + { + Name = "VirtoCommerce.NonEditableUsers", + GroupName = "Platform|Setup", + ValueType = SettingValueType.ShortText, + DefaultValue = null, + RestartRequired = true + }; + public static IEnumerable AllSettings { get @@ -156,6 +163,7 @@ public static IEnumerable AllSettings yield return SampleDataState; yield return ModulesAutoInstallState; yield return ModulesAutoInstalled; + yield return NonEditableUsers; } } } diff --git a/VirtoCommerce.Platform.Web/Startup.cs b/VirtoCommerce.Platform.Web/Startup.cs index 4adbfa960..5751b44fa 100644 --- a/VirtoCommerce.Platform.Web/Startup.cs +++ b/VirtoCommerce.Platform.Web/Startup.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using System.Net; @@ -30,6 +31,7 @@ using VirtoCommerce.Platform.Core.Jobs; using VirtoCommerce.Platform.Core.Modularity; using VirtoCommerce.Platform.Core.Security; +using VirtoCommerce.Platform.Core.Settings; using VirtoCommerce.Platform.Data.Extensions; using VirtoCommerce.Platform.Data.PushNotifications; using VirtoCommerce.Platform.Data.Repositories; @@ -143,10 +145,8 @@ public void ConfigureServices(IServiceCollection services) }); services.AddAuthentication().AddCookie(); - services.AddSecurityServices(options => - { - options.NonEditableUsers = new[] { "admin" }; - }); + + services.AddSecurityServices(); services.AddIdentity(options => options.Stores.MaxLengthForKeys = 128) .AddEntityFrameworkStores() @@ -315,12 +315,13 @@ public void ConfigureServices(IServiceCollection services) services.AddHangfire(config => config.UseMemoryStorage()); } - var mvcJsonOptions = services.BuildServiceProvider().GetService>(); + var mvcJsonOptions = services. + BuildServiceProvider().GetService>(); JobHelper.SetSerializerSettings(mvcJsonOptions.Value.SerializerSettings); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceCollection services, ISettingsManager settingManager, IOptions securityOptions) { if (env.IsDevelopment()) @@ -397,15 +398,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseDbTriggers(); //Register platform settings app.UsePlatformSettings(); + var nonEditableUsers = settingManager.GetValue(PlatformConstants.Settings.Setup.NonEditableUsers.Name, string.Empty); + securityOptions.Value.NonEditableUsers = nonEditableUsers.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + app.UseModules(); //Register platform permissions app.UsePlatformPermissions(); //Setup SignalR hub app.UseSignalR(routes => - { - routes.MapHub("/pushNotificationHub"); - }); + { + routes.MapHub("/pushNotificationHub"); + }); //Seed default users app.UseDefaultUsersAsync().GetAwaiter().GetResult(); From 0244a610654a21371c3c75bbb6cdcb72e1766c4a Mon Sep 17 00:00:00 2001 From: Aleksandr Andreev Date: Tue, 28 May 2019 15:40:43 +0300 Subject: [PATCH 2/3] reformat --- VirtoCommerce.Platform.Web/Startup.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/VirtoCommerce.Platform.Web/Startup.cs b/VirtoCommerce.Platform.Web/Startup.cs index 5751b44fa..87882f036 100644 --- a/VirtoCommerce.Platform.Web/Startup.cs +++ b/VirtoCommerce.Platform.Web/Startup.cs @@ -315,8 +315,7 @@ public void ConfigureServices(IServiceCollection services) services.AddHangfire(config => config.UseMemoryStorage()); } - var mvcJsonOptions = services. - BuildServiceProvider().GetService>(); + var mvcJsonOptions = services.BuildServiceProvider().GetService>(); JobHelper.SetSerializerSettings(mvcJsonOptions.Value.SerializerSettings); } @@ -407,9 +406,9 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IService //Setup SignalR hub app.UseSignalR(routes => - { - routes.MapHub("/pushNotificationHub"); - }); + { + routes.MapHub("/pushNotificationHub"); + }); //Seed default users app.UseDefaultUsersAsync().GetAwaiter().GetResult(); From 475d174537ddd29552f589430172bcf11f07e72c Mon Sep 17 00:00:00 2001 From: Aleksandr Andreev Date: Tue, 28 May 2019 15:41:52 +0300 Subject: [PATCH 3/3] reformat --- VirtoCommerce.Platform.Web/Startup.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/VirtoCommerce.Platform.Web/Startup.cs b/VirtoCommerce.Platform.Web/Startup.cs index 87882f036..4703563ba 100644 --- a/VirtoCommerce.Platform.Web/Startup.cs +++ b/VirtoCommerce.Platform.Web/Startup.cs @@ -145,7 +145,6 @@ public void ConfigureServices(IServiceCollection services) }); services.AddAuthentication().AddCookie(); - services.AddSecurityServices(); services.AddIdentity(options => options.Stores.MaxLengthForKeys = 128)