Skip to content

Commit

Permalink
Merge pull request #2969 from reactioncommerce/spencer-2889-cleanup-m…
Browse files Browse the repository at this point in the history
…arketplace-shop-creation

Limit, cleanup, and secure shop creation
  • Loading branch information
spencern authored Sep 30, 2017
2 parents 782ce04 + 52b7c4b commit e276692
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class UpdateEmail extends Component {
/>
<Components.Button
bezelStyle={"solid"}
icon={showSpinner && "fa fa-spin fa-circle-o-notch"}
icon={showSpinner ? "fa fa-spin fa-circle-o-notch" : ""}
i18nKeyLabel={showSpinner ? "accountsUI.updatingEmailAddress" : "accountsUI.updateEmailAddress"}
label={showSpinner ? "Updating Email Address" : "Update Email Address"}
status={"primary"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3 class="panel-title" data-i18n="accountsUI.yourOrders">Your Orders</h3>
{{> addressBookPanel}}
</div>

{{#if isMarketplaceGuest }}
{{#if showMerchantSignup }}
<div class="flex-item">
<div class="panel panel-default">
<div class="panel-heading">
Expand All @@ -57,18 +57,6 @@ <h3 class="panel-title" data-i18n="marketplace.becomeSeller">Become a Seller</h3
</div>
</div>
</div>

<div class="flex-item">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title" data-i18n="marketplace.stripeConnectSignup">Start Accepting Payments</h3>
</div>

<div class="panel-content">
{{> stripeConnectSignupButton}}
</div>
</div>
</div>
{{/if}}
</div>

Expand Down
58 changes: 20 additions & 38 deletions imports/plugins/core/accounts/client/templates/profile/profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { Roles } from "meteor/alanning:roles";
import { ReactiveVar } from "meteor/reactive-var";
import { Reaction } from "/client/api";
import { i18next } from "/client/api";
Expand Down Expand Up @@ -66,55 +65,38 @@ Template.accountProfile.helpers({
}
},

/**
* User's account profile
* @return {Object} account profile
*/
account() {
return Collections.Accounts.findOne();
},

/**
* User's display name
* @return {String} display name
*/
displayName() {
const userId = Meteor.userId() || {};
const user = Collections.Accounts.findOne(userId);

if (user) {
if (user.name) {
return user.name;
} else if (user.username) {
return user.username;
} else if (user.profile && user.profile.name) {
return user.profile.name;
if (Reaction.Subscriptions && Reaction.Subscriptions.Account && Reaction.Subscriptions.Account.ready()) {
const account = Collections.Accounts.findOne(Meteor.userId());
if (account) {
if (account.name) {
return account.name;
} else if (account.username) {
return account.username;
} else if (account.profile && account.profile.name) {
return account.profile.name;
}
}
}

if (Roles.userIsInRole(user._id || user.userId, "account/profile",
Reaction.getShopId())) {
if (Reaction.hasPermission("account/profile")) {
return i18next.t("accountsUI.guest", { defaultValue: "Guest" });
}
},

/**
* Returns the address book default view
* @return {String} "addressBookGrid" || "addressBookAdd"
*/
addressBookView: function () {
const account = Collections.Accounts.findOne();
if (account.profile) {
return "addressBookGrid";
showMerchantSignup: function () {
if (Reaction.Subscriptions && Reaction.Subscriptions.Account && Reaction.Subscriptions.Account.ready()) {
const account = Collections.Accounts.findOne({ _id: Meteor.userId() });
const marketplaceEnabled = Reaction.marketplace && Reaction.marketplace.enabled === true;
const allowMerchantSignup = Reaction.marketplace && Reaction.marketplace.allowMerchantSignup === true;
// A user has the primaryShopId until a shop is created for them.
const userHasShop = account.shopId !== Reaction.getPrimaryShopId();
return marketplaceEnabled && allowMerchantSignup && !userHasShop;
}
return "addressBookAdd";
},

isMarketplaceGuest: function () {
return (Reaction.hasMarketplaceAccess("guest") && !Reaction.hasAdminAccess());
},

isMarketplaceSeller: function () {
return (Reaction.hasMarketplaceAccess() && !Reaction.hasOwnerAccess());
return false;
}
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template name="becomeSellerButton">
<button
class="btn {{classes}}"
class="btn btn-info"
data-event-category="marketplace"
data-event-action="button-click-become-seller"
data-event-label="Become a Seller button click"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,12 @@ import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { Reaction, i18next } from "/client/api";


// Page


// Button
Template.becomeSellerButton.helpers({
/**
* Give it a size and style
* @return {String} The classes
*/
classes() {
const classes = [
(this.type || "btn-info"),
(this.size || "")
];

return classes.join(" ");
}
});


Template.becomeSellerButton.events({
"click [data-event-action='button-click-become-seller']": function () {
Meteor.call("shop/createShop", Meteor.userId(), function (error, response) {
if (error) {
const errorMessage = i18next.t("marketplace.errorCannotCreateShop", { defaultValue: "Could not create shop for current user {{user}}" });
return Alerts.toast(errorMessage, "error");
return Alerts.toast(`${errorMessage} ${error}`, "error");
}

const success = i18next.t("marketplace.yourShopIsReady", { defaultValue: "Your shop is now ready!" });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
<template name="marketplaceSettings">
<div class="panel panel-default">
<div class="panel-heading panel-heading-flex">
<h3 class="panel-title">
<i class="{{PackageData.settings.icon}}"></i> General
</h3>
</div>
<div class="panel-body">
{{#autoForm collection=Collections.Packages schema=MarketplacePackageConfig
doc=packageData id="marketplaceOptionsForm" type="update" autosave=true}}
{{> afFieldInput name="settings.public.allowGuestSellers"}}
{{/autoForm}}

{{schema}}
</div>
</div>
</template>

<template name="marketplaceShopSettings">
{{#autoForm collection=Collections.Packages schema=MarketplacePackageConfig
doc=packageData id="marketplaceOptionsForm" type="update" autosave=true}}
{{> afFieldInput name="settings.public.allowGuestSellers"}}
{{> afFieldInput name="settings.public.merchantFulfillment"}}
{{> afFieldInput name="settings.public.allowMerchantSignup"}}
<!-- TODO: As we add optional functionality to marketplace, add options here -->
{{/autoForm}}

{{schema}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { MarketplacePackageConfig } from "../../../lib/collections/schemas";
import { Components } from "@reactioncommerce/reaction-components";

/**
* marketplaceSettings helpers
* marketplaceShopSettings helpers
*
*/
Template.marketplaceSettings.helpers({
Template.marketplaceShopSettings.helpers({
MarketplacePackageConfig() {
return MarketplacePackageConfig;
},
Expand All @@ -25,11 +25,6 @@ Template.marketplaceSettings.helpers({
}
});

/**
* marketplace Catalog settings
*/
Template.marketplaceShopSettings.inheritsHelpersFrom("marketplaceSettings");

/**
* marketplaceSettings autoform alerts
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export const MarketplacePackageConfig = new SimpleSchema([
type: Boolean,
defaultValue: false
},
// Deprecated - no longer used in any marketplace considerations
// marketplace is enabled and disabled via the package
// seller signup is controlled by the allowMerchantSignup setting
"settings.public.allowGuestSellers": {
type: Boolean,
defaultValue: false
Expand Down
1 change: 0 additions & 1 deletion imports/plugins/included/marketplace/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Reaction.registerPackage({
}]
},
public: {
allowGuestSellers: true, // TODO: Eliminate in favor of marketplace.enabled and allowMerchantSignup
allowMerchantSignup: false, // Merchants can sign up without an invite
marketplaceNakedRoutes: true, // Routes to the primary marketplace shop should not use shop prefix
merchantCart: false, // Unique cart for each merchant
Expand Down
22 changes: 1 addition & 21 deletions lib/api/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,11 @@ function getSellerShop(user, noFallback = false) {
return Shops.findOne({ _id });
}

/**
* hasMarketplaceAccess
* @summary Checks if the current user has access to the marketplace based on role(s),
* when the Marketplace module is enabled and with guest access on
* @param {String|Array} role The role(s) to check for access
* @returns {Boolean} True if current user has access
*/
function hasMarketplaceAccess(role = "admin") {
const currentUser = Meteor.user();
const packageSettings = Core.Reaction.getPackageSettings("reaction-marketplace");

return (
packageSettings &&
packageSettings.enabled &&
packageSettings.settings.public.allowGuestSellers &&
Roles.userIsInRole(currentUser, role, this.getSellerShopId())
);
}

const Reaction = Object.assign(Core.Reaction, {
isPackageEnabled,
getSeller,
getSellerShopId,
getSellerShop,
hasMarketplaceAccess
getSellerShop
});

export {
Expand Down
Loading

0 comments on commit e276692

Please sign in to comment.