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
Remove dead IAdminDataScope<TEntity>.ApplyScope
KrzysztofPajak332c7b28feb5
diff --git a/docs/superpowers/specs/2026-08-17-arch001-phase2-view-consolidation-design.md b/docs/superpowers/specs/2026-08-17-arch001-phase2-view-consolidation-design.mdindex cead7381b..2e85bd298 100644--- a/docs/superpowers/specs/2026-08-17-arch001-phase2-view-consolidation-design.md+++ b/docs/superpowers/specs/2026-08-17-arch001-phase2-view-consolidation-design.md@@ -567,3 +567,36 @@ consolidation, check host X's *own* codebase for the real answer (does it have ais it used elsewhere, what does `_ViewImports.cshtml` actually import) - don't infer it from whatthe entity's *original*, pre-consolidation views for that host happened to contain. A copy-pasted,never-adapted call is evidence of a pre-existing bug, not evidence the host lacks the capability.++## 8. Remove `IAdminDataScope<TEntity>.ApplyScope` (addendum, 2026-08-19)++### Problem++`ApplyScope(IQueryable<TEntity> query)` was part of the original Phase 1 interface design but never+became load-bearing: `BaseProductController` and `ProductViewModelService` scope every read+(`SearchProducts`) and write path through the `storeId`/`vendorId` parameters and `HasAccess`/+`CanView` checks instead, never through an `IQueryable` filter. Confirmed by grep across `src/Web`+and `src/Tests`: the only callers of `ApplyScope` were its own unit tests+(`GlobalAdminDataScopeTests.ApplyScope_ReturnsQueryUnchanged`,+`VendorProductDataScopeTests.ApplyScope_FiltersToOwnVendorId`) - dead production code advertising a+scoping mechanism nothing uses, flagged during the tenant-isolation audit in section 6/7's session+and removed on request rather than left to accumulate.++### Resolution++Removed the member from `IAdminDataScope<TEntity>` and its four implementations+(`GlobalAdminDataScope<TEntity>`, `StoreAdminDataScope<TEntity>`, `VendorProductDataScope`,+`RoutedProductDataScope`'s pass-through), plus the two tests that only existed to exercise it. No+other code referenced it (grep clean after removal). `IStoreLinkEntity`/`Stores`/`LimitedToStores`+filtering logic that lived inside `StoreAdminDataScope.ApplyScope` is not reproduced elsewhere - it+was never called, so there is nothing to preserve.++**If Phase 3 needs query-level scoping** (e.g. a list endpoint that filters via `IQueryable` instead+of passing a `storeId`/`vendorId` parameter into a service method, the way Product does), add the+member back on the entity/host where it is actually wired to a caller in the same change - not+speculatively ahead of a caller, which is what happened here.++### Verification++`dotnet build GrandNode.sln` clean. `Grand.Web.Admin.Tests`/`Grand.Web.Store.Tests`/+`Grand.Web.Vendor.Tests`: 419/33/8 (down 2 from the removed `ApplyScope` tests), all green.diff --git a/src/Tests/Grand.Web.Admin.Tests/Services/GlobalAdminDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Services/GlobalAdminDataScopeTests.csindex 4d4cee044..e14f3bfbd 100644--- a/src/Tests/Grand.Web.Admin.Tests/Services/GlobalAdminDataScopeTests.cs+++ b/src/Tests/Grand.Web.Admin.Tests/Services/GlobalAdminDataScopeTests.cs@@ -15,17 +15,6 @@ public class GlobalAdminDataScopeTestsAssert.IsTrue(result);}- [TestMethod]- public void ApplyScope_ReturnsQueryUnchanged()- {- var scope = new GlobalAdminDataScope<Product>();- var query = new[] { new Product { Id = "1" }, new Product { Id = "2" } }.AsQueryable();-- var result = scope.ApplyScope(query);-- CollectionAssert.AreEqual(query.ToList(), result.ToList());- }-[TestMethod]public void DefaultStoreId_IsNull(){diff --git a/src/Tests/Grand.Web.Vendor.Tests/Services/VendorProductDataScopeTests.cs b/src/Tests/Grand.Web.Vendor.Tests/Services/VendorProductDataScopeTests.csindex f90d4f257..5546b8528 100644--- a/src/Tests/Grand.Web.Vendor.Tests/Services/VendorProductDataScopeTests.cs+++ b/src/Tests/Grand.Web.Vendor.Tests/Services/VendorProductDataScopeTests.cs@@ -44,22 +44,6 @@ public class VendorProductDataScopeTestsAssert.IsFalse(await scope.HasAccess(null!));}- [TestMethod]- public void ApplyScope_FiltersToOwnVendorId()- {- var scope = new VendorProductDataScope(_contextAccessor.Object);- var query = new[]- {- new Product { Id = "1", VendorId = VendorId },- new Product { Id = "2", VendorId = "vendor-2" }- }.AsQueryable();-- var result = scope.ApplyScope(query).ToList();-- Assert.AreEqual(1, result.Count);- Assert.AreEqual("1", result[0].Id);- }-[TestMethod]public void DefaultStoreId_IsNull(){diff --git a/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.cs b/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.csindex b92f5f8b6..b9fda2ef5 100644--- a/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Interfaces/IAdminDataScope.cs@@ -21,9 +21,6 @@ public interface IAdminDataScope<TEntity>/// `CheckAccessToProduct`). Only Store overrides this.</summary>Task<bool> CanView(TEntity entity) => HasAccess(entity);- /// <summary>Narrows a query to the entities the current user may see. No-op for global (Admin) scope.</summary>- IQueryable<TEntity> ApplyScope(IQueryable<TEntity> query);-/// <summary>Store id to default onto new/edited entities. Null when the host has no store concept/// (Admin: global, no default; Vendor: not store-scoped at all).</summary>string? DefaultStoreId { get; }diff --git a/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.csindex c44291b2c..aeff35d49 100644--- a/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs@@ -8,8 +8,6 @@ public class GlobalAdminDataScope<TEntity> : IAdminDataScope<TEntity>{public Task<bool> HasAccess(TEntity entity) => Task.FromResult(true);- public IQueryable<TEntity> ApplyScope(IQueryable<TEntity> query) => query;-public string? DefaultStoreId => null;public string ResourceKeyPrefix => "Admin";diff --git a/src/Web/Grand.Web.AdminShared/Services/RoutedProductDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/RoutedProductDataScope.csindex bbf068851..dfd189aae 100644--- a/src/Web/Grand.Web.AdminShared/Services/RoutedProductDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Services/RoutedProductDataScope.cs@@ -53,8 +53,6 @@ public class RoutedProductDataScope(public Task<bool> CanView(Product entity) => Resolved.CanView(entity);- public IQueryable<Product> ApplyScope(IQueryable<Product> query) => Resolved.ApplyScope(query);-public string? DefaultStoreId => Resolved.DefaultStoreId;public string ResourceKeyPrefix => Resolved.ResourceKeyPrefix;diff --git a/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.csindex 0a6269350..334757c9a 100644--- a/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Services/StoreAdminDataScope.cs@@ -29,13 +29,6 @@ public class StoreAdminDataScope<TEntity>(IContextAccessor contextAccessor) : IAreturn Task.FromResult(allowed);}- public IQueryable<TEntity> ApplyScope(IQueryable<TEntity> query)- {- var staffStoreId = contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;- if (string.IsNullOrEmpty(staffStoreId)) return query;- return query.Where(x => x.LimitedToStores && x.Stores.Contains(staffStoreId) && x.Stores.Count == 1);- }-public string? DefaultStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;public string ResourceKeyPrefix => "Admin";diff --git a/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.csindex cea9c9854..d9c913167 100644--- a/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.cs+++ b/src/Web/Grand.Web.AdminShared/Services/VendorProductDataScope.cs@@ -14,12 +14,6 @@ public class VendorProductDataScope(IContextAccessor contextAccessor) : IAdminDareturn Task.FromResult(entity.VendorId == contextAccessor.WorkContext.CurrentVendor.Id);}- public IQueryable<Product> ApplyScope(IQueryable<Product> query)- {- var vendorId = contextAccessor.WorkContext.CurrentVendor.Id;- return query.Where(x => x.VendorId == vendorId);- }-public string? DefaultStoreId => null;public string ResourceKeyPrefix => "Vendor";