From faea43e25fa0c41e69bfff73b28c2454dbde200d Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Tue, 20 Mar 2018 23:45:08 +0300 Subject: [PATCH 1/2] Not showing connection view if the user cannot connect. Fixes #8066. This PR adds a check to the connection view condition. Before we would not show anything to the user if they could not manage modules. Now we add the connect privilege check here as well, so the same thing happens if a user does not have the 'jetpack_connect' cap. --- _inc/client/main.jsx | 6 ++++-- _inc/client/state/initial-state/reducer.js | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/_inc/client/main.jsx b/_inc/client/main.jsx index e7a3867152a2e..1d0a93f85fd9b 100644 --- a/_inc/client/main.jsx +++ b/_inc/client/main.jsx @@ -25,7 +25,8 @@ import { getSiteAdminUrl, getApiNonce, getApiRootUrl, - userCanManageModules + userCanManageModules, + userCanConnectSite } from 'state/initial-state'; import { areThereUnsavedSettings, clearUnsavedSettingsFlag, showWelcomeForNewPlan } from 'state/settings'; import { getSearchTerm } from 'state/search'; @@ -156,7 +157,7 @@ class Main extends React.Component { // Track page views this.props.isSiteConnected && analytics.tracks.recordEvent( 'jetpack_wpa_page_view', { path: route } ); - if ( ! this.props.userCanManageModules ) { + if ( ! this.props.userCanManageModules || ! this.props.userCanConnectSite ) { if ( ! this.props.siteConnectionStatus ) { return false; } @@ -282,6 +283,7 @@ export default connect( tracksUserData: getTracksUserData( state ), areThereUnsavedSettings: areThereUnsavedSettings( state ), userCanManageModules: userCanManageModules( state ), + userCanConnectSite: userCanConnectSite( state ), isSiteConnected: isSiteConnected( state ), newPlanActivated: showWelcomeForNewPlan( state ), rewindStatus: getRewindStatus( state ), diff --git a/_inc/client/state/initial-state/reducer.js b/_inc/client/state/initial-state/reducer.js index a3edb18e56133..48f203d09a748 100644 --- a/_inc/client/state/initial-state/reducer.js +++ b/_inc/client/state/initial-state/reducer.js @@ -114,6 +114,10 @@ export function userCanDisconnectSite( state ) { return get( state.jetpack.initialState.userData.currentUser.permissions, 'disconnect', false ); } +export function userCanConnectSite( state ) { + return get( state.jetpack.initialState.userData.currentUser.permissions, 'connect', false ); +} + export function userIsMaster( state ) { return get( state.jetpack.initialState.userData.currentUser, 'isMaster', false ); } From 8ec1b7e37665c1eedc136aa86423b33f774914f3 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 21 Mar 2018 23:44:24 +0300 Subject: [PATCH 2/2] Modified the privilege to check for connect cap instead of module management. --- _inc/client/components/jetpack-notices/index.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/_inc/client/components/jetpack-notices/index.jsx b/_inc/client/components/jetpack-notices/index.jsx index a1f80ceef0ffa..52189d0542d91 100644 --- a/_inc/client/components/jetpack-notices/index.jsx +++ b/_inc/client/components/jetpack-notices/index.jsx @@ -14,7 +14,11 @@ import NoticesList from 'components/global-notices'; */ import JetpackStateNotices from './state-notices'; import { getSiteConnectionStatus, getSiteDevMode, isStaging, isInIdentityCrisis, isCurrentUserLinked } from 'state/connection'; -import { isDevVersion, userCanManageModules, userIsSubscriber } from 'state/initial-state'; +import { + isDevVersion, + userCanConnectSite, + userIsSubscriber +} from 'state/initial-state'; import DismissableNotices from './dismissable'; import { getConnectUrl as _getConnectUrl } from 'state/connection'; import JetpackBanner from 'components/jetpack-banner'; @@ -203,7 +207,10 @@ class JetpackNotices extends React.Component { siteConnected={ true === this.props.siteConnectionStatus } isLinked={ this.props.isLinked } /> { - ( ! this.props.siteConnectionStatus && ! this.props.userCanManageModules ) && ( + ( + ! this.props.siteConnectionStatus && + ! this.props.userCanConnectSite + ) && (