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

Move the guest should verify email logic to the order class #43834

Merged

Conversation

hsingyuc
Copy link
Contributor

@hsingyuc hsingyuc commented Jan 19, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR move the guest should verify email logic to the order class so we can reuse email is valid check.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Create a guest pay-for-order order with (ex. WC Pre-Orders)
  2. Find the order and update the status to pending payment
  3. Open the Customer payment page → in incognito
  4. See the pay-for-order order without email verification because we are in the grace period
  5. Comment out the grace period or wait till the time pass
  6. Go to the pay-for-order page again
  7. See the verify email address page.

Screenshot

Screenshot 2024-01-21 at 3 40 00 PM

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Move the guest should verify email logic to the user utils

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jan 19, 2024
Copy link
Contributor

github-actions bot commented Jan 19, 2024

Test Results Summary

Commit SHA: 1fce2d1

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests30500403097m 29s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@hsingyuc hsingyuc marked this pull request as ready for review January 21, 2024 21:16
Copy link
Contributor

github-actions bot commented Jan 21, 2024

Hi @barryhughes,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@leonardola leonardola self-assigned this Jan 24, 2024
Copy link
Contributor

@leonardola leonardola left a comment

Choose a reason for hiding this comment

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

Generally the changes look good. Tests went well. But I left a comment about making the code more readable.

Also the wc-order class is already huge so I'm a little unease about moving more code into it.

We'll need to check with a team that is more familiar with WooCommerce core code to also review this PR before it gets merged.

*/
return (bool) apply_filters( 'woocommerce_order_email_verification_required', $email_verification_required, $order, $context );
// If we cannot match the order with the current user, ask that they verify their email address.
$supplied_email = sanitize_email( wp_unslash( filter_input( INPUT_POST, 'email' ) ) ) === $order->get_billing_email()
Copy link
Contributor

Choose a reason for hiding this comment

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

This one liner is quite hard to understand at first. Let's take the opportunity and refactor it into a more readable code. Maybe change to something like this:

// If we cannot match the order with the current user, ask that they verify their email address.
$supplied_email_matches_order_email = sanitize_email( wp_unslash( filter_input( INPUT_POST, 'email' ) ) ) === $order->get_billing_email();
$nonce_is_valid                     = wp_verify_nonce( filter_input( INPUT_POST, 'check_submission' ), 'wc_verify_email' );
$supplied_email                     = null;

if ( $supplied_email_matches_order_email &&  $nonce_is_valid ) {
	$supplied_email = sanitize_email( wp_unslash( filter_input( INPUT_POST, 'email' ) ) );
}

Also it ends up checking if the email matches with the order again in the new function. Do we really need to also check it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one liner is quite hard to understand at first. Let's take the opportunity and refactor it into a more readable code.

Good idea, thank you!

Also it ends up checking if the email matches with the order again in the new function. Do we really need to also check it here?

Thank you for catching that! Both issues are fixed here cf90234.

@hsingyuc hsingyuc force-pushed the update/move-guest-should-verify-email-logic-to-order-class branch from 4adee49 to d81488a Compare January 26, 2024 00:05
Copy link
Contributor

@leonardola leonardola left a comment

Choose a reason for hiding this comment

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

Changes look good now. Thanks for the fixes.

@hsingyuc
Copy link
Contributor Author

Hi @jonathansadowski, can you help us review this PR, we'll need it before Jan 31st for testing. Thank you!

Copy link
Contributor

@jonathansadowski jonathansadowski left a comment

Choose a reason for hiding this comment

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

Hi @jonathansadowski, can you help us review this PR, we'll need it before Jan 31st for testing. Thank you!

Hey @hsingyuc I cycled the tests on this by closing and reopening the PR, as after the changelog was added by our automation, the checks weren't automatically triggered (a fix for this is in the works). I noticed that there was a lint issue that should be addressed before this was run.

We'll need to check with a team that is more familiar with WooCommerce core code to also review this PR before it gets merged.

I'm going to add @woocommerce/proton as a reviewer to this PR for that. @woocommerce/vortex is primarily involved with the tooling surrounding the monorepo.

@jonathansadowski jonathansadowski requested review from a team and jorgeatorres and removed request for a team January 29, 2024 18:17
@barryhughes
Copy link
Member

Also the wc-order class is already huge so I'm a little unease about moving more code into it.

