Skip to content

Commit

Permalink
Not showing connection view if the user cannot connect. (#9102)
Browse files Browse the repository at this point in the history
* 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.

* Modified the privilege to check for connect cap instead of module management.
  • Loading branch information
zinigor authored and dereksmart committed Mar 26, 2018
1 parent 08b020b commit 69e7a4d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 10 additions & 3 deletions _inc/client/components/jetpack-notices/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
) && (
<SimpleNotice
showDismiss={ false }
status="is-warning"
Expand All @@ -221,7 +228,7 @@ export default connect(
return {
connectUrl: _getConnectUrl( state ),
siteConnectionStatus: getSiteConnectionStatus( state ),
userCanManageModules: userCanManageModules( state ),
userCanConnectSite: userCanConnectSite( state ),
userIsSubscriber: userIsSubscriber( state ),
isLinked: isCurrentUserLinked( state ),
isDevVersion: isDevVersion( state ),
Expand Down
6 changes: 4 additions & 2 deletions _inc/client/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -283,6 +284,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 ),
Expand Down
4 changes: 4 additions & 0 deletions _inc/client/state/initial-state/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 69e7a4d

Please sign in to comment.