Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Lock system-wide settings in store panel & add "All stores" scope in admin (#724)
Krzysztof Pajak6631acb3ff3f
diff --git a/src/Web/Grand.Web.Admin/Components/StoreScope.cs b/src/Web/Grand.Web.Admin/Components/StoreScope.csindex 340819741..200b5ae38 100644--- a/src/Web/Grand.Web.Admin/Components/StoreScope.cs+++ b/src/Web/Grand.Web.Admin/Components/StoreScope.cs@@ -1,6 +1,5 @@-using Grand.Business.Core.Interfaces.Common.Directory;+using Grand.Business.Core.Interfaces.Common.Localization;using Grand.Business.Core.Interfaces.Common.Stores;-using Grand.Infrastructure;using Grand.Web.AdminShared.Models.Settings;using Grand.Web.Common.Components;using Grand.Web.Common.Helpers;@@ -15,9 +14,8 @@ public class StoreScopeViewComponent : BaseAdminViewComponent#region Fieldsprivate readonly IStoreService _storeService;- private readonly IContextAccessor _contextAccessor;- private readonly IGroupService _groupService;private readonly IAdminStoreService _adminStoreService;+ private readonly ITranslationService _translationService;#endregion@@ -26,13 +24,11 @@ public class StoreScopeViewComponent : BaseAdminViewComponentpublic StoreScopeViewComponent(IStoreService storeService,IAdminStoreService adminStoreService,- IGroupService groupService,- IContextAccessor contextAccessor)+ ITranslationService translationService){_adminStoreService = adminStoreService;_storeService = storeService;- _contextAccessor = contextAccessor;- _groupService = groupService;+ _translationService = translationService;}#endregion@@ -45,10 +41,14 @@ public class StoreScopeViewComponent : BaseAdminViewComponentif (allStores.Count < 2)return Content("");- if (await _groupService.IsStoreManager(_contextAccessor.WorkContext.CurrentCustomer))- allStores = allStores.Where(x => x.Id == _contextAccessor.WorkContext.CurrentCustomer.StaffStoreId).ToList();-var model = new StoreScopeModel();++ //global scope (all stores)+ model.Stores.Add(new StoreModel {+ Id = "",+ Name = _translationService.GetResource("Admin.Settings.StoreScope.AllStores")+ });+foreach (var s in allStores)model.Stores.Add(new StoreModel {Id = s.Id,diff --git a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.csindex 49774c2b5..786c7e428 100644--- a/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/BaseAdminController.cs@@ -1,5 +1,4 @@-using Grand.Business.Core.Interfaces.Common.Directory;-using Grand.Business.Core.Interfaces.Common.Stores;+using Grand.Business.Core.Interfaces.Common.Stores;using Grand.Domain.Common;using Grand.Domain.Customers;using Grand.Infrastructure;@@ -24,23 +23,21 @@ public abstract class BaseAdminController : BaseController{var storeService = HttpContext.RequestServices.GetRequiredService<IStoreService>();var workContext = HttpContext.RequestServices.GetRequiredService<IContextAccessor>().WorkContext;- var groupService = HttpContext.RequestServices.GetRequiredService<IGroupService>();var stores = await storeService.GetAllStores();if (stores.Count < 2)return stores.FirstOrDefault()?.Id;- if (await groupService.IsStoreManager(workContext.CurrentCustomer)) return workContext.CurrentCustomer.StaffStoreId;-var storeId =workContext.CurrentCustomer.GetUserFieldFromEntity<string>(SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration);+ //empty scope means "all stores" - settings are loaded from/saved to the global scopeif (string.IsNullOrEmpty(storeId)){- return stores.First()?.Id;+ return "";}var store = await storeService.GetStoreById(storeId);- return store != null ? store.Id : stores.First()?.Id;+ return store != null ? store.Id : "";}}\ No newline at end of filediff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Customer.TabCustomerSecurity.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Customer.TabCustomerSecurity.cshtmlindex 1d6321c51..6e7c142c6 100644--- a/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Customer.TabCustomerSecurity.cshtml+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Customer.TabCustomerSecurity.cshtml@@ -40,24 +40,6 @@<span asp-validation-for="CustomerSettings.TwoFactorAuthenticationType"></span></div></div>- <div class="form-group">- <div class="col-8 col-md-4 col-sm-4 text-right">- <admin-label asp-for="CustomerSettings.DefaultPasswordFormat" class="control-label"/>- </div>- <div class="col-4 col-md-8 col-sm-8">- <admin-select asp-for="CustomerSettings.DefaultPasswordFormat" asp-items="EnumTranslationService.ToSelectList((PasswordFormat)Model.CustomerSettings.DefaultPasswordFormat)"/>- <span asp-validation-for="CustomerSettings.DefaultPasswordFormat"></span>- </div>- </div>- <div class="form-group">- <div class="col-8 col-md-4 col-sm-4 text-right">- <admin-label asp-for="CustomerSettings.HashedPasswordFormat" class="control-label"/>- </div>- <div class="col-4 col-md-8 col-sm-8">- <admin-select asp-for="CustomerSettings.HashedPasswordFormat" asp-items="EnumTranslationService.ToSelectList(Model.CustomerSettings.HashedPasswordFormat)"/>- <span asp-validation-for="CustomerSettings.HashedPasswordFormat"></span>- </div>- </div><div class="form-group"><div class="col-8 col-md-4 col-sm-4 text-right"><admin-label asp-for="CustomerSettings.PasswordRegularExpression" class="control-label"/>diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Sales.TabLoyaltyPoints.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Sales.TabLoyaltyPoints.cshtmlindex c71b24ede..c64162cc9 100644--- a/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Sales.TabLoyaltyPoints.cshtml+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/Setting/Partials/Sales.TabLoyaltyPoints.cshtml@@ -103,18 +103,6 @@<span asp-validation-for="LoyaltyPointsSettings.DisplayHowMuchWillBeEarned"></span></div></div>- <div class="form-group">- <div class="col-8 col-md-4 col-sm-4 text-right">- <admin-label asp-for="LoyaltyPointsSettings.PointsAccumulatedForAllStores" class="control-label"/>- </div>- <div class="col-4 col-md-8 col-sm-8">- <label class="mt-checkbox mt-checkbox-outline control control-checkbox">- <admin-input asp-for="LoyaltyPointsSettings.PointsAccumulatedForAllStores"/>- <div class="control__indicator"></div>- </label>- <span asp-validation-for="LoyaltyPointsSettings.PointsAccumulatedForAllStores"></span>- </div>- </div></div></div><vc:admin-widget widget-zone="loyalty_points_settings_bottom" additional-data="null"/>\ No newline at end of filediff --git a/src/Web/Grand.Web.Store/Controllers/SettingController.cs b/src/Web/Grand.Web.Store/Controllers/SettingController.csindex 11aa64f11..aa716bb02 100644--- a/src/Web/Grand.Web.Store/Controllers/SettingController.cs+++ b/src/Web/Grand.Web.Store/Controllers/SettingController.cs@@ -285,7 +285,13 @@ public class SettingController(if (ModelState.IsValid){var loyaltyPointsSettings = await settingService.LoadSetting<LoyaltyPointsSettings>(storeScope);++ // Cross-store accumulation is managed by the administrator - store owners cannot change it+ var pointsAccumulatedForAllStores = loyaltyPointsSettings.PointsAccumulatedForAllStores;+loyaltyPointsSettings = model.LoyaltyPointsSettings.ToEntity(loyaltyPointsSettings);+ loyaltyPointsSettings.PointsAccumulatedForAllStores = pointsAccumulatedForAllStores;+await settingService.SaveSetting(loyaltyPointsSettings, storeScope);var shoppingCartSettings = await settingService.LoadSetting<ShoppingCartSettings>(storeScope);@@ -625,7 +631,14 @@ public class SettingController(var customerSettings = await settingService.LoadSetting<CustomerSettings>(storeScope);var addressSettings = await settingService.LoadSetting<AddressSettings>(storeScope);+ // Password storage formats are managed by the administrator - store owners cannot change them+ var defaultPasswordFormat = customerSettings.DefaultPasswordFormat;+ var hashedPasswordFormat = customerSettings.HashedPasswordFormat;+customerSettings = model.CustomerSettings.ToEntity(customerSettings);+ customerSettings.DefaultPasswordFormat = defaultPasswordFormat;+ customerSettings.HashedPasswordFormat = hashedPasswordFormat;+await settingService.SaveSetting(customerSettings, storeScope);addressSettings = model.AddressSettings.ToEntity(addressSettings);