Skip to content

Commit

Permalink
Social | Restore must_reauth as connection status (#40946)
Browse files Browse the repository at this point in the history
* Add "must_reauth" to status in REST schema

* Restore the UI changes to consider must_reauth status

* Add changelog

* Don't disable connections with must_reauth status

must_reauth means that the connection will break soon, but it still
works. We'll display an appropriate notice.

---------

Co-authored-by: Paul Bunkham <[email protected]>
  • Loading branch information
manzoorwanijk and pablinos authored Jan 10, 2025
1 parent 6b80d99 commit b1f7eb4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Restored UI changes to support must_reauth status
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PublicizeConnection extends Component {
}

isDisabled() {
return this.props.disabled || this.connectionIsFailing() || this.connectionNeedsReauth();
return this.props.disabled || this.connectionIsFailing();
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ export function getFailedConnections( state ) {

/**
* Returns a list of Publicize connection service names that require reauthentication from users.
* iFor example, when LinkedIn switched its API from v1 to v2.
* For example, when LinkedIn switched its API from v1 to v2.
*
* @param {import("../types").SocialStoreState} state - State object.
* @return {Array<import("../types").Connection>} List of service names that need reauthentication.
*/
export function getMustReauthConnections( state ) {
const connections = getConnections( state );
return connections
.filter( connection => 'broken' === connection.status )
.filter( connection => 'must_reauth' === connection.status )
.map( connection => connection.service_name );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const state = {
external_handle: '@[email protected]',
enabled: false,
connection_id: '219876543',
status: 'ok',
status: 'must_reauth',
},
],
},
Expand Down Expand Up @@ -90,7 +90,7 @@ describe( 'Social store selectors: connectionData', () => {
it( 'should return must reauth connections', () => {
const mustReauthConnections = getMustReauthConnections( state );
expect( mustReauthConnections ).toEqual( [
state.connectionData.connections[ 1 ].service_name,
state.connectionData.connections[ 2 ].service_name,
] );
} );
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ConnectionStatus = 'ok' | 'broken';
export type ConnectionStatus = 'ok' | 'broken' | 'must_reauth';

export type Connection = {
connection_id: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Added must_reauth as status in connection REST schema
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public static function get_the_item_schema() {
'enum' => array(
'ok',
'broken',
'must_reauth',
),
),
'user_id' => array(
Expand Down Expand Up @@ -326,8 +327,11 @@ protected static function get_connections_test_status() {
$test_results_map = array();

foreach ( $test_results as $test_result ) {
// Compare to `true` because the API returns a 'must_reauth' for LinkedIn.
$test_results_map[ $test_result['connectionID'] ] = true === $test_result['connectionTestPassed'] ? 'ok' : 'broken';
$result = $test_result['connectionTestPassed'];
if ( 'must_reauth' !== $result ) {
$result = $test_result['connectionTestPassed'] ? 'ok' : 'broken';
}
$test_results_map[ $test_result['connectionID'] ] = $result;
}

return $test_results_map;
Expand Down

0 comments on commit b1f7eb4

Please sign in to comment.