Skip to content

Commit

Permalink
Social: Update the admin page for use by Editors and Authors (#41859)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pablinos authored and matticbot committed Feb 24, 2025
1 parent 3b9fa89 commit 83e9fd6
Show file tree
Hide file tree
Showing 22 changed files with 224 additions and 174 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is an alpha version! The changes listed here are not final.
- Connection: Disconnecting a connection owner account will disconnect all other users first.
- Enabled Social Post UI for WPCOM sites
- Post List: Add a Copy Link Quick Action
- Social: Updated the admin page for use by Editors and Authors

### Changed
- Connection: Display connection status on Users page independent of the SSO module.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "GPL-2.0-or-later",
"require": {
"automattic/jetpack-admin-ui": "^0.5.2",
"automattic/jetpack-assets": "^4.0.7",
"automattic/jetpack-assets": "^4.0.8-alpha",
"automattic/jetpack-autoloader": "^5.0.1",
"automattic/jetpack-composer-plugin": "^4.0.0",
"automattic/jetpack-config": "^3.0.0",
Expand Down
8 changes: 8 additions & 0 deletions jetpack_vendor/automattic/jetpack-assets/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.8-alpha] - unreleased

This is an alpha version! The changes listed here are not final.

### Added
- User data: Added permissions to the current user object

## [4.0.7] - 2025-02-17
### Changed
- Update dependencies.
Expand Down Expand Up @@ -564,6 +571,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Statically access asset tools

[4.0.8-alpha]: https://github.com/Automattic/jetpack-assets/compare/v4.0.7...v4.0.8-alpha
[4.0.7]: https://github.com/Automattic/jetpack-assets/compare/v4.0.6...v4.0.7
[4.0.6]: https://github.com/Automattic/jetpack-assets/compare/v4.0.5...v4.0.6
[4.0.5]: https://github.com/Automattic/jetpack-assets/compare/v4.0.4...v4.0.5
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'ef2f2e5166a54321a227');
<?php return array('dependencies' => array(), 'version' => '71e696cb91a018077b9d');

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ protected static function get_current_user_data() {
return array(
'display_name' => $current_user->display_name,
'id' => $current_user->ID,
'capabilities' => array(
'manage_options' => current_user_can( 'manage_options' ),
'manage_modules' => current_user_can( 'jetpack_manage_modules' ),
),
);
}
}
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-connection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=7.2",
"automattic/jetpack-a8c-mc-stats": "^3.0.0",
"automattic/jetpack-admin-ui": "^0.5.2",
"automattic/jetpack-assets": "^4.0.7",
"automattic/jetpack-assets": "^4.0.8-alpha",
"automattic/jetpack-constants": "^3.0.1",
"automattic/jetpack-roles": "^3.0.1",
"automattic/jetpack-status": "^5.0.4-alpha",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-jitm/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": ">=7.2",
"automattic/jetpack-a8c-mc-stats": "^3.0.0",
"automattic/jetpack-assets": "^4.0.7",
"automattic/jetpack-assets": "^4.0.8-alpha",
"automattic/jetpack-connection": "^6.6.0-alpha",
"automattic/jetpack-device-detection": "^3.0.0",
"automattic/jetpack-logo": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-my-jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": ">=7.2",
"automattic/jetpack-admin-ui": "^0.5.2",
"automattic/jetpack-assets": "^4.0.7",
"automattic/jetpack-assets": "^4.0.8-alpha",
"automattic/jetpack-boost-speed-score": "^0.4.1",
"automattic/jetpack-connection": "^6.6.0-alpha",
"automattic/jetpack-explat": "^0.2.7",
Expand Down
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-post-list/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.2",
"automattic/jetpack-assets": "^4.0.7"
"automattic/jetpack-assets": "^4.0.8-alpha"
},
"require-dev": {
"automattic/jetpack-test-environment": "@dev",
Expand Down
3 changes: 3 additions & 0 deletions jetpack_vendor/automattic/jetpack-publicize/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

This is an alpha version! The changes listed here are not final.

### Added
- Social: Updated the admin page for use by Editors and Authors

### Changed
- Script data: extract less detailed host information.
- Social | Use new connections class for share status
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'd657850dce88be4f6b12');
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-date', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '6b225d426cb0ad12a8e9');

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-publicize/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"automattic/jetpack-connection": "^6.6.0-alpha",
"automattic/jetpack-autoloader": "^5.0.1",
"automattic/jetpack-config": "^3.0.0",
"automattic/jetpack-assets": "^4.0.7",
"automattic/jetpack-assets": "^4.0.8-alpha",
"automattic/jetpack-redirect": "^3.0.1",
"automattic/jetpack-plans": "^0.5.2",
"automattic/jetpack-status": "^5.0.4-alpha"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Automattic\Jetpack\Admin_UI\Admin_Menu;
use Automattic\Jetpack\Assets;
use Automattic\Jetpack\Publicize\Publicize_Utils as Utils;

