Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

fix(core): limit creator attribution visibility to unpublished products (#1552)

Viktor Holikc21022d83556
diff --git a/integration-tests/http/product/vendor/product.spec.ts b/integration-tests/http/product/vendor/product.spec.ts
index 0c57ab1c8..6b976b8ca 100644
--- a/integration-tests/http/product/vendor/product.spec.ts
+++ b/integration-tests/http/product/vendor/product.spec.ts
@@ -444,6 +444,27 @@ medusaIntegrationTestRunner({
const idsB = listAsB.data.products.map((p: { id: string }) => p.id)
expect(idsB).not.toContain(restrictedToA)
})
+
+ it("hides a published product from its creator once restricted to other sellers", async () => {
+ const b = await createSellerUser(appContainer, {
+ email: "[email protected]",
+ name: "Scope C Store",
+ })
+ const createdByAForC = await createProduct(
+ "Created By A, Assigned To C",
+ "published",
+ sellerA.id,
+ [b.seller.id]
+ )
+
+ const listAsA = await api.get("/vendor/products?limit=100", headersA)
+ const idsA = listAsA.data.products.map((p: { id: string }) => p.id)
+ expect(idsA).not.toContain(createdByAForC)
+
+ const listAsC = await api.get("/vendor/products?limit=100", b.headers)
+ const idsC = listAsC.data.products.map((p: { id: string }) => p.id)
+ expect(idsC).toContain(createdByAForC)
+ })
})
// MER-246: creating a product with several images persisted only one in the
diff --git a/packages/core/src/api/vendor/product-variants/middlewares.ts b/packages/core/src/api/vendor/product-variants/middlewares.ts
index d4f751903..d6cb25759 100644
--- a/packages/core/src/api/vendor/product-variants/middlewares.ts
+++ b/packages/core/src/api/vendor/product-variants/middlewares.ts
@@ -34,7 +34,12 @@ const applySellerProductVariantFilter = async (
...existingAnd,
{
$or: [
- { product_id: ownProductIds },
+ {
+ product_id: ownProductIds,
+ product: {
+ status: { $in: [ProductStatus.DRAFT, ProductStatus.PROPOSED] },
+ },
+ },
{
product: { status: ProductStatus.PUBLISHED },
product_id: { $nin: restrictedFromSellerIds },
diff --git a/packages/core/src/api/vendor/products/middlewares.ts b/packages/core/src/api/vendor/products/middlewares.ts
index 75f84b78f..8d9e75889 100644
--- a/packages/core/src/api/vendor/products/middlewares.ts
+++ b/packages/core/src/api/vendor/products/middlewares.ts
@@ -57,7 +57,10 @@ const applySellerProductLinkFilter = async (
...existingAnd,
{
$or: [
- { id: ownProductIds },
+ {
+ id: ownProductIds,
+ status: { $in: [ProductStatus.DRAFT, ProductStatus.PROPOSED] },
+ },
{
status: ProductStatus.PUBLISHED,
id: { $nin: restrictedFromSellerIds },