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 a0c38aa commit 418f760
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 135 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "wordpress-plugin",
"license": "GPL-2.0-or-later",
"require": {
"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
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
2 changes: 1 addition & 1 deletion jetpack_vendor/automattic/jetpack-videopress/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-connection": "^6.6.0-alpha",
"automattic/jetpack-my-jetpack": "^5.5.0-alpha",
"automattic/jetpack-plans": "^0.5.2"
Expand Down
4 changes: 2 additions & 2 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 @@ -66,7 +66,7 @@
),
'jetpack-sync' => array(
'path' => 'jetpack_vendor/automattic/jetpack-sync',
'ver' => '4.8.2-alpha1740070348',
'ver' => '4.8.2-alpha1740396408',
),
'jetpack-videopress-pkg' => array(
'path' => 'jetpack_vendor/automattic/jetpack-videopress',
Expand Down
Loading

0 comments on commit 418f760

Please sign in to comment.