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
fix(arch001): guard SearchStoreId forcing so Admin's submitted store filter isn't overwritten (final review fix)
KrzysztofPajak959894173bdd
diff --git a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.cs b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.csindex de40bdb57..a356d767c 100644--- a/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.cs+++ b/src/Tests/Grand.Web.Admin.Tests/Controllers/BaseCategoryControllerTests.cs@@ -112,6 +112,20 @@ public class BaseCategoryControllerTestsAssert.AreEqual("store-1", model.SearchStoreId);}+ [TestMethod]+ public async Task ListPost_GlobalScope_LeavesSubmittedSearchStoreIdUntouched()+ {+ _scopeMock.Setup(s => s.DefaultStoreId).Returns((string)null);+ _categoryViewModelServiceMock+ .Setup(v => v.PrepareCategoryListModel(It.IsAny<CategoryListModel>(), 1, 10))+ .ReturnsAsync((Enumerable.Empty<CategoryModel>(), 0));++ var model = new CategoryListModel { SearchStoreId = "admin-submitted-store" };+ await _controller.List(new DataSourceRequest { Page = 1, PageSize = 10 }, model);++ Assert.AreEqual("admin-submitted-store", model.SearchStoreId);+ }+// --- Edit (GET) --------------------------------------------------------------------------------[TestMethod]@@ -471,6 +485,20 @@ public class BaseCategoryControllerTests_categoryViewModelServiceMock.Verify(v => v.InsertCategoryProductModel(It.IsAny<CategoryModel.AddCategoryProductModel>()), Times.Never);}+ [TestMethod]+ public async Task ProductAddPopupList_GlobalScope_LeavesSubmittedSearchStoreIdUntouched()+ {+ _scopeMock.Setup(s => s.DefaultStoreId).Returns((string)null);+ _categoryViewModelServiceMock+ .Setup(v => v.PrepareProductModel(It.IsAny<CategoryModel.AddCategoryProductModel>(), 1, 10))+ .ReturnsAsync((new List<ProductModel>(), 0));++ var model = new CategoryModel.AddCategoryProductModel { SearchStoreId = "admin-submitted-store" };+ await _controller.ProductAddPopupList(new DataSourceRequest { Page = 1, PageSize = 10 }, model);++ Assert.AreEqual("admin-submitted-store", model.SearchStoreId);+ }+[TestMethod]public async Task ProductDelete_ProductNotOwnedByScopeStore_ReturnsKendoError(){diff --git a/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.cs b/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.csindex 7f3f838eb..255859132 100644--- a/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.cs+++ b/src/Web/Grand.Web.AdminShared/Controllers/BaseCategoryController.cs@@ -61,7 +61,7 @@ public abstract class BaseCategoryController([HttpPost]public async Task<IActionResult> List(DataSourceRequest command, CategoryListModel model){- model.SearchStoreId = scope.DefaultStoreId;+ if (scope.DefaultStoreId is not null) model.SearchStoreId = scope.DefaultStoreId;var categories = await categoryViewModelService.PrepareCategoryListModel(model, command.Page, command.PageSize);var gridModel = new DataSourceResult {Data = categories.categoryListModel,@@ -320,7 +320,7 @@ public abstract class BaseCategoryController(public async Task<IActionResult> ProductAddPopupList(DataSourceRequest command, CategoryModel.AddCategoryProductModel model){var gridModel = new DataSourceResult();- model.SearchStoreId = scope.DefaultStoreId;+ if (scope.DefaultStoreId is not null) model.SearchStoreId = scope.DefaultStoreId;var products = await categoryViewModelService.PrepareProductModel(model, command.Page, command.PageSize);gridModel.Data = products.products.ToList();gridModel.Total = products.totalCount;