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.

1.8 KB
Raw Blame
#nullable enable

using Grand.Domain.Shipping;
using Grand.Infrastructure;
using Grand.Web.AdminShared.Interfaces;

namespace Grand.Web.AdminShared.Services;

/// <summary>
///     Store's <see cref="IAdminDataScope{Shipment}" />. Bespoke, not the generic
///     <see cref="StoreAdminDataScope{TEntity}" />: <c>Shipment</c> is a plain <see cref="Grand.Domain.BaseEntity" />
///     with a single <c>StoreId</c> field, not <c>IStoreLinkEntity</c> (no <c>Stores</c>/
///     <c>LimitedToStores</c> list), so the generic class's <c>where TEntity : BaseEntity,
///     IStoreLinkEntity</c> constraint doesn't apply. Mirrors Store's original controller's
///     <c>shipment.StoreId != StaffStoreId</c> check, repeated at every action site in that file.
///     No <see cref="IAdminDataScope{TEntity}.CanView" /> override: Store's original code has one
///     uniform check for both viewing and mutating, unlike Category/Product's loose/strict split —
///     <see cref="IAdminDataScope{TEntity}.CanView" /> is simply inherited from the interface
///     default, which delegates to <see cref="HasAccess" />.
/// </summary>
public class StoreShipmentDataScope(IContextAccessor contextAccessor) : IAdminDataScope<Shipment>
{
    public Task<bool> HasAccess(Shipment entity) =>
        Task.FromResult(entity is not null &&
            !string.IsNullOrEmpty(contextAccessor.WorkContext.CurrentCustomer.StaffStoreId) &&
            entity.StoreId == contextAccessor.WorkContext.CurrentCustomer.StaffStoreId);

    public string? DefaultStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
    public string ResourceKeyPrefix => "Admin";
    public bool ShowStoreSelector => true;
    public string? DefaultVendorId => null;
    public bool CanFeatureOnHomepage => true; // unused for Shipment; required interface member
}