Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning Complete product tree for non admin users fixes #2029 #2063

Merged
merged 1 commit into from
Mar 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } }
]
});
}
});