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

Disable shops #3132

Merged
merged 11 commits into from
Oct 30, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ function composer(props, onData) {

if (user && user.roles) {
// Get all shops for which user has roles
shops = Shops.find({ _id: { $in: Object.keys(user.roles) } }).fetch();
shops = Shops.find({
$and: [
{ _id: { $in: Object.keys(user.roles) } },
{ $or: [{ "workflow.status": "active" }, { _id: Reaction.getPrimaryShopId() }] }
]
}).fetch();
}

// Standard variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Reaction } from "/client/api";
import { ITEMS_INCREMENT } from "/client/config/defaults";
import { ReactionProduct } from "/lib/api";
import { applyProductRevision } from "/lib/api/products";
import { Products, Tags } from "/lib/collections";
import { Products, Tags, Shops } from "/lib/collections";
import ProductsComponent from "../components/products";

/**
Expand Down Expand Up @@ -166,9 +166,17 @@ function composer(props, onData) {
window.prerenderReady = true;
}

const activeShopsIds = Shops.find({
$or: [
{ "workflow.status": "active" },
{ _id: Reaction.getPrimaryShopId() }
]
}).fetch().map(activeShop => activeShop._id);

const productCursor = Products.find({
ancestors: [],
type: { $in: ["simple"] }
type: { $in: ["simple"] },
shopId: { $in: activeShopsIds }
});

const products = productCursor.map((product) => {
Expand Down
23 changes: 11 additions & 12 deletions server/publications/collections/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so
return this.ready();
}

// Get active shop id's to use for filtering
const activeShopsIds = Shops.find({
$or: [
{ "workflow.status": "active" },
{ _id: Reaction.getPrimaryShopId() }
]
}).fetch().map(activeShop => activeShop._id);

// if there are filter/params that don't match the schema
// validate, catch except but return no results
try {
Expand Down Expand Up @@ -278,7 +286,7 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so
$in: [true, false, null, undefined]
};
selector.shopId = {
$in: userAdminShopIds
$in: activeShopsIds
};

// Get _ids of top-level products
Expand Down Expand Up @@ -517,20 +525,11 @@ Meteor.publish("Products", function (productScrollLimit = 24, productFilters, so
});
}

// Get disabled shop id's to use for filtering
const disabledShopIds = Shops.find({
"workflow.status": {
$in: ["disabled", "archived"]
}
}, {
fields: { _id: 1 }
}).map((shop) => shop._id);

// Adjust the selector to exclude all disabled shops
// Adjust the selector to include only active shops
newSelector = {
...newSelector,
shopId: {
$nin: disabledShopIds
$in: activeShopsIds
}
};

Expand Down