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.

Add GlobalAdminDataScope for the Admin host (ARCH-001 Phase 1)

KrzysztofPajak2a5ccc8eb029
diff --git a/src/Tests/Grand.Web.Admin.Tests/Services/GlobalAdminDataScopeTests.cs b/src/Tests/Grand.Web.Admin.Tests/Services/GlobalAdminDataScopeTests.cs
new file mode 100644
index 000000000..18148315e
--- /dev/null
+++ b/src/Tests/Grand.Web.Admin.Tests/Services/GlobalAdminDataScopeTests.cs
@@ -0,0 +1,42 @@
+using Grand.Domain.Catalog;
+using Grand.Web.AdminShared.Services;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Grand.Web.Admin.Tests.Services;
+
+[TestClass]
+public class GlobalAdminDataScopeTests
+{
+ [TestMethod]
+ public async Task HasAccess_AlwaysReturnsTrue()
+ {
+ var scope = new GlobalAdminDataScope<Product>();
+ var result = await scope.HasAccess(new Product());
+ Assert.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()
+ {
+ var scope = new GlobalAdminDataScope<Product>();
+ Assert.IsNull(scope.DefaultStoreId);
+ }
+
+ [TestMethod]
+ public void ResourceKeyPrefix_IsAdmin()
+ {
+ var scope = new GlobalAdminDataScope<Product>();
+ Assert.AreEqual("Admin", scope.ResourceKeyPrefix);
+ }
+}
diff --git a/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs b/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs
new file mode 100644
index 000000000..2f28984ca
--- /dev/null
+++ b/src/Web/Grand.Web.AdminShared/Services/GlobalAdminDataScope.cs
@@ -0,0 +1,16 @@
+#nullable enable
+
+using Grand.Web.AdminShared.Interfaces;
+
+namespace Grand.Web.AdminShared.Services;
+
+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";
+}