Fwiw, I agree with this. Less because of the size of the existing WC_Order class (though, yep, it's definitely grown pretty big), but because its core job is to model orders, rather than to govern access to a frontend view.

Could this logic live inside OrderAuthorizationTrait? Even though that is in the Blocks namespace, I'm sure the shortcode class could still reference it (or, if that is not palatable, a new trait or utility class could be created).

@hsingyuc hsingyuc force-pushed the update/move-guest-should-verify-email-logic-to-order-class branch from 583005f to eea1892 Compare January 30, 2024 00:05
@hsingyuc
Copy link
Contributor Author

hsingyuc commented Jan 30, 2024

I noticed that there was a lint issue that should be addressed before this was run.

Thank you, @jonathansadowski ! Fixed in eea1892.

@barryhughes This is more of a permission check, it's only checking if the email is valid. I put it inside class-wc-order because we put key_is_valid there, and they seem like they should be together. I don't think we want to put it inside OrderAuthorizationTrait because that's for endpoints and might be weird for the shortcode to use. I found /Utilities/OrderUtil.php but it doesn't seem to fit well with the other methods in there. Any suggestions?

@jorgeatorres jorgeatorres requested review from barryhughes and removed request for jorgeatorres January 30, 2024 14:23
@barryhughes
Copy link
Member

barryhughes commented Jan 30, 2024

Hi @hsingyuc,

I found /Utilities/OrderUtil.php but it doesn't seem to fit well with the other methods in there.

True. Although, it's described as a spot for any order-related helpers—so it wouldn't be the worst fit (but I take your point). If that's uncomfortable, how about either of:

  • Automattic\WooCommerce\Internal\Utilities\Users (and renaming the method to should_user_verify_order_email).
  • Or, placing it in a new type Automattic\WooCommerce\Internal\Utilities\Checkout.

Both have the advantage we are not adding frontend validation logic to a data model, and both are in the internal namespace which can be used from both block and traditional shortcode logic, but gives us the freedom to refactor further in the future.

@hsingyuc hsingyuc force-pushed the update/move-guest-should-verify-email-logic-to-order-class branch from 185b11e to bc14f07 Compare January 31, 2024 03:56
@hsingyuc
Copy link
Contributor Author

Thank you, @barryhughes! Fixed in bc14f07 and moved the function to user utils.

@barryhughes barryhughes reopened this Jan 31, 2024
@barryhughes
Copy link
Member

Hi @hsingyuc, I wanted to take a bit of time to test some scenarios, because the rollout of the original change (adding protections to the order confirmation page) resulted in some friction.

One thing I'm noticing (with the 'classic'/shortcode-based flow) is that, after a guest checks out, they are immediately asked to verify their email address. This shouldn't be the case, they should see the confirmation page.

@hsingyuc
Copy link
Contributor Author

hsingyuc commented Feb 1, 2024

I wanted to take a bit of time to test some scenarios, because the rollout of the original change (adding protections to the order confirmation page) resulted in some friction.

Sure. I'm just trying to make the store API meet the Core expectations and expose the function so we can use it. Let me know how I can help.

@barryhughes
Copy link
Member

Definitely. We'd need to start by addressing the issue I just mentioned, we can't merge as-is, or we'd disrupt a large number of sites.

@hsingyuc hsingyuc force-pushed the update/move-guest-should-verify-email-logic-to-order-class branch from 56024da to 4ee6572 Compare February 2, 2024 02:07
@hsingyuc
Copy link
Contributor Author

hsingyuc commented Feb 2, 2024

One thing I'm noticing (with the 'classic'/shortcode-based flow) is that, after a guest checks out, they are immediately asked to verify their email address. This shouldn't be the case, they should see the confirmation page.

Thank you for pointing that out! Fixed in 4ee6572

@barryhughes
Copy link
Member

Thanks! Closing and re-opening to re-start CI checks (...again 🙃).

@barryhughes barryhughes closed this Feb 2, 2024
@barryhughes barryhughes reopened this Feb 2, 2024
@hsingyuc hsingyuc dismissed jonathansadowski’s stale review February 2, 2024 22:56

Changes are made and tests are passing.

@hsingyuc
Copy link
Contributor Author

hsingyuc commented Feb 2, 2024

@barryhughes Thank you for the review! I'm not authorized to merge the PR, could you merge it for me? Thanks!

@barryhughes barryhughes merged commit 24ea7a1 into trunk Feb 3, 2024
42 checks passed
@barryhughes barryhughes deleted the update/move-guest-should-verify-email-logic-to-order-class branch February 3, 2024 02:03
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 3, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 3, 2024
@nigeljamesstevenson nigeljamesstevenson added needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Feb 5, 2024
samueljseay pushed a commit that referenced this pull request Feb 6, 2024
* Move the guest should verify email logic to the order class

* Refactor for readability and remove redundant code

* Use billing email variable

* Remove white space

* Rename and move email_is_valid to users utils

* Use global WC_DateTime and WC_Session classes

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
@rodelgc rodelgc modified the milestones: 8.7.0, 8.6.0 Feb 6, 2024
github-actions bot pushed a commit that referenced this pull request Feb 6, 2024
* Move the guest should verify email logic to the order class

* Refactor for readability and remove redundant code

* Use billing email variable

* Remove white space

* Rename and move email_is_valid to users utils

* Use global WC_DateTime and WC_Session classes

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
rodelgc pushed a commit that referenced this pull request Feb 6, 2024
* Move the guest should verify email logic to the order class (#43834)

* Move the guest should verify email logic to the order class

* Refactor for readability and remove redundant code

* Use billing email variable

* Remove white space

* Rename and move email_is_valid to users utils

* Use global WC_DateTime and WC_Session classes

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>

* Prep for cherry pick 43834

---------

Co-authored-by: Hsing-yu Flowers <hsingyuc.7@gmail.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: WooCommerce Bot <no-reply@woo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants