Skip to content

Commit

Permalink
Merge pull request #3394 from reactioncommerce/release-1.6.1
Browse files Browse the repository at this point in the history
Release 1.6.1
  • Loading branch information
spencern authored Dec 12, 2017
2 parents ee3b6e1 + 0f50b1c commit 5003530
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .circleci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ reaction:

mongo:
image: mongo:latest
command: mongod --storageEngine=wiredTiger
command: mongod --storageEngine=wiredTiger --bind_ip_all
2 changes: 1 addition & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ [email protected]
mdg:validated-method
[email protected]
[email protected]
[email protected]

# Meteor Auth Packages
[email protected]
Expand All @@ -47,7 +48,6 @@ [email protected]


# Community Packages
abernix:standard-minifier-js
alanning:roles
aldeed:autoform
aldeed:collection2
Expand Down
45 changes: 44 additions & 1 deletion client/modules/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,49 @@ export default {
return typeof hasPermissions !== "undefined";
},

/**
* getShopsForUser -
* @summary gets shopIds of shops where user has provided permissions
* @param {Array} roles - roles to check if user has
* @param {Object} userId - userId to check permissions for (defaults to current user)
* @return {Array} - shopIds user has provided permissions for
*/
getShopsForUser(roles, userId = Meteor.userId()) {
// Get full user object, and get shopIds of all shops they are attached to
const user = Meteor.user(userId);
const shopIds = Object.keys(user.roles);
// Remove "__global_roles__" from the list of shopIds, as this function will always return true for
// marketplace admins if that "id" is left in the check
const filteredShopIds = shopIds.filter(shopId => shopId !== "__global_roles__");

// Reduce shopIds to shopsWithPermission, using the roles passed in to this function
const shopIdsWithRoles = filteredShopIds.reduce((shopsWithPermission, shopId) => {
// Get list of roles user has for this shop
const rolesUserHas = user.roles[shopId];

// Find first role that is included in the passed in roles array, otherwise hasRole is undefined
const hasRole = rolesUserHas.find((roleUserHas) => roles.includes(roleUserHas));

// if we found the role, then the user has permission for this shop. Add shopId to shopsWithPermission array
if (hasRole) {
shopsWithPermission.push(shopId);
}
return shopsWithPermission;
}, []);

return shopIdsWithRoles;
},

/**
* hasDashboardAccessForAnyShop - client
* @summary - client permission check for any "owner", "admin", or "dashboard" permissions for more than one shop.
* @return {Boolean} Boolean - true if has dashboard access for more than one shop
*/
hasDashboardAccessForMultipleShops() {
const adminShopIds = this.getShopsForUser(["owner", "admin", "dashboard"]);
return Array.isArray(adminShopIds) && adminShopIds.length > 1;
},

hasOwnerAccess() {
const ownerPermissions = ["owner"];
return this.hasPermission(ownerPermissions);
Expand Down Expand Up @@ -325,7 +368,7 @@ export default {
},

hasShopSwitcherAccess() {
return this.hasDashboardAccessForAnyShop();
return this.hasDashboardAccessForMultipleShops();
},

getSellerShopId: function (userId = Meteor.userId(), noFallback = false) {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ reaction:

mongo:
image: mongo:latest
command: mongod --storageEngine=wiredTiger
command: mongod --storageEngine=wiredTiger --bind_ip_all
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ function handleChange(event, value) {
if (error) {
Logger.error(error, "Failed to logout.");
}

// Resets the app to show the primary shop as the active shop when a user logs out.
// When an admin user is switching back and forth between shops, the app will keep the
// activeShopId as the last shop visited. If an admin user logs out, the app will stay on that shop
// for any new user who uses the same browser, temporarily, until the app is refreshed. This fixes that issue.
Reaction.setShopId(Reaction.getPrimaryShopId());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ Template.accountProfile.helpers({

if (account && Array.isArray(account.emails)) {
const defaultEmail = account.emails.find((email) => email.provides === "default");
if (defaultEmail === undefined) {
return "";
}
return defaultEmail.address;
return defaultEmail && defaultEmail.address || account.emails[0].address;
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CartItems extends Component {
onClick={this.handleClick}
>
{handleImage(item) ?
<div className="center-cropped" style={{ backgroundImage: `url(${handleImage(item).url({ store: "small" })})` }}>
<div className="center-cropped" style={{ backgroundImage: `url('${handleImage(item).url({ store: "small" })}')` }}>
<img src={handleImage(item).url({ store: "small" })} className="product-grid-item-images img-responsive" />
</div> :
<div className="center-cropped" style={{ backgroundImage: "url('/resources/placeholder.gif')" }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template name="cartCheckout">
{{#if cart.items}}
{{#if cartCount}}

<div class="checkout-progress">
<div class="container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ Template.cartCheckout.helpers({
return Cart.findOne();
}
return {};
},
cartCount() {
const cart = Cart.findOne();
if (cart.items && cart.items.length > 0) {
return true;
}
return false;
}
});

Expand Down
49 changes: 29 additions & 20 deletions imports/plugins/core/dashboard/client/components/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,37 @@ class PublishControls extends Component {

renderShopSelect() {
let menuItems;
if (Array.isArray(this.props.shops)) {
menuItems = this.props.shops.map((shop, index) => {
return (
<MenuItem
label={shop.name}
selectLabel={shop.name}
value={shop._id}
key={index}
/>
);
});

// If a user has owner, admin, or marketplace permissions for more than one (1) shops
// show the shop switcher to allow for easy switching between the shops
if (Reaction.hasShopSwitcherAccess()) {
if (Array.isArray(this.props.shops)) {
menuItems = this.props.shops.map((shop, index) => {
return (
<MenuItem
label={shop.name}
selectLabel={shop.name}
value={shop._id}
key={index}
/>
);
});
}

return (
<DropDownMenu
onChange={this.onShopSelectChange}
value={this.props.shopId}
closeOnClick={true}
>
{menuItems}
</DropDownMenu>
);
}

return (
<DropDownMenu
onChange={this.onShopSelectChange}
value={this.props.shopId}
closeOnClick={true}
>
{menuItems}
</DropDownMenu>
);
// If the user is just a shop owner, not a marketplace owner,
// make sure the shop is set to their shop and do not show the shop switcher
return this.onShopSelectChange(null, Reaction.getSellerShopId());
}

renderVisibilitySwitch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,10 @@ const handleShopSelectChange = (event, shopId) => {
function composer(props, onData) {
// Reactive data sources
const routeName = Reaction.Router.getRouteName();
const user = Meteor.user();
let shops;

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

const shopIds = Reaction.getShopsForUser(["owner", "admin", "dashboard"]);
const shops = Shops.find({
_id: { $in: shopIds }
}).fetch();
// Standard variables
const packageButtons = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Object.assign(Alerts, {
alert(titleOrOptions, messageOrCallback, options, callback) {
if (_.isObject(titleOrOptions)) {
return swal({
useRejections: true,
type: "info",
...titleOrOptions
}).then((isConfirm) => {
Expand All @@ -94,6 +95,7 @@ Object.assign(Alerts, {
const message = messageOrCallback;

return swal({
useRejections: true,
title,
text: message,
type: "info",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ Template.coreOrderShippingInvoice.events({
const settingsKey = paymentMethod && paymentMethod.paymentSettingsKey;
// check if payment provider supports de-authorize
const checkSupportedMethods = Packages.findOne({
_id: packageId,
shopId: Reaction.getShopId()
_id: packageId
}).settings[settingsKey].support;

const orderStatus = paymentMethod && paymentMethod.status;
Expand Down
6 changes: 1 addition & 5 deletions imports/plugins/core/ui/client/containers/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ const composer = (props, onData) => {
// If we now have an account, and that account has an email address, return it
if (account && Array.isArray(account.emails)) {
const defaultEmail = account.emails.find((emailObj) => emailObj.provides === "default");
if (defaultEmail === undefined) {
email = "";
} else {
email = defaultEmail.address;
}
email = defaultEmail && defaultEmail.address || account.emails[0].address;
}
onData(null, { email });
};
Expand Down
5 changes: 5 additions & 0 deletions imports/plugins/included/connectors-shopify/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions lib/api/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ export function applyProductRevision(product) {
* @return {Boolean} True if variant is selected
*/
export function variantIsSelected(variantId) {
const current = ReactionProduct.selectedVariant();
if (current && typeof current === "object" && (variantId === current._id || ~current.ancestors.indexOf(variantId))) {
const current = Object.assign({}, ReactionProduct.selectedVariant());
if (current.ancestors && (variantId === current._id || ~current.ancestors.indexOf(variantId))) {
return true;
}

return false;
}

Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5003530

Please sign in to comment.