Skip to content

Commit

Permalink
SSO: Log error message from user invite response (#37144)
Browse files Browse the repository at this point in the history
* Log error message from user invite response

* changelog

* Check for wp_error

* Retrieve error message

* Copy changes to connection package

* changelog

* Connection package version update

* Display user invite error message

* update query param key

* Update logic to display error message on users screen

* Sync latest sso user admin changes in Connection package

* Update connection package version

* Remove duplicate changelogs

* Update projects/packages/connection/src/sso/class-user-admin.php

Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

* Update projects/packages/connection/src/sso/class-user-admin.php

Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

* Update projects/plugins/jetpack/modules/sso/class.jetpack-sso-user-admin.php

Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

* Update projects/plugins/jetpack/modules/sso/class.jetpack-sso-user-admin.php

Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>

* Display api error response for invite revoke

* Update revoke user invite error tracking

* Bump version

---------

Co-authored-by: mindbuc <immanuelkanterino@gmail.com>
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
  • Loading branch information
3 people authored May 10, 2024
1 parent 17a3a97 commit 83fcea8
Show file tree
Hide file tree
Showing 34 changed files with 176 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

SSO: Improve user invite error logging
2 changes: 1 addition & 1 deletion projects/packages/connection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"link-template": "https://github.com/Automattic/jetpack-connection/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "2.7.x-dev"
"dev-trunk": "2.8.x-dev"
},
"dependencies": {
"test-only": [
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '2.7.7';
const PACKAGE_VERSION = '2.8.0-alpha';

const PACKAGE_SLUG = 'connection';

Expand Down
55 changes: 41 additions & 14 deletions projects/packages/connection/src/sso/class-user-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,18 @@ public function revoke_user_invite( $user_id ) {
$event = 'sso_user_invite_revoked';

if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
$body = json_decode( wp_remote_retrieve_body( $response ) );
$tracking_event_data = array(
'success' => 'false',
'error_code' => 'invalid-revoke-api-error',
);

if ( ! empty( $body ) && ! empty( $body->message ) ) {
$tracking_event_data['error_message'] = $body->message;
}
self::$tracking->record_user_event(
$event,
array(
'success' => 'false',
'error_message' => 'invalid-revoke-api-error',
)
$tracking_event_data
);
return $response;
}
Expand Down Expand Up @@ -171,6 +177,10 @@ public function handle_invitation_results() {
return wp_admin_notice( __( 'User invite revoked successfully.', 'jetpack-connection' ), array( 'type' => 'success' ) );
}

if ( $_GET['jetpack-sso-invite-user'] === 'failed' && isset( $_GET['jetpack-sso-api-error-message'] ) ) {
return wp_admin_notice( wp_kses( wp_unslash( $_GET['jetpack-sso-api-error-message'] ), array() ), array( 'type' => 'error' ) );
}

if ( $_GET['jetpack-sso-invite-user'] === 'failed' && isset( $_GET['jetpack-sso-invite-error'] ) ) {
switch ( $_GET['jetpack-sso-invite-error'] ) {
case 'invalid-user':
Expand Down Expand Up @@ -261,19 +271,27 @@ public function invite_user_to_wpcom() {
);

if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
$error = 'invalid-invite-api-error';
$error_code = 'invalid-invite-api-error';
$query_params = array(
'jetpack-sso-invite-user' => 'failed',
'jetpack-sso-invite-error' => $error,
'jetpack-sso-invite-error' => $error_code,
'_wpnonce' => $nonce,
);

$tracking_event_data = array(
'success' => 'false',
'error_code' => $error_code,
);

$body = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! empty( $body ) && ! empty( $body->message ) ) {
$query_params['jetpack-sso-api-error-message'] = $body->message;
$tracking_event_data['error_message'] = $body->message;
}

self::$tracking->record_user_event(
$event,
array(
'success' => 'false',
'error_message' => $error,
)
$tracking_event_data
);
return self::create_error_notice_and_redirect( $query_params );
}
Expand Down Expand Up @@ -410,12 +428,21 @@ public function handle_request_revoke_invite() {
'jetpack-sso-invite-error' => $error, // general error message
'_wpnonce' => $nonce,
);

$tracking_event_data = array(
'success' => 'false',
'error_code' => $error,
);

$body = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! empty( $body ) && ! empty( $body->message ) ) {
$query_params['jetpack-sso-api-error-message'] = $body->message;
$tracking_event_data['error_message'] = $body->message;
}

self::$tracking->record_user_event(
$event,
array(
'success' => 'false',
'error_message' => $error,
)
$tracking_event_data
);
return self::create_error_notice_and_redirect( $query_params );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/automattic-for-agencies-client/composer.lock

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
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/backup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"autoloader-suffix": "9559eef123208b7d1b9c15b978567267_backupⓥ2_6",
"autoloader-suffix": "9559eef123208b7d1b9c15b978567267_backupⓥ2_7_alpha",
"allow-plugins": {
"automattic/jetpack-autoloader": true,
"automattic/jetpack-composer-plugin": true
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/backup/composer.lock

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

2 changes: 1 addition & 1 deletion projects/plugins/backup/jetpack-backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Jetpack VaultPress Backup
* Plugin URI: https://jetpack.com/jetpack-backup
* Description: Easily restore or download a backup of your site from a specific moment in time.
* Version: 2.6
* Version: 2.7-alpha
* Author: Automattic - Jetpack Backup team
* Author URI: https://jetpack.com/
* License: GPLv2 or later
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/boost/composer.lock

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
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/inspect/composer.lock

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
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Update invite user error response logging
4 changes: 2 additions & 2 deletions projects/plugins/jetpack/composer.lock

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 @@ -103,12 +103,18 @@ public function revoke_user_invite( $user_id ) {
$event = 'sso_user_invite_revoked';

if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
$body = json_decode( wp_remote_retrieve_body( $response ) );
$tracking_event_data = array(
'success' => 'false',
'error_code' => 'invalid-revoke-api-error',
);

if ( ! empty( $body ) && ! empty( $body->message ) ) {
$tracking_event_data['error_message'] = $body->message;
}
self::$tracking->record_user_event(
$event,
array(
'success' => 'false',
'error_message' => 'invalid-revoke-api-error',
)
$tracking_event_data
);
return $response;
}
Expand Down Expand Up @@ -162,6 +168,10 @@ public function handle_invitation_results() {
return wp_admin_notice( __( 'User invite revoked successfully.', 'jetpack' ), array( 'type' => 'success' ) );
}

if ( $_GET['jetpack-sso-invite-user'] === 'failed' && isset( $_GET['jetpack-sso-api-error-message'] ) ) {
return wp_admin_notice( wp_kses( wp_unslash( $_GET['jetpack-sso-api-error-message'] ), array() ), array( 'type' => 'error' ) );
}

if ( $_GET['jetpack-sso-invite-user'] === 'failed' && isset( $_GET['jetpack-sso-invite-error'] ) ) {
switch ( $_GET['jetpack-sso-invite-error'] ) {
case 'invalid-user':
Expand Down Expand Up @@ -252,19 +262,27 @@ public function invite_user_to_wpcom() {
);

if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
$error = 'invalid-invite-api-error';
$error_code = 'invalid-invite-api-error';
$query_params = array(
'jetpack-sso-invite-user' => 'failed',
'jetpack-sso-invite-error' => $error,
'jetpack-sso-invite-error' => $error_code,
'_wpnonce' => $nonce,
);

$tracking_event_data = array(
'success' => 'false',
'error_code' => $error_code,
);

$body = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! empty( $body ) && ! empty( $body->message ) ) {
$query_params['jetpack-sso-api-error-message'] = $body->message;
$tracking_event_data['error_message'] = $body->message;
}

self::$tracking->record_user_event(
$event,
array(
'success' => 'false',
'error_message' => $error,
)
$tracking_event_data
);
return self::create_error_notice_and_redirect( $query_params );
}
Expand Down Expand Up @@ -397,12 +415,21 @@ public function handle_request_revoke_invite() {
'jetpack-sso-invite-error' => $error, // general error message
'_wpnonce' => $nonce,
);

$tracking_event_data = array(
'success' => 'false',
'error_code' => $error,
);

$body = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! empty( $body ) && ! empty( $body->message ) ) {
$query_params['jetpack-sso-api-error-message'] = $body->message;
$tracking_event_data['error_message'] = $body->message;
}

self::$tracking->record_user_event(
$event,
array(
'success' => 'false',
'error_message' => $error,
)
$tracking_event_data
);
return self::create_error_notice_and_redirect( $query_params );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/migration/composer.lock

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
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
]
},
"config": {
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_1_22"
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_1_23_alpha"
}
}
Loading

0 comments on commit 83fcea8

Please sign in to comment.