-
Notifications
You must be signed in to change notification settings - Fork 121
REST API: Check for Woo after authentication #8525
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
Conversation
You can test the changes from this Pull Request by:
|
|
|
||
| func checkWooInstallation(in navigationController: UINavigationController, | ||
| onSuccess: @escaping () -> Void) { | ||
| let action = SitePluginAction.getPluginDetails(siteID: WooConstants.placeholderStoreID, pluginName: Constants.wooPluginName) { result in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@itsmeichigo I was just taking a look to compare how the implementation differs between the two platforms, and if I'm understanding things correctly, you are using the endpoint /wp/v2/plugins to check if Woo is installed here, I don't think this can work for all cases, users with the role "shop manager" can't use this endpoint.
As detailed in the internal doc pe5sF9-U3-p2, there are two ways to check if Woo is installed for all the users. Currently, in Android we are re-using the same check as Jetpack CP sites (meaning /wc/v3/settings), but if we decide to remove XMLRPC, we might try to move to use the root endpoint /wp-json/ in order to reduce the number of requests we send.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into my code @hichamboushaba! Could you clarify how we can use the root endpoint to check for Woo please? And how does it have anything to do with XMLRPC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify how we can use the root endpoint to check for Woo please?
This would be the same as we do for checking the Woo API version (here), the root endpoint returns an array of the available namespaces of APIs in the site, and if it contains /wc/{something}, we can infer that the site has WooCommerce.
And how does it have anything to do with XMLRPC?
Sorry for not being clear about this, this is specific to Android, currently the site data is being fetched using XMLRPC, so as long as we don't touch this, it made sense to me to reuse the same WooCommerce check that we use for Jetpack CP sites. But if we decide to remove XMLRPC, we will use the root endpoint to fetch site data, so in order to save one request, I would use this same request to infer if Woo is installed or not too, and stop using /wc/v3/settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed explanation Hicham! I'll use the root endpoint to check too, for simplicity 🙇
selanthiraiyan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚢
I left a couple of non-blocking nits.
| self?.checkRoleEligibility(in: navigationController) { | ||
| self?.checkWooInstallation(for: siteURL, in: navigationController, onSuccess: onSuccess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Can we send these requests in parallel? Do we have to wait for the role eligibility response before checking Woo installation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to avoid presenting a few alerts at the same time in case there is more than one issue with the checks. If we want to call everything concurrently, we'll need another mechanism to check the results and prioritize the alerts we want to display. For simplicity, I'm using nested closures for now, I hope it's alright.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. 👍
|
|
||
| /// MOCK: application password use case | ||
| /// | ||
| private final class MockApplicationPasswordUseCase: ApplicationPasswordUseCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could we move this to a separate file and use it here and in RequestAuthenticatorTests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should import NetworkingTests from WooCommerceTests? Or should we move this code to Networking` instead? @selanthiraiyan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed that these files reside in separate frameworks. Let us keep them separate. 😅
Part of #8453
Description
This PR adds a check for Woo after authenticating the user with site credentials only. Following Hicham's suggestion in a comment below, the check is handled by calling the logged in site's root endpoint and checking for any namespaces starting with
wc/.For simplicity, we are only showing an alert when Woo is not installed for now. To improve the UX, we'll need to handle Woo installation in the future.
Also, for readability and testability, all the checks for #8453 are now moved to a separate class named
PostSiteCredentialLoginChecker. This along with the unit tests cause the PR to be slightly larger, sorry if this causes any inconvenience for reviewing.I've also replaced the used of the
FancyAlertControllerwithUIAlertControllerfor a more intuitive look.Tracks events will be added in a subsequent PR.
Testing instructions
1. Without active WooCommerce:
Prerequisite: Make sure that application password is enabled in your test site. Deactivate or uninstall WooCommerce from the site.
applicationPasswordAuthenticationForSiteCredentialLoginand build the app.2. With issue fetching site information:
Prerequisite: Make sure that application password is enabled on your site.
applicationPasswordAuthenticationForSiteCredentialLoginand build the app.Please feel free to test again with a site that has WooCommerce activated. You should be able to get to the home screen after logging in.
Screenshots
RELEASE-NOTES.txtif necessary.