Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/error when non admin user disconnects site #40371

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix error when non-admin disconnects
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const StepDisconnect = props => {
</div>
</div>
{ disconnectError && (
<p className="jp-connection__disconnect-dialog__error">{ disconnectError }</p>
<p className="jp-connection__disconnect-dialog__error">{ disconnectError.toString() }</p>
) }
</div>
</React.Fragment>
Expand All @@ -188,7 +188,7 @@ StepDisconnect.propTypes = {
/** Callback function that is triggered by clicking the "Disconnect" button. */
onDisconnect: PropTypes.func,
/** An error that occurred during a request to disconnect. */
disconnectError: PropTypes.bool,
disconnectError: PropTypes.oneOfType( [ PropTypes.object, PropTypes.bool ] ),
/** A component to be rendered as part of this step */
disconnectStepComponent: PropTypes.element,
/** Plugins that are using the Jetpack connection. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix error when non-admin tries to disconnect user account
7 changes: 6 additions & 1 deletion projects/packages/connection/src/class-rest-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public static function connection_plugins_permission_check() {
* @return bool|WP_Error True if user is able to disconnect the site or the request is signed with a blog token (aka a direct request from WPCOM).
*/
public static function disconnect_site_permission_check() {
if ( current_user_can( 'jetpack_disconnect' ) ) {
if ( current_user_can( 'jetpack_disconnect' ) || current_user_can( 'jetpack_connect_user' ) ) {
return true;
}

Expand Down Expand Up @@ -918,6 +918,11 @@ public static function update_user_token( $request ) {
public static function disconnect_site() {
$connection = new Manager();

if ( ! current_user_can( 'jetpack_disconnect' ) ) {
$connection->disconnect_user();
return rest_ensure_response( array( 'code' => 'success' ) );
}

if ( $connection->is_connected() ) {
$connection->disconnect_site();
return rest_ensure_response( array( 'code' => 'success' ) );
Expand Down
Loading