/**
* The class to handle the Social Admin Page.
Expand Down Expand Up @@ -54,10 +55,16 @@ public function add_menu() {
// Remove the old Social menu item, if it exists.
Admin_Menu::remove_menu( 'jetpack-social' );

// If this isn't an admin (or someone with the capability to change the module status )
// and Publicize is inactive, then don't render the admin page.
if ( ! current_user_can( 'manage_options' ) && ! Utils::is_publicize_active() ) {
return;
}

$page_suffix = Admin_Menu::add_menu(
__( 'Jetpack Social', 'jetpack-publicize-pkg' ),
_x( 'Social', 'The Jetpack Social product name, without the Jetpack prefix', 'jetpack-publicize-pkg' ),
'manage_options',
'publish_posts',
'jetpack-social',
array( $this, 'render' ),
4
Expand Down
3 changes: 3 additions & 0 deletions jetpack_vendor/automattic/jetpack-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

This is an alpha version! The changes listed here are not final.

### Added
- Modules: Moved the custom capibilities from the Jetpack plugin

### Fixed
- Code: Prevent dynamic class properties.

Expand Down
24 changes: 24 additions & 0 deletions jetpack_vendor/automattic/jetpack-sync/src/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ public static function configure() {

// Set up package version hook.
add_filter( 'jetpack_package_versions', __NAMESPACE__ . '\Package_Version::send_package_version_to_tracker' );

// Add the custom capabilities for managing modules
add_filter( 'map_meta_cap', array( __CLASS__, 'module_custom_caps' ), 10, 2 );
}

/**
* Sets the Module custom capabilities.
*
* @param string[] $caps Array of the user's capabilities.
* @param string $cap Capability name.
* @return string[] The user's capabilities, adjusted as necessary.
*/
public static function module_custom_caps( $caps, $cap ) {
switch ( $cap ) {
case 'jetpack_manage_modules':
case 'jetpack_activate_modules':
case 'jetpack_deactivate_modules':
$caps = array( 'manage_options' );
break;
case 'jetpack_configure_modules':
$caps = array( 'manage_options' );
break;
}
return $caps;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
),
'jetpack-assets' => array(
'path' => 'jetpack_vendor/automattic/jetpack-assets',
'ver' => '4.0.7',
'ver' => '4.0.8-alpha1740396408',
),
'jetpack-boost-core' => array(
'path' => 'jetpack_vendor/automattic/jetpack-boost-core',
Expand Down Expand Up @@ -70,11 +70,11 @@
),
'jetpack-publicize-pkg' => array(
'path' => 'jetpack_vendor/automattic/jetpack-publicize',
'ver' => '0.60.2-alpha1740070348',
'ver' => '0.60.2-alpha1740396408',
),
'jetpack-sync' => array(
'path' => 'jetpack_vendor/automattic/jetpack-sync',
'ver' => '4.8.2-alpha1740070348',
'ver' => '4.8.2-alpha1740396408',
),
),
);
Loading

0 comments on commit 83e9fd6

Please sign in to comment.