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

Remove business plugins (cleanup of #3079) #3170

Merged
merged 4 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion assets/stylesheets/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
@import 'my-sites/plugins/plugin-site-disabled-manage/style';
@import 'my-sites/plugins/plugin-site-jetpack/style';
@import 'my-sites/plugins/plugin-site-update-indicator/style';
@import 'my-sites/plugins/plugin-site-business/style';
@import 'my-sites/plugins/plugin-install-button/style';
@import 'my-sites/plugins/plugin-settings-link/style';
@import 'my-sites/plugins/plugin-remove-button/style';
Expand Down
4 changes: 3 additions & 1 deletion client/lib/accept/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ module.exports = React.createClass( {
displayName: 'AcceptDialog',

propTypes: {
// message can either be a string, an element or an array of string/elements (returned by `this.translate`)
message: React.PropTypes.oneOfType( [
React.PropTypes.string,
React.PropTypes.element
React.PropTypes.element,
React.PropTypes.array,
] ).isRequired,
onClose: React.PropTypes.func.isRequired,
confirmButtonText: React.PropTypes.string,
Expand Down
3 changes: 1 addition & 2 deletions client/lib/plugins/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var debug = require( 'debug' )( 'calypso:my-sites:plugins:actions' ),
*/
var analytics = require( 'analytics' ),
Dispatcher = require( 'dispatcher' ),
isBusiness = require( 'lib/products-values' ).isBusiness,
wpcom = require( 'lib/wp' ).undocumented();

var _actionsQueueBySite = {},
Expand Down Expand Up @@ -133,7 +132,7 @@ PluginsActions = {
},

fetchSitePlugins: function( site ) {
if ( ! site.user_can_manage || ( ! site.jetpack && ! isBusiness( site.plan ) ) ) {
if ( ! site.user_can_manage || ! site.jetpack ) {
defer( () => {
Dispatcher.handleViewAction( {
type: 'NOT_ALLOWED_TO_RECEIVE_PLUGINS',
Expand Down
4 changes: 0 additions & 4 deletions client/lib/plugins/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ function update( site, slug, plugin ) {
if ( ! _pluginsBySite[ site.ID ][ slug ] ) {
_pluginsBySite[ site.ID ][ slug ] = { slug: slug };
}
plugin = assign( {}, plugin, { wpcom: ! site.jetpack } );
plugin = PluginUtils.normalizePluginData( plugin );
plugin = PluginUtils.addWpcomIcon( plugin );
_pluginsBySite[ site.ID ][ slug ] = assign( {}, _pluginsBySite[ site.ID ][ slug ], plugin );

debug( 'update to ', _pluginsBySite[ site.ID ][ slug ] );
Expand Down Expand Up @@ -208,8 +206,6 @@ PluginsStore = {
return [];
}

plugins = PluginUtils.duplicateHybridPlugins( plugins );

if ( plugins.filter && !! pluginFilter ) {
plugins = plugins.filter( _filters[ pluginFilter ] );
}
Expand Down
41 changes: 1 addition & 40 deletions client/lib/plugins/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
var pick = require( 'lodash/pick' ),
assign = require( 'lodash/assign' ),
property = require( 'lodash/property' ),
reject = require( 'lodash/reject' ),
map = require( 'lodash/map' ),
filter = require( 'lodash/filter' ),
transform = require( 'lodash/transform' ),
Expand Down Expand Up @@ -87,8 +85,7 @@ PluginUtils = {
'update',
'updating',
'version',
'wp_admin_settings_page_url',
'wpcom'
'wp_admin_settings_page_url'
);
},

Expand Down Expand Up @@ -207,42 +204,6 @@ PluginUtils = {
} );
},

addWpcomIcon: function( plugin ) {
if ( plugin.slug && plugin.wpcom ) {
return assign( {}, plugin, { icon: '/calypso/images/upgrades/plugins/' + plugin.slug + '.png' } );
}

return plugin;
},
/**
* In order to handle the case in All Sites in which a plugin with the same slug is available on both
* a Jetpack site and a .com site, this method ensures that the plugin appears twice in the plugins array,
* with/without the wpcom flag.
*
* @param {Array} plugins - List of plugins
* @returns {Array} - List of plugins
*/
duplicateHybridPlugins: function( plugins ) {
return plugins.reduce( function( result, plugin ) {
if ( ( plugin.wpcom && plugin.sites.some( property( 'jetpack' ) ) ) ||
( ! plugin.wpcom && ! plugin.sites.every( property( 'jetpack' ) ) ) ) {
// this is a plugin shared by .com and Jetpack sites, add it twice with different sites
return result.concat(
assign( {}, plugin, {
sites: filter( plugin.sites, property( 'jetpack' ) ),
wpcom: false
} ),
PluginUtils.addWpcomIcon( assign( {}, plugin, {
sites: reject( plugin.sites, property( 'jetpack' ) ),
wpcom: true
} ) )
);
}

return result.concat( plugin );
}, [] );
},

normalizePluginsList: function( pluginsList ) {
if ( ! pluginsList ) {
return [];
Expand Down
13 changes: 0 additions & 13 deletions client/lib/sites-list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,19 +688,6 @@ SitesList.prototype.canManageSelectedOrAll = function() {
}
} );
};
/**
* Whether the user has any jetpack site that the user can manage
* @return bool
*/
SitesList.prototype.canManageAnyJetpack = function() {
return this.getJetpack().some( function( site ) {
if ( site.capabilities && site.capabilities.manage_options ) {
return true;
} else {
return false;
}
} );
};

SitesList.prototype.onUpdatedPlugin = function( site ) {
if ( ! site.jetpack ) {
Expand Down
76 changes: 9 additions & 67 deletions client/my-sites/plugins/access-control.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,30 @@
/**
* External Dependencies
*/
import React from 'react'

/**
* Internal Dependencies
*/
import PluginItem from 'my-sites/plugins/plugin-item/plugin-item'
import sitesList from 'lib/sites-list'
import i18n from 'lib/mixins/i18n'
import config from 'config'
import analytics from 'analytics'
import { isBusiness } from 'lib/products-values'
import notices from 'notices'

let sites = sitesList();
const sites = sitesList();

const hasErrorCondition = ( site, type ) => {
const errorConditions = {
noBusinessPlan: site && ! site.jetpack && ! isBusiness( site.plan ),
notMinimumJetpackVersion: site && ! site.hasMinimumJetpackVersion && site.jetpack,
notRightsToManagePlugins: sites.initialized && ! sites.canManageSelectedOrAll()
};
return errorConditions[ type ];
}

const getMockBusinessPluginItems = () => {
const plugins = [ {
slug: 'ecwid',
name: 'Ecwid',
wpcom: true,
icon: '/calypso/images/upgrades/plugins/ecwid.png'
}, {
slug: 'gumroad',
name: 'Gumroad',
wpcom: true,
icon: '/calypso/images/upgrades/plugins/gumroad.png'
}, {
slug: 'shopify',
name: 'Shopify',
wpcom: true,
icon: '/calypso/images/upgrades/plugins/shopify-store.png'
} ];
const selectedSite = {
slug: 'no-slug',
canUpdateFiles: true,
name: 'Not a real site'
}
};

return plugins.map( plugin => {
return React.createElement( PluginItem, {
key: 'plugin-item-mock-' + plugin.slug,
plugin: plugin,
sites: [],
selectedSite: selectedSite,
progress: [],
isMock: true
} );
} );
}

const getWpcomPluginPageError = ( siteSlug = '' ) => {
const getWpcomPluginPageError = () => {
return {
title: i18n.translate( 'Want to add a store to your site?' ),
line: i18n.translate( 'Support for Shopify, Ecwid, and Gumroad is now available for WordPress.com Business.' ),
action: i18n.translate( 'Upgrade Now' ),
actionURL: '/plans/' + siteSlug,
illustration: '/calypso/images/drake/drake-whoops.svg',
actionCallback: () => {
analytics.tracks.recordEvent( 'calypso_upgrade_nudge_cta_click', { cta_name: 'business_plugins' } );
},
featureExample: getMockBusinessPluginItems()
title: i18n.translate( 'Oops! Not supported' ),
line: i18n.translate( 'This site doesn\'t support installing plugins. Switch to a self-hosted site to install and manage plugins' ),
illustration: '/calypso/images/drake/drake-whoops.svg'
};
}
};

const hasRestrictedAccess = ( site ) => {
let pluginPageError;

site = site || sites.getSelectedSite();

// Display a 404 to users that don't have the rights to manage plugins
Expand All @@ -103,15 +51,9 @@ const hasRestrictedAccess = ( site ) => {
);
}

if ( hasErrorCondition( site, 'noBusinessPlan' ) ) {
pluginPageError = getWpcomPluginPageError( site.slug );
}

if ( ! sites.hasSiteWithPlugins() ) {
pluginPageError = getWpcomPluginPageError();
return getWpcomPluginPageError();
}

return pluginPageError;
}
};

export default { hasRestrictedAccess };
34 changes: 4 additions & 30 deletions client/my-sites/plugins/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ var lastPluginsListVisited,
lastPluginsQuerystring,
controller;

const businessPlugins = [ 'gumroad', 'shopify-store', 'ecwid' ];

function renderSinglePlugin( context, siteUrl, isWpcomPlugin ) {
function renderSinglePlugin( context, siteUrl ) {
var pluginSlug = decodeURIComponent( context.params.plugin ),
site = sites.getSelectedSite(),
analyticsPageTitle = 'Plugins',
Expand All @@ -43,29 +41,6 @@ function renderSinglePlugin( context, siteUrl, isWpcomPlugin ) {
baseAnalyticsPath += '/:site';
}

if ( site &&
site.jetpack &&
context.path.indexOf( '/business' ) >= 0 &&
businessPlugins.indexOf( pluginSlug ) >= 0
) {
return page.redirect( '/plugins/' + pluginSlug + '/' + site.slug );
}

if (
( site && ! site.jetpack ) &&
businessPlugins.indexOf( pluginSlug ) >= 0 &&
context.path.indexOf( '/business' ) < 0
) {
return page.redirect( '/plugins/' + pluginSlug + '/business' + ( site ? '/' + site.slug : '' ) );
}

if ( ! site &&
context.path.indexOf( '/business' ) >= 0 &&
-1 === businessPlugins.indexOf( pluginSlug )
) {
return page.redirect( '/plugins/' + pluginSlug );
}

analytics.pageView.record( baseAnalyticsPath, analyticsPageTitle + ' > Plugin Details' );

// Scroll to the top
Expand All @@ -80,7 +55,6 @@ function renderSinglePlugin( context, siteUrl, isWpcomPlugin ) {
sites: sites,
pluginSlug: pluginSlug,
siteUrl: siteUrl,
isWpcomPlugin: isWpcomPlugin,
onPluginRefresh: title => titleActions.setTitle( title )
} ),
document.getElementById( 'primary' ),
Expand Down Expand Up @@ -182,16 +156,15 @@ controller = {
},

plugin: function( context ) {
var isWpcomPlugin = 'business' === context.params.business_plugin,
siteUrl = route.getSiteFragment( context.path );
var siteUrl = route.getSiteFragment( context.path );

if ( siteUrl && context.params.plugin && context.params.plugin === siteUrl.toString() ) {
controller.plugins( 'all', context );
return;
}

notices.clearNotices( 'notices' );
renderSinglePlugin( context, siteUrl, isWpcomPlugin );
renderSinglePlugin( context, siteUrl );
},

browsePlugins: function( context ) {
Expand Down Expand Up @@ -220,6 +193,7 @@ controller = {
}
next();
},

setupPlugins: function() {
renderProvisionPlugins();
}
Expand Down
Loading