Skip to content

Commit

Permalink
Returning Toplevel products as per scroll limit for non admin users f…
Browse files Browse the repository at this point in the history
…ixes #2029 (#2063)
  • Loading branch information
hrath2015 authored and brent-hoover committed Mar 30, 2017
1 parent 6160ea2 commit 51bf059
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions server/publications/collections/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,20 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so
}

if (shop) {
const selector = {
isDeleted: { $in: [null, false] },
ancestors: {
$exists: true
},
shopId: shop._id
};
const selector = {};
if (Roles.userIsInRole(this.userId, ["owner", "admin", "createProduct"], shop._id)) {
_.extend(selector, {
isDeleted: { $in: [null, false] },
ancestors: { $exists: true },
shopId: shop._id
});
} else { // Changing the selector for non admin users only. To get top-level products.
_.extend(selector, {
isDeleted: { $in: [null, false] },
ancestors: [],
shopId: shop._id
});
}

if (productFilters) {
// handle multiple shops
Expand Down Expand Up @@ -398,10 +405,12 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so
]
});
}

return Products.find(newSelector, {
sort: sort,
limit: productScrollLimit
});
// Returning Complete product tree for top level products to avoid sold out warning.
return Products.find(
{
$or: [ { _id: { $in: productIds } },
{ ancestors: { $in: productIds } }
]
});
}
});

0 comments on commit 51bf059

Please sign in to comment.