Skip to content

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.

Admin - move action ChangeStore from SettingsController to the HomepageController (user without access to the settings can't change the store)

KrzysztofPajakb8a47ff37635
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Components/StoreScope/Default.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Components/StoreScope/Default.cshtml
index 3a6063c23..b214ac242 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Components/StoreScope/Default.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Shared/Components/StoreScope/Default.cshtml
@@ -4,7 +4,7 @@
var stores = Model.Stores.Select(store => new SelectListItem
{
Text = store.Name,
- Value = Url.Action("ChangeStore", "Setting", new { storeid = store.Id, returnurl = rawUrl, area = Constants.AreaAdmin }),
+ Value = Url.Action("ChangeStore", "Home", new { storeid = store.Id, returnurl = rawUrl, area = Constants.AreaAdmin }),
Selected = store.Id.Equals(Model.StoreId)
})
.ToList();
diff --git a/src/Web/Grand.Web.Admin/Components/StoreScope.cs b/src/Web/Grand.Web.Admin/Components/StoreScope.cs
index 3bedc8d6b..f97f40bf7 100644
--- a/src/Web/Grand.Web.Admin/Components/StoreScope.cs
+++ b/src/Web/Grand.Web.Admin/Components/StoreScope.cs
@@ -6,6 +6,8 @@ using Grand.Web.Common.Components;
using Grand.Web.Admin.Models.Settings;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
+using Grand.Business.Common.Interfaces.Directory;
+using System.Linq;
namespace Grand.Web.Admin.Components
{
@@ -15,15 +17,17 @@ namespace Grand.Web.Admin.Components
private readonly IStoreService _storeService;
private readonly IWorkContext _workContext;
+ private readonly IGroupService _groupService;
#endregion
#region Constructors
- public StoreScopeViewComponent(IStoreService storeService, IWorkContext workContext)
+ public StoreScopeViewComponent(IStoreService storeService, IWorkContext workContext, IGroupService groupService)
{
_storeService = storeService;
_workContext = workContext;
+ _groupService = groupService;
}
#endregion
@@ -36,6 +40,9 @@ namespace Grand.Web.Admin.Components
if (allStores.Count < 2)
return Content("");
+ if (await _groupService.IsStaff(_workContext.CurrentCustomer))
+ allStores = allStores.Where(x => x.Id == _workContext.CurrentCustomer.StaffStoreId).ToList();
+
var model = new StoreScopeModel();
foreach (var s in allStores)
{
diff --git a/src/Web/Grand.Web.Admin/Controllers/CommonController.cs b/src/Web/Grand.Web.Admin/Controllers/CommonController.cs
index 69b345912..9d8b2a7a4 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CommonController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CommonController.cs
@@ -12,7 +12,6 @@ using Grand.Business.Customers.Interfaces;
using Grand.Business.Storage.Interfaces;
using Grand.Business.System.Commands.Models.Common;
using Grand.Business.System.Interfaces.MachineNameProvider;
-using Grand.Domain.Data;
using Grand.Domain.Directory;
using Grand.Domain.Media;
using Grand.Domain.Seo;
diff --git a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
index 7eae8adf8..54d2dd652 100644
--- a/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/HomeController.cs
@@ -4,6 +4,7 @@ using Grand.Business.Common.Extensions;
using Grand.Business.Common.Interfaces.Directory;
using Grand.Business.Common.Interfaces.Localization;
using Grand.Business.Common.Interfaces.Logging;
+using Grand.Business.Common.Interfaces.Stores;
using Grand.Business.Customers.Queries.Models;
using Grand.Business.System.Interfaces.Reports;
using Grand.Domain.Customers;
@@ -27,6 +28,8 @@ namespace Grand.Web.Admin.Controllers
#region Fields
private readonly ITranslationService _translationService;
+ private readonly IStoreService _storeService;
+ private readonly IUserFieldService _userFieldService;
private readonly GoogleAnalyticsSettings _googleAnalyticsSettings;
private readonly IWorkContext _workContext;
private readonly IGroupService _groupService;
@@ -42,6 +45,8 @@ namespace Grand.Web.Admin.Controllers
public HomeController(
ITranslationService translationService,
+ IStoreService storeService,
+ IUserFieldService userFieldService,
GoogleAnalyticsSettings googleAnalyticsSettings,
IWorkContext workContext,
IGroupService groupService,
@@ -52,6 +57,8 @@ namespace Grand.Web.Admin.Controllers
IMediator mediator)
{
_translationService = translationService;
+ _storeService = storeService;
+ _userFieldService = userFieldService;
_googleAnalyticsSettings = googleAnalyticsSettings;
_workContext = workContext;
_groupService = groupService;
@@ -142,6 +149,31 @@ namespace Grand.Web.Admin.Controllers
return Redirect(returnUrl);
}
+ public async Task<IActionResult> ChangeStore(string storeid, string returnUrl = "")
+ {
+ if (storeid != null)
+ storeid = storeid.Trim();
+
+ if (await _groupService.IsStaff(_workContext.CurrentCustomer))
+ returnUrl = Url.Action("Index", "Home", new { area = Constants.AreaAdmin });
+
+ var store = await _storeService.GetStoreById(storeid);
+ if (store != null || storeid == "")
+ {
+ await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, storeid);
+ }
+ else
+ await _userFieldService.SaveField(_workContext.CurrentCustomer,
+ SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, "");
+
+ //home page
+ if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
+ returnUrl = Url.Action("Index", "Home", new { area = Constants.AreaAdmin });
+
+ return Redirect(returnUrl);
+ }
+
[AcceptVerbs("Get")]
public async Task<IActionResult> GetStatesByCountryId([FromServices] ICountryService countryService,
string countryId, bool? addSelectStateItem, bool? addAsterisk)
diff --git a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs b/src/Web/Grand.Web.Admin/Controllers/SettingController.cs
index 4e88cdf51..3be4532b3 100644
--- a/src/Web/Grand.Web.Admin/Controllers/SettingController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/SettingController.cs
@@ -64,7 +64,6 @@ namespace Grand.Web.Admin.Controllers
private readonly ICustomerActivityService _customerActivityService;
private readonly IStoreService _storeService;
private readonly IWorkContext _workContext;
- private readonly IUserFieldService _userFieldService;
private readonly IMediator _mediator;
private readonly IMerchandiseReturnService _merchandiseReturnService;
private readonly ILanguageService _languageService;
@@ -76,20 +75,14 @@ namespace Grand.Web.Admin.Controllers
#region Constructors
public SettingController(ISettingService settingService,
- ICountryService countryService,
- ITaxCategoryService taxCategoryService,
ICurrencyService currencyService,
IPictureService pictureService,
ITranslationService translationService,
IDateTimeService dateTimeService,
- IOrderService orderService,
- IEncryptionService encryptionService,
IThemeProvider themeProvider,
- ICustomerService customerService,
ICustomerActivityService customerActivityService,
IStoreService storeService,
IWorkContext workContext,
- IUserFieldService userFieldService,
IMediator mediator,
IMerchandiseReturnService merchandiseReturnService,
ILanguageService languageService,
@@ -105,7 +98,6 @@ namespace Grand.Web.Admin.Controllers
_customerActivityService = customerActivityService;
_storeService = storeService;
_workContext = workContext;
- _userFieldService = userFieldService;
_mediator = mediator;
_merchandiseReturnService = merchandiseReturnService;
_languageService = languageService;
@@ -123,30 +115,6 @@ namespace Grand.Web.Admin.Controllers
await _cacheBase.Clear();
}
- public async Task<IActionResult> ChangeStore(string storeid, string returnUrl = "")
- {
- if (storeid != null)
- storeid = storeid.Trim();
-
- var store = await _storeService.GetStoreById(storeid);
- if (store != null || storeid == "")
- {
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
- SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, storeid);
- }
- else
- await _userFieldService.SaveField(_workContext.CurrentCustomer,
- SystemCustomerFieldNames.AdminAreaStoreScopeConfiguration, "");
-
-
- //home page
- if (String.IsNullOrEmpty(returnUrl))
- returnUrl = Url.Action("Index", "Home", new { area = Constants.AreaAdmin });
- //prevent open redirection attack
- if (!Url.IsLocalUrl(returnUrl))
- return RedirectToAction("Index", "Home", new { area = Constants.AreaAdmin });
- return Redirect(returnUrl);
- }
public async Task<IActionResult> Content()
{
//load settings for a chosen store scope