Skip to content

Commit

Permalink
Connection: add modal for disconnecting owner account (#41923)
Browse files Browse the repository at this point in the history
  • Loading branch information
bindlegirl authored and matticbot committed Feb 24, 2025
1 parent 9a2b369 commit a0c38aa
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 133 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

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

### Added
- Connection: Disconnecting a connection owner account will disconnect all other users first.

### Changed
- Code: Use function-style exit() and die() with a default status code of 0.
- Connection: Display connection status on Users page independent of the SSO module.
Expand Down
3 changes: 3 additions & 0 deletions jetpack_vendor/automattic/jetpack-connection/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
- Connection: Disconnection connection ower will disconnect all other users first.

### Changed
- moved endpoint for unlinking user to connection package

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => '3a37101ab5cb857d48cd');
<?php return array('dependencies' => array('react', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-url'), 'version' => 'd5c9b5c171dc14dcc54a');

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('jetpack-script-data', 'react', 'react-jsx-runtime', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => 'e26cbfaac86c4072d9fc');
<?php return array('dependencies' => array('jetpack-script-data', 'react', 'react-jsx-runtime', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '51f69fbd939224c71267');

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions jetpack_vendor/automattic/jetpack-connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,19 +944,48 @@ public function connect_user( $user_id = null, $redirect_url = null ) {
/**
* Force user disconnect.
*
* @param int $user_id Local (external) user ID.
* @param int $user_id Local (external) user ID.
* @param bool $disconnect_all_users Whether to disconnect all users before disconnecting the primary user.
*
* @return bool
*/
public function disconnect_user_force( $user_id ) {
public function disconnect_user_force( $user_id, $disconnect_all_users = false ) {
if ( ! (int) $user_id ) {
// Missing user ID.
return false;
}
// If we are disconnecting the primary user we may need to disconnect all other users first
if ( $user_id === $this->get_connection_owner_id() && $disconnect_all_users && ! $this->disconnect_all_users_except_primary() ) {
return false;
}

return $this->disconnect_user( $user_id, true, true );
}

/**
* Disconnects all users except the primary user.
*
* @return bool
*/
public function disconnect_all_users_except_primary() {

$all_connected_users = $this->get_connected_users();

foreach ( $all_connected_users as $user ) {
// Skip the primary.
if ( $user->ID === $this->get_connection_owner_id() ) {
continue;
}
$disconnected = $this->disconnect_user( $user->ID, false, true );
// If we fail to disconnect any user, we should not proceed with disconnecting the primary user.
if ( ! $disconnected ) {
return false;
}
}

return true;
}

/**
* Unlinks the current user from the linked WordPress.com user.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,20 @@ public static function unlink_user( $request ) {
return new WP_Error( 'invalid_param', esc_html__( 'Invalid Parameter', 'jetpack-connection' ), array( 'status' => 404 ) );
}

// If the user is also connection owner, we need to disconnect all users. Since disconnecting all users is a destructive action, we need to pass a parameter to confirm the action.
$disconnect_all_users = false;

if ( ( new Manager() )->get_connection_owner_id() === get_current_user_id() ) {
if ( isset( $request['disconnect-all-users'] ) && false !== $request['disconnect-all-users'] ) {
$disconnect_all_users = true;
} else {
return new WP_Error( 'unlink_user_failed', esc_html__( 'Unable to unlink the connection owner.', 'jetpack-connection' ), array( 'status' => 400 ) );
}
}

// Allow admins to force a disconnect by passing the "force" parameter
// This allows an admin to disconnect themselves
if ( isset( $request['force'] ) && false !== $request['force'] && current_user_can( 'manage_options' ) && ( new Manager( 'jetpack' ) )->disconnect_user_force( get_current_user_id() ) ) {
if ( isset( $request['force'] ) && false !== $request['force'] && current_user_can( 'manage_options' ) && ( new Manager( 'jetpack' ) )->disconnect_user_force( get_current_user_id(), $disconnect_all_users ) ) {
return rest_ensure_response(
array(
'code' => 'success',
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-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-polyfill', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => '4d0b2cfaa264221ae46c');
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-polyfill', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => '0063d3a8b218022c89ac');

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '00292b3fc25821274302');
<?php return array('dependencies' => array('jetpack-connection', 'jetpack-script-data', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '3581caa51b8c2d901eac');

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jetpack_vendor/i18n-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
),
'jetpack-connection' => array(
'path' => 'jetpack_vendor/automattic/jetpack-connection',
'ver' => '6.6.0-alpha1739926846',
'ver' => '6.6.0-alpha1740393816',
),
'jetpack-explat' => array(
'path' => 'jetpack_vendor/automattic/jetpack-explat',
Expand Down
58 changes: 29 additions & 29 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-a8c-mc-stats",
"reference": "efb608fbecbbf7007c00321ba1db46e6af2b237b"
"reference": "f25ecf112ada090395139a57f5b6116b37355055"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -63,7 +63,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-admin-ui",
"reference": "90c5f133e99d1e0106e66b1a51e18ec39e054396"
"reference": "6c44a4ef47ab48930d480ba109c555989c073ebd"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -125,7 +125,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-assets",
"reference": "07eb33942db7aad4921d8b0d2525ba974255265f"
"reference": "b5df6acc4bcbfceb8f6da7cf2179b52563e3f2d0"
},
"require": {
"automattic/jetpack-constants": "^3.0.1",
Expand Down Expand Up @@ -197,7 +197,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-autoloader",
"reference": "e2e1a2f88151d88e1d05ce2bdb879561eaca527e"
"reference": "1a1f880491b6c918fbe6e216fba257b3631521cd"
},
"require": {
"composer-plugin-api": "^2.2",
Expand Down Expand Up @@ -268,7 +268,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-boost-core",
"reference": "b85a3dbb01a60e6054a67a2da584df0739f1ea3b"
"reference": "8c423a16be8d37ff8e883230d315e7801652f291"
},
"require": {
"automattic/jetpack-connection": "^6.6.0-alpha",
Expand Down Expand Up @@ -326,7 +326,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-boost-speed-score",
"reference": "41e7521ce669cd264e3e785b7ee9f853f4e3cdfc"
"reference": "7d035bb30a164ecdc98b786cf9ca3a6dfe7619b8"
},
"require": {
"automattic/jetpack-boost-core": "^0.3.5",
Expand Down Expand Up @@ -393,7 +393,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-composer-plugin",
"reference": "0d12d5bf5dba9e27202df5ecec1cba2e233bdfdc"
"reference": "938f55942b05eab499953c0ac730e6bd19fcd178"
},
"require": {
"composer-plugin-api": "^2.2",
Expand Down Expand Up @@ -456,7 +456,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-config",
"reference": "39692508a82dc313d60166189efee4b03503bb2f"
"reference": "f38f6b1ebbae446b9b1bfb35f8cfd60f2abefb99"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -526,12 +526,12 @@
},
{
"name": "automattic/jetpack-connection",
"version": "6.6.0-alpha.1739926846",
"version_normalized": "6.6.0.0-alpha1739926846",
"version": "6.6.0-alpha.1740393816",
"version_normalized": "6.6.0.0-alpha1740393816",
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-connection",
"reference": "87c8fd7fac9a33aa6d9fe02024b173c3be63f5a4"
"reference": "7e8a59c51f397c2273d8e0c0740afdd8ab7eb8e8"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^3.0.0",
Expand Down Expand Up @@ -618,7 +618,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-constants",
"reference": "fa4180ab8613bd13f26b5d934e1f98653db4b8f9"
"reference": "51ad27a542957ee6bdddf66300f3c8a3921ab738"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -675,7 +675,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-device-detection",
"reference": "559045e77243d36b570d0ca56085122e0b811199"
"reference": "2396cd985392372e34893575f8da7726dd8b9ea8"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -731,7 +731,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-explat",
"reference": "e2a3f842fcbd89a8fd8f907ba01bcca36365c1f3"
"reference": "eb7e15530d1417650627d2d43c10b13aa27dbffe"
},
"require": {
"automattic/jetpack-connection": "^6.6.0-alpha",
Expand Down Expand Up @@ -809,7 +809,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-ip",
"reference": "5d69db73ad3fd2a40b129808d1d6cc3c8a719ee1"
"reference": "5e37849658eb77018e3b940dab15c8e4cba650b2"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -870,7 +870,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-jitm",
"reference": "a4f4a2fbd39ef83431857bbdfbb78b87940bbd0b"
"reference": "520842113695b4edda07f78da421f545e2efb857"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^3.0.0",
Expand Down Expand Up @@ -948,7 +948,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-licensing",
"reference": "c5bbfadb99484bee26883c17acd512e122443b52"
"reference": "c19c7bff708ffb2eebbda1e49286ad171b519359"
},
"require": {
"automattic/jetpack-connection": "^6.6.0-alpha",
Expand Down Expand Up @@ -1007,7 +1007,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-logo",
"reference": "d5fafefd3acaee07ae83df381fbace9b82a4edd8"
"reference": "e95b5c643eb4ab5347ccf48f8c22f75d68ef10ea"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -1063,7 +1063,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-my-jetpack",
"reference": "a25220c6d499fe12c33b37087700cae47b75ff85"
"reference": "4af1e1fb5dbfab0c23050fe6832097a43e38a339"
},
"require": {
"automattic/jetpack-admin-ui": "^0.5.2",
Expand Down Expand Up @@ -1162,7 +1162,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-password-checker",
"reference": "16a00407e52fcb62f9ed05d2b228a18dc957adaa"
"reference": "ba417b6e905cb157a1a9f0de5f443addbc6dc623"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -1220,7 +1220,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plans",
"reference": "0a95d712d1819236f72a39f79cc2ab57e5e4a026"
"reference": "bba0e86a118df1dc5f87d2ec39d04849b7a86cae"
},
"require": {
"automattic/jetpack-connection": "^6.6.0-alpha",
Expand Down Expand Up @@ -1285,7 +1285,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-plugins-installer",
"reference": "3a0f2c37ae79e013424b12f0a17bc3828af45320"
"reference": "02cb9bda4b27a9a510a2d73d0bb8b5a667ae6392"
},
"require": {
"automattic/jetpack-a8c-mc-stats": "^3.0.0",
Expand Down Expand Up @@ -1344,7 +1344,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-protect-models",
"reference": "ae25e31eaf1bc494317e8fcd865342196c508eb9"
"reference": "a2708a37dd5345054224e68c2342b5af7bc076bb"
},
"require": {
"automattic/jetpack-redirect": "^3.0.1",
Expand Down Expand Up @@ -1412,7 +1412,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-protect-status",
"reference": "f70c3b47fd92fb3dc1b271b7a5493c28efc1ab85"
"reference": "784cabbfbddd0bb1555e6189508b20459017333e"
},
"require": {
"automattic/jetpack-connection": "^6.6.0-alpha",
Expand Down Expand Up @@ -1484,7 +1484,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-redirect",
"reference": "a519b218cd1ed896217de55f08c713f1ee47b094"
"reference": "31fa9c4618480cd5b28ccee84451579d85f5611b"
},
"require": {
"automattic/jetpack-status": "^5.0.4-alpha",
Expand Down Expand Up @@ -1542,7 +1542,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-roles",
"reference": "54b360fe7c83b5ae3277a0bbc95fcf2ad25ed2d7"
"reference": "d77f4edaa5aa84900714cd8d73aa1202daa19002"
},
"require": {
"php": ">=7.2"
Expand Down Expand Up @@ -1599,7 +1599,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-status",
"reference": "298fdf80da8fb3d9335506adc5b787c4ec0a939b"
"reference": "e28c2ebbcc8d9e53f0f3f8367ddc9c9dff771eb7"
},
"require": {
"automattic/jetpack-constants": "^3.0.1",
Expand Down Expand Up @@ -1666,7 +1666,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-sync",
"reference": "2dd95101a8edb282382579ea4d0d90998d9939bc"
"reference": "f79ffa1833e78b63d96b7fca17b40e1be6323ba2"
},
"require": {
"automattic/jetpack-connection": "^6.6.0-alpha",
Expand Down Expand Up @@ -1741,7 +1741,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-videopress",
"reference": "111b5075bae3a922e6ead57f6defe11f9870c117"
"reference": "77d1ac4bd713390e7ad191abf67ba9b3060540c3"
},
"require": {
"automattic/jetpack-admin-ui": "^0.5.2",
Expand Down
Loading

0 comments on commit a0c38aa

Please sign in to comment.