Skip to content

Commit

Permalink
Merge pull request #2562 from Automattic/fix/plugins-not-available-on…
Browse files Browse the repository at this point in the history
…-any-site

Plugins: Fix/plugins not available on any site
  • Loading branch information
enejb committed Jan 28, 2016
2 parents 3254429 + 2fe300c commit 3f55b21
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
12 changes: 8 additions & 4 deletions client/lib/sites-list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var debug = require( 'debug' )( 'calypso:sites-list' ),
store = require( 'store' ),
assign = require( 'lodash/object/assign' ),
find = require( 'lodash/collection/find' ),
isEmpty = require( 'lodash/lang/isEmpty' ),
some = require( 'lodash/collection/some' );

/**
Expand Down Expand Up @@ -528,13 +529,16 @@ SitesList.prototype.getSelectedOrAllJetpackCanManage = function() {
};

SitesList.prototype.getSelectedOrAllWithPlugins = function() {
return this.getSelectedOrAll().filter( site => ( isBusiness( site.plan ) || site.jetpack ) && ( site.visible || this.selected ) );
return this.getSelectedOrAll().filter( site => {
return site.capabilities &&
site.capabilities.manage_options &&
( isBusiness( site.plan ) || site.jetpack ) &&
( site.visible || this.selected )
} );
};

SitesList.prototype.hasSiteWithPlugins = function() {
return some( this.get(), function( site ) {
return isBusiness( site.plan ) || site.jetpack;
} );
return ! isEmpty( this.getSelectedOrAllWithPlugins() );
};

SitesList.prototype.fetchAvailableUpdates = function() {
Expand Down
45 changes: 32 additions & 13 deletions client/my-sites/plugins/access-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,28 @@ const getMockBusinessPluginItems = () => {
} );
}

const getWpcomPluginPageError = ( siteSlug = '' ) => {
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()
};
}

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

site = site || sites.getSelectedSite();

// Display a 404 to users that don't have the rights to manage plugins
if ( hasErrorCondition( site, 'notRightsToManagePlugins' ) ) {
pluginPageError = {
return {
title: i18n.translate( 'Not Available' ),
line: i18n.translate( 'The page you requested could not be found' ),
illustration: '/calypso/images/drake/drake-404.svg',
Expand All @@ -90,18 +104,23 @@ const hasRestrictedAccess = ( site ) => {
);
}

if ( abtest( 'businessPluginsNudge' ) === 'drake' && hasErrorCondition( site, 'noBusinessPlan' ) ) {
pluginPageError = {
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/' + site.slug,
illustration: '/calypso/images/drake/drake-whoops.svg',
actionCallback: () => {
analytics.tracks.recordEvent( 'calypso_upgrade_nudge_cta_click', { cta_name: 'business_plugins' } );
},
featureExample: getMockBusinessPluginItems()
};
if ( hasErrorCondition( site, 'noBusinessPlan' ) ) {
switch ( abtest( 'businessPluginsNudge' ) ) {
case 'nudge':
pluginPageError = {
abtest: 'nudge'
};
break;

case 'drake':
default:
pluginPageError = getWpcomPluginPageError( site.slug );
break;
}
}

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

return pluginPageError;
Expand Down
24 changes: 11 additions & 13 deletions client/my-sites/plugins/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import get from 'lodash/object/get';
/**
* Internal dependencies
*/
import { abtest } from 'lib/abtest';
import Main from 'components/main';
import SidebarNavigation from 'my-sites/sidebar-navigation';
import pluginsAccessControl from 'my-sites/plugins/access-control';
import { isBusiness } from 'lib/products-values';
import PluginItem from './plugin-item/plugin-item';
import SectionNav from 'components/section-nav';
import NavTabs from 'components/section-nav/tabs';
Expand Down Expand Up @@ -353,7 +351,17 @@ const PluginsMain = React.createClass( {
},

render() {
const selectedSite = this.props.sites.getSelectedSite();

if ( this.state.accessError ) {
if ( this.state.accessError.abtest === 'nudge' ) {
return (
<Main>
<SidebarNavigation />
<PlanNudge currentProductId={ selectedSite.plan.product_id } selectedSiteSlug={ selectedSite.slug } />
</Main>
);
}
return (
<Main>
<SidebarNavigation />
Expand All @@ -363,23 +371,13 @@ const PluginsMain = React.createClass( {
);
}

const selectedSite = this.props.sites.getSelectedSite();
if ( abtest( 'businessPluginsNudge' ) === 'nudge' && selectedSite && ! selectedSite.jetpack && ! isBusiness( selectedSite.plan ) ) {
return (
<Main>
<SidebarNavigation />
<PlanNudge currentProductId={ selectedSite.plan.product_id } selectedSiteSlug={ selectedSite.slug } />
</Main>
);
}

if ( selectedSite && selectedSite.jetpack && ! selectedSite.canManage() ) {
return (
<Main>
<SidebarNavigation />
<JetpackManageErrorPage
template="optInManage"
site={ this.props.sites.getSelectedSite() }
site={ selectedSite }
title={ this.translate( 'Looking to manage this site\'s plugins?' ) }
section="plugins"
featureExample={ this.getMockPluginItems() } />
Expand Down
6 changes: 5 additions & 1 deletion client/my-sites/sidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ module.exports = React.createClass( {
return null;
}

if ( ! this.props.sites.canManageSelectedOrAll() ) {
if ( ! this.props.sites.canManageSelectedOrAll() ) {
return null;
}

if ( ! this.props.sites.hasSiteWithPlugins() && ! this.isSingle() ) {
return null;
}

Expand Down

0 comments on commit 3f55b21

Please sign in to comment.