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

Handle expired or missing tokens for orders autosuggest #3308

Merged
merged 12 commits into from
Feb 15, 2023

Conversation

JakePT
Copy link
Contributor

@JakePT JakePT commented Feb 9, 2023

Description of the Change

Adds handling for missing or expired tokens. Now if an search fails a new token will be fetched and the search will be reattempted. This will handle situations where a token has expired. Refreshing a token will only be attempted once.

Additionally I've included a few fixes for the suggestion dropdown:

  • Fixed an issue where the date and time of orders could be incorrect.
  • Added support for opening suggestions in a new tab by holding Control/Command when selecting a suggestion.
  • Close the suggestions dropdown immediately when the input is empty, instead of debouncing.

Closes #3296

How to test the Change

From #3175:

  1. Connect to an EP.io environment that supports the order search API.
  2. Activate the WooCommerce and Protected Content features.
  3. Add ( new Orders() )->setup(); to the setup() method of the WooCommerce feature class.
  4. Perform an index.
  5. Visit WooCommerce > Orders and start searching for orders. Suggestions should be offered in a listbox below the search form.

New:

  • Watching the network tab, visit WooCommerce > Orders. A request to wp-json/elasticpress/v1/token should be sent and should return a token.
  • Start searching for orders. Suggestions should be offered in a listbox below the search form.
  • In the database, in wp_usermeta, find ep_token for your user and manipulate it so that it's invalid.
  • Watching the network tab, visit WooCommerce > Orders. A request to wp-json/elasticpress/v1/token should be sent and should return the manipulated token.
  • Watching the network tab, start searching for orders. The first request to the ElasticPress.io API should fail. Another request to wp-json/elasticpress/v1/token should be sent and should return a new token. Another API request to ElasticPress.io should follow and should succeed. Suggestions should now be offered in a listbox below the search form.

Changelog Entry

See #3175

Credits

Props @JakePT

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Copy link
Member

@felipeelia felipeelia left a comment

Choose a reason for hiding this comment

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

@JakePT during my tests on this one, at some point I didn't have a search template saved, and when I typed anything the request failed but then JS went in an infinite loop of requesting a token and trying again. Did you see that before?

Also, would it be possible to disable the browser's autosuggest? Chrome keeps adding its suggestions in front of the autosuggest list.

I've also pushed a few minor changes if you want to give it a look (including fixing some conflicts we got with develop after the Request ID inclusion.)

@JakePT
Copy link
Contributor Author

JakePT commented Feb 15, 2023

@felipeelia I have:

  • Fixed the issue where refreshing tokens would get stuck in a loop.
  • Disabled browser autocomplete on the order search input when the plugin's autosuggest is active.
  • Brought the branch up to date with develop.
  • Checked your conflict resolutions. LGTM.

@felipeelia felipeelia added this to the 4.5.0 milestone Feb 15, 2023
@felipeelia felipeelia merged commit b97d1c8 into develop Feb 15, 2023
@felipeelia felipeelia deleted the feature/3296 branch February 15, 2023 12:52
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.

Handle expired or missing tokens for orders autosuggest
2 participants