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

feat/603: remove Auth0 related features #310

Merged
merged 6 commits into from
Jul 26, 2022
Merged

feat/603: remove Auth0 related features #310

merged 6 commits into from
Jul 26, 2022

Conversation

Sidsector9
Copy link
Contributor

@Sidsector9 Sidsector9 commented Jul 19, 2022

Description of the Change

  • Removed the Auth0 class and related code.
  • Removed the client ID and secret fields.
  • Added Host and Tenant ID fields.
  • Added a cleanup function to delete client ID, client secret and auth token transient.

Closes #306

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Added - New Curator API.
Removed - Dependency on Auth0 and replaced with the new Curator API.

Credits

Props @Sidsector9

@Sidsector9 Sidsector9 requested a review from oscarssanchez July 19, 2022 10:12
@jeffpaul jeffpaul added this to the 1.2.0 milestone Jul 19, 2022
delete_option( 'sophi_site_automation_access_token' );
}

if ( ! empty( $settings['client_id'] && ! empty( $settings['client_secret'] ) ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may still want some validation that Host/Tenant ID are entered when someone tries to save the form.

@jeffpaul jeffpaul requested review from dkotter and dinhtungdu and removed request for oscarssanchez July 20, 2022 21:02
dkotter
dkotter previously approved these changes Jul 21, 2022
sophi.php Outdated
Comment on lines 101 to 137
function sophi_remove_stale_data( $plugin ) {
/** Return if the plugin is not Sophi. */
if ( 'sophi.php' !== basename( $plugin ) ) {
return;
}

$version_key = 'sophi_version';
$current_version = get_transient( $version_key );

if ( false === $current_version ) {
$current_version = get_option( $version_key, false );

if ( false !== $current_version ) {
set_transient( $version_key, $current_version );
}
}

if ( SOPHI_WP_VERSION === $current_version ) {
return;
}

if ( false === $current_version || version_compare( $current_version, SOPHI_WP_VERSION, '<' ) ) {

/** Cleanup logic before setting the new version of the plugin. */
delete_option( 'sophi_site_automation_access_token' );

$sophi_settings = get_option( 'sophi_settings' );
unset( $sophi_settings['client_id'] );
unset( $sophi_settings['client_secret'] );

update_option( 'sophi_settings', $sophi_settings );
update_option( $version_key, SOPHI_WP_VERSION, true );
set_transient( $version_key, SOPHI_WP_VERSION );
}
}

add_action( 'plugin_loaded', 'sophi_remove_stale_data' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried about the new option in terms of site performance. Is there another way to clean the data without adding a new option?

I think we can remove irrelevant options when updating the Sophi setting. Do you think it's sufficient to clean the old settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dinhtungdu I've replaced this logic, can you check?

@Sidsector9 Sidsector9 force-pushed the feat/306 branch 2 times, most recently from 223b11b to 78e8488 Compare July 25, 2022 18:09
@Sidsector9 Sidsector9 requested a review from dinhtungdu July 25, 2022 19:21
Copy link
Contributor

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sidsector9 thanks for the update! I just have one more minor comment, otherwise, this is LGTM!

sophi.php Outdated
Comment on lines 97 to 122
/**
* Method to cleanup settings before setting the new version.
*
* @param mixed $value The new, unserialized option value.
*
* @return mixed
*/
function sophi_remove_stale_data( $value ) {
$is_client_id_set = isset( $value['client_id'] );
$is_client_secret_set = isset( $value['client_secret'] );

if ( ! $is_client_id_set && ! $is_client_secret_set ) {
return $value;
}

if ( $is_client_id_set ) {
unset( $value['client_id'] );
}

if ( isset( $is_client_secret_set ) ) {
unset( $value['client_secret'] );
}

return $value;
}
add_filter( 'pre_update_option_sophi_settings', 'sophi_remove_stale_data' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic can be added to the sanitize_settings function in includes/functions/settings.php instead.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Sidsector9 Sidsector9 requested a review from dinhtungdu July 26, 2022 04:47
@dinhtungdu
Copy link
Contributor

@Sidsector9 Thanks so much for being patient with me! This is LGTM now!

@jeffpaul jeffpaul merged commit d1dcea2 into develop Jul 26, 2022
@jeffpaul jeffpaul deleted the feat/306 branch July 26, 2022 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SIT-3368: Use the new curator API in the plugin, which does not use Auth0 authentication
4 participants