Skip to content

Commit

Permalink
Merge branch 'marketplace'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.meteor/release
#	package-lock.json
  • Loading branch information
aaronjudd committed Sep 26, 2017
1 parent b54e8d9 commit 25031a0
Show file tree
Hide file tree
Showing 170 changed files with 3,665 additions and 7,622 deletions.
20 changes: 19 additions & 1 deletion client/modules/core/helpers/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Meteor } from "meteor/meteor";
import { Roles } from "meteor/alanning:roles";
import { Reaction } from "/client/api";
import { Packages, Shops } from "/lib/collections";
import { Registry } from "/lib/collections/schemas/registry";


/**
Expand Down Expand Up @@ -152,7 +153,24 @@ export function Apps(optionHash) {
return false;
}

return _.isMatch(item, itemFilter);
const filterKeys = Object.keys(itemFilter);
// Loop through all keys in the itemFilter
// each filter item should match exactly with the property in the registry or
// should be included in the array if that property is an array
return filterKeys.every((property) => {
// Check to see if the schema for this property is an array
// if so, we want to make sure that this item is included in the array
if (Array.isArray(Registry._schema[property].type())) {
// Check to see if the registry entry is an array.
// Legacy registry entries could exist that use a string even when the schema requires an array.
if (Array.isArray(item[property])) {
return item[property].includes(itemFilter[property]);
}
}

// If it's not an array, the filter should match exactly
return item[property] === itemFilter[property];
});
});

for (const registry of matchingRegistry) {
Expand Down
71 changes: 35 additions & 36 deletions client/modules/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,42 @@ export default {
Tracker.autorun(() => {
let shop;
if (this.Subscriptions.PrimaryShop.ready()) {
// if we've already set the primaryShopId, carry on.
// otherwise we need to define it.
if (!this.primaryShopId) {
// There should only ever be one "primary" shop
shop = Shops.findOne({
shopType: "primary"
});

if (shop) {
this.primaryShopId = shop._id;
this.primaryShopName = shop.name;

// We'll initialize locale and currency for the primary shop unless
// marketplace settings exist and merchantLocale is set to true
if (this.marketplace.merchantLocale !== true) {
// initialize local client Countries collection
if (!Countries.findOne()) {
createCountryCollection(shop.locales.countries);
}
// There should only ever be one "primary" shop
shop = Shops.findOne({
shopType: "primary"
});

if (shop) {
this.primaryShopId = shop._id;
this.primaryShopName = shop.name;

// We'll initialize locale and currency for the primary shop unless
// marketplace settings exist and merchantLocale is set to true
if (this.marketplace.merchantLocale !== true) {
// initialize local client Countries collection
if (!Countries.findOne()) {
createCountryCollection(shop.locales.countries);
}

const locale = this.Locale.get() || {};
const locale = this.Locale.get() || {};

// fix for https://github.com/reactioncommerce/reaction/issues/248
// we need to keep an eye for rates changes
if (typeof locale.locale === "object" &&
// fix for https://github.com/reactioncommerce/reaction/issues/248
// we need to keep an eye for rates changes
if (typeof locale.locale === "object" &&
typeof locale.currency === "object" &&
typeof locale.locale.currency === "string") {
const localeCurrency = locale.locale.currency.split(",")[0];
if (typeof shop.currencies[localeCurrency] === "object") {
if (typeof shop.currencies[localeCurrency].rate === "number") {
locale.currency.rate = shop.currencies[localeCurrency].rate;
localeDep.changed();
}
const localeCurrency = locale.locale.currency.split(",")[0];
if (typeof shop.currencies[localeCurrency] === "object") {
if (typeof shop.currencies[localeCurrency].rate === "number") {
locale.currency.rate = shop.currencies[localeCurrency].rate;
localeDep.changed();
}
}
// we are looking for a shopCurrency changes here
if (typeof locale.shopCurrency === "object") {
locale.shopCurrency = shop.currencies[shop.currency];
localeDep.changed();
}
}
// we are looking for a shopCurrency changes here
if (typeof locale.shopCurrency === "object") {
locale.shopCurrency = shop.currencies[shop.currency];
localeDep.changed();
}
}
}
Expand Down Expand Up @@ -199,7 +195,10 @@ export default {
} else {
permissions = checkPermissions;
}
// if the user has admin, owner permissions we'll always check if those roles are enough
// if the user has owner permissions we'll always check if those roles are enough
// By adding the "owner" role to the permissions list, we are making hasPermission always return
// true for "owners". This gives owners global access.
// TODO: Review this way of granting global access for owners
permissions.push("owner");
permissions = _.uniq(permissions);

Expand Down Expand Up @@ -736,7 +735,7 @@ export default {
// valid application
if (reactionApp) {
const settingsData = _.find(reactionApp.registry, function (item) {
return item.provides === provides && item.template === template;
return item.provides && item.provides.includes(provides) && item.template === template;
});
return settingsData;
}
Expand Down
2 changes: 1 addition & 1 deletion client/modules/i18n/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Meteor.startup(() => {
locale.language = getBrowserLanguage();
moment.locale(locale.language);
// flag in case the locale currency isn't enabled
locale.currencyEnabled = locale.currencyEnabled;
locale.currencyEnabled = locale.currency.enabled;
const user = Meteor.user();
if (user && user.profile && user.profile.currency) {
localStorage.setItem("currency", user.profile.currency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function groupPermissions(packages) {
shopId: pkg.shopId,
permission: registryItem.name || pkg.name + "/" + registryItem.template,
icon: registryItem.icon,
// TODO: Rethink naming convention for permissions list
label: registryItem.label || registryItem.provides || registryItem.route
});
}
Expand Down
8 changes: 4 additions & 4 deletions imports/plugins/core/accounts/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Reaction.registerPackage({
registry: [{
route: "/dashboard/accounts",
name: "accounts",
provides: "dashboard",
provides: ["dashboard"],
label: "Accounts",
description: "Manage how members sign into your shop.",
icon: "fa fa-users",
Expand All @@ -26,7 +26,7 @@ Reaction.registerPackage({
}, {
label: "Account Settings",
icon: "fa fa-sign-in",
provides: "settings",
provides: ["settings"],
route: "/dashboard/account/settings",
container: "accounts",
workflow: "coreAccountsWorkflow",
Expand All @@ -35,7 +35,7 @@ Reaction.registerPackage({
route: "/dashboard/accounts",
name: "dashboard/accounts",
workflow: "coreAccountsWorkflow",
provides: "shortcut",
provides: ["shortcut"],
label: "Accounts",
icon: "fa fa-users",
priority: 1,
Expand All @@ -47,7 +47,7 @@ Reaction.registerPackage({
name: "account/profile",
label: "Profile",
icon: "fa fa-user",
provides: "userAccountDropdown"
provides: ["userAccountDropdown"]
}],
layout: [{
layout: "coreLayout",
Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/catalog/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Reaction.registerPackage({
},
registry: [
{
provides: "dashboard",
provides: ["dashboard"],
label: "Catalog",
description: "Product catalog",
icon: "fa fa-book",
Expand All @@ -20,7 +20,7 @@ Reaction.registerPackage({
label: "Catalog Settings",
icon: "fa fa-book",
name: "catalog/settings",
provides: "settings",
provides: ["settings"],
template: "catalogSettings"
}
]
Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/checkout/client/helpers/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { Template } from "meteor/templating";
* cartCount, cartSubTotal, cartShipping, cartTaxes, cartTotal
* are calculated by a transformation on the collection
* and are available to use in template as cart.xxx
* in template: {{cart.cartCount}}
* in code: Cart.findOne().cartTotal()
* in template: {{cart.getCount}}
* in code: Cart.findOne().getTotal()
* @return {Object} returns inventory helpers
*/
Template.registerHelper("cart", function () {
Expand Down
21 changes: 13 additions & 8 deletions imports/plugins/core/components/lib/hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ export function withCurrentAccount(component) {
return null;
}

// shoppers should always be guests
const isGuest = Roles.userIsInRole(user, "guest", shopId);
// but if a user has never logged in then they are anonymous
const isAnonymous = Roles.userIsInRole(user, "anonymous", shopId);

const account = Accounts.findOne(user._id);

onData(null, { currentAccount: isGuest && !isAnonymous && account });
const accSub = Meteor.subscribe("Accounts", user._id);
if (accSub.ready()) {
// shoppers should always be guests
const isGuest = Reaction.hasPermission("guest");
// but if a user has never logged in then they are anonymous
const isAnonymous = Roles.userIsInRole(user, "anonymous", shopId);
// this check for "anonymous" uses userIsInRole instead of hasPermission because hasPermission
// always return `true` when logged in as the owner.
// But in this case, the anonymous check should be false when a user is logged in
const account = Accounts.findOne(user._id);

onData(null, { currentAccount: isGuest && !isAnonymous && account });
}
})(component);
}

Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/connectors/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Reaction.registerPackage({
name: "Connectors"
},
registry: [{
provides: "dashboard",
provides: ["dashboard"],
route: "/dashboard/connectors",
name: "connectors",
label: "Connectors",
Expand All @@ -19,7 +19,7 @@ Reaction.registerPackage({
container: "core",
workflow: "coreDashboardWorkflow"
}, {
provides: "settings",
provides: ["settings"],
name: "settings/connectors",
label: "Connectors",
description: "Configure connectors",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { getComponent } from "@reactioncommerce/reaction-components";
const getStyles = (props) => {
let viewSize = 400;
const actionView = props.actionView || {};
const isBigView = actionView.provides === "dashboard" || (actionView.provides === "shortcut" && actionView.container === "dashboard");
const provides = actionView.provides || [];
// legacy provides could be a string, is an array since 1.5.0, check for either.
// prototype.includes has the fortunate side affect of checking string equality as well as array inclusion.
const isBigView = provides.includes("dashboard") ||
(provides.includes("shortcut") && actionView.container === "dashboard");

if (isBigView) {
viewSize = "90vw";
Expand Down Expand Up @@ -277,8 +281,9 @@ class ActionView extends Component {
get actionViewIsLargeSize() {
const { meta } = this.props.actionView;
const dashboardSize = meta && meta.actionView && meta.actionView.dashboardSize || "sm";
const includesDashboard = this.props.actionView.provides && this.props.actionView.provides.includes("dashboard");

return this.props.actionView.provides === "dashboard" || dashboardSize !== "sm";
return includesDashboard || dashboardSize !== "sm";
}

get showOverlay() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class ShortcutBar extends Component {
<FlatButton onClick={this.props.handleShowDashboard}>
<Icon
icon="icon icon-reaction-logo"
style={{
fontSize: 24
}}
/>
</FlatButton>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class PublishControls extends Component {
});
}}
>
<Icon style={{ fontSize: 24 }} icon="icon icon-reaction-logo" />
<Icon icon="icon icon-reaction-logo" />
</FlatButton>
</ToolbarGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ function composer(props, onData) {
for (const item of registryItems) {
if (Reaction.hasPermission(item.route, Meteor.userId())) {
let icon = item.icon;

if (!item.icon && item.provides === "settings") {
if (!item.icon && item.provides && item.provides.includes("settings")) {
icon = "gear";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Template.settingsHeader.helpers({

if (reactionApp) {
const settingsData = _.find(reactionApp.registry, function (item) {
return item.route === Reaction.Router.getRouteName() && item.provides === "settings";
return item.route === Reaction.Router.getRouteName() && item.provides && item.provides.includes("settings");
});

return settingsData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<div class="panel-body">
{{#autoForm collection=Collections.Shops doc=shop id="shopEditForm" type="update"}}
{{> afQuickField name='name' placeholder="Shop Name"}}
{{> afQuickField name='slug' placeholder="Shop Slug"}}
{{> afQuickField name='emails.0.address' label="Email" placeholder="Primary Contact Email"}}
{{> afQuickField name='description' placeholder="Description"}}
{{> afQuickField name='keywords' placeholder="Keywords"}}
Expand Down
6 changes: 3 additions & 3 deletions imports/plugins/core/dashboard/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Reaction.registerPackage({
name: "Dashboard"
},
registry: [{
provides: "dashboard",
provides: ["dashboard"],
workflow: "coreDashboardWorkflow",
name: "dashboardPackages",
label: "Core",
Expand All @@ -25,7 +25,7 @@ Reaction.registerPackage({
route: "/dashboard",
name: "dashboard",
workflow: "coreDashboardWorkflow",
provides: "shortcut",
provides: ["shortcut"],
label: "Dashboard",
template: "dashboardPackages",
icon: "icon-reaction-logo",
Expand All @@ -40,7 +40,7 @@ Reaction.registerPackage({
name: "shopSettings",
label: "Shop Settings",
icon: "fa fa-th",
provides: "settings",
provides: ["settings"],
container: "dashboard"
}],
layout: [{
Expand Down
2 changes: 1 addition & 1 deletion imports/plugins/core/email/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Reaction.registerPackage({
description: "Email settings",
icon: "fa fa-envelope-o",
name: "email/settings",
provides: "settings",
provides: ["settings"],
workflow: "coreEmailWorkflow",
template: "emailSettings",
meta: {
Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/i18n/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Reaction.registerPackage({
name: "i18n"
},
registry: [{
provides: "dashboard",
provides: ["dashboard"],
label: "i18n",
description: "Internationalization utilities",
icon: "fa fa-language",
priority: 1,
container: "utilities"
}, {
provides: "settings",
provides: ["settings"],
template: "i18nSettings",
label: "Localization and i18n",
icon: "fa fa-language",
Expand Down
Loading

0 comments on commit 25031a0

Please sign in to comment.