Skip to content

Commit 2de5419

Browse files
pablinosmatticbot
authored andcommitted
Social: Update the admin page for use by Editors and Authors (#41859)
* Add the user permissions to script data. * Allow Editors and Authors to manage Social in Jetpack * Only register the admin page if the user has permissions * Only render the module toggle if the user has permission * Move the module capabilities to the sync package The Sync package holds the Modules class that handles the actions to manage the modules. We need the custom capibility to turn the module on and off on the Social admin page, but it's likely to be generally useful for other standalone plugins. * Add changelogs * Refine the permissions type * Update the user capabilities script-data utilities * Implement UserCapabilities interface * Implement the hideToggle logic for the description * Remove unused import Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13496936847 Upstream-Ref: Automattic/jetpack@e3e42e3
1 parent e467349 commit 2de5419

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This is an alpha version! The changes listed here are not final.
1111

1212
### Added
1313
- Added support for Bluesky video selection
14+
- Social: Updated the admin page for use by Editors and Authors
1415

1516
### Fixed
1617
- Fixed an issue with unsupported connection showing up

src/components/admin-page/index.tsx

+16-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
isJetpackSelfHostedSite,
1212
isSimpleSite,
1313
siteHasFeature,
14+
currentUserCan,
1415
} from '@automattic/jetpack-script-data';
1516
import { useSelect } from '@wordpress/data';
1617
import { useState, useCallback } from '@wordpress/element';
@@ -57,6 +58,8 @@ export const SocialAdminPage = () => {
5758
? `Jetpack Social ${ social.version }`
5859
: `Jetpack ${ jetpack.version }`;
5960

61+
const canManageOptions = currentUserCan( 'manage_options' );
62+
6063
if ( showConnectionCard ) {
6164
return (
6265
<AdminPage moduleName={ moduleName } showHeader={ false } showBackground={ false }>
@@ -92,15 +95,19 @@ export const SocialAdminPage = () => {
9295
</AdminSectionHero>
9396
<AdminSection>
9497
<SocialModuleToggle />
95-
{ isModuleEnabled && <UtmToggle /> }
96-
{
97-
// Only show the Social Notes toggle if Social plugin is active
98-
social.version && isModuleEnabled && (
99-
<SocialNotesToggle disabled={ isUpdatingJetpackSettings } />
100-
)
101-
}
102-
{ isModuleEnabled && siteHasFeature( features.IMAGE_GENERATOR ) && (
103-
<SocialImageGeneratorToggle disabled={ isUpdatingJetpackSettings } />
98+
{ canManageOptions && (
99+
<>
100+
{ isModuleEnabled && <UtmToggle /> }
101+
{
102+
// Only show the Social Notes toggle if Social plugin is active
103+
social.version && isModuleEnabled && (
104+
<SocialNotesToggle disabled={ isUpdatingJetpackSettings } />
105+
)
106+
}
107+
{ isModuleEnabled && siteHasFeature( features.IMAGE_GENERATOR ) && (
108+
<SocialImageGeneratorToggle disabled={ isUpdatingJetpackSettings } />
109+
) }
110+
</>
104111
) }
105112
</AdminSection>
106113
<AdminSectionHero>

src/components/admin-page/test/index.test.jsx

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ describe( 'load the app', () => {
2323
},
2424
},
2525
},
26+
user: {
27+
current_user: {
28+
capabilities: {},
29+
},
30+
},
2631
};
2732
} );
2833

src/components/admin-page/toggles/social-module-toggle/index.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
getRedirectUrl,
66
useBreakpointMatch,
77
} from '@automattic/jetpack-components';
8-
import { getScriptData, isWpcomPlatformSite } from '@automattic/jetpack-script-data';
8+
import {
9+
getScriptData,
10+
isWpcomPlatformSite,
11+
currentUserCan,
12+
} from '@automattic/jetpack-script-data';
913
import { ExternalLink } from '@wordpress/components';
1014
import { useSelect, useDispatch } from '@wordpress/data';
1115
import { __, _x } from '@wordpress/i18n';
@@ -77,9 +81,10 @@ const SocialModuleToggle: React.FC = () => {
7781
) : null;
7882
};
7983

84+
const hideToggle = is_wpcom || ! currentUserCan( 'manage_modules' );
8085
return (
8186
<ToggleSection
82-
hideToggle={ is_wpcom }
87+
hideToggle={ hideToggle }
8388
title={ __(
8489
'Automatically share your posts to social networks',
8590
'jetpack-publicize-components'
@@ -89,7 +94,7 @@ const SocialModuleToggle: React.FC = () => {
8994
onChange={ toggleModule }
9095
>
9196
<Text className={ styles.text }>
92-
{ ! is_wpcom
97+
{ ! hideToggle
9398
? _x(
9499
'When enabled, you’ll be able to connect your social media accounts and send a post’s featured image and content to the selected channels with a single click when the post is published.',
95100
'Description of the feature that the toggle enables',

0 commit comments

Comments
 (0)