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

API Pull - Grant access to Google WPCOM app in onboarding flow #2337

Open
wants to merge 16 commits into
base: feature/google-api-project-phase-2
Choose a base branch
from

Conversation

ianlin
Copy link
Contributor

@ianlin ianlin commented Mar 27, 2024

Changes proposed in this Pull Request:

Project: pcTzPl-1SM-p2
Figma: JjJwsuOziVFv6eP1HNFhU8-fi-18069-355

Part of #2146 and similar to #2311. This PR adds the granting access to Google WPCOM app flow in the onboarding flow.

What has been changed:

  • Add a shared hook to handle REST API auth URL redirect, both settings page and onboarding can use this hook.
  • Add a new setup mc step grant_rest_api_access. Like the step accounts, its index is also 1 as we want the UI stays on the set up accounts page when the step grant_rest_api_access is still incomplete.
    • This step is only valid when notification service is enabled (by setting the filter woocommerce_gla_notifications_enabled to true)
  • Remove a prop hideNotificationService in the component ConnectedGoogleMCAccountCard as we would always show it on both settings and onboarding pages.
  • Add a prop hideDisableProductFetch in the component ConnectedGoogleMCAccountCard as we are not showing Disable product data fetch in the onboarding flow when the granting access is approved.
    • This is open for discussion, whether we'd want to show it in the onboarding flow.

Screenshots:

Detailed test instructions:

Approved

  1. Checkout this branch
  2. Set the filter woocommerce_gla_notifications_enabled to true
  3. Make sure the option gla_wpcom_rest_api_status is not set
  4. Delete all connected accounts, go to the onboarding flow by going to /wp-admin/admin.php?page=wc-admin&path=/google/setup-mc
  5. Connect Google account
  6. Connect MC account
  7. After MC account is connected, it will automatically be redirect to the WPCOM app granting access page
    • Screenshot 2024-03-26 at 21 36 09
  8. Finish the auth step, it will eventually be redirect to https://woo.com
    • Because currently we are using a test WPCOM app, in the future this will the Google's WPCOM app and they will help us to redirect back to the merchant site.
  9. Go back to setup mc page with an extra query parameter google_wpcom_app_status=approved. E.g.
    • /wp-admin/admin.php?page=wc-admin&path=/google/setup-mc&google_wpcom_app_status=approved
  10. The UI shows MC account connected and also Google has been granted access to fetch your product data.
    • Screenshot 2024-04-02 at 17 38 42
  11. The UI does not show Disable product data fetch like that in the settings page. API Pull - Grant access to google WPCOM app in settings page #2311
    • Screenshot 2024-04-02 at 17 08 42

Disapproved or Error

  1. Disconnect MC account by calling DELETE /wc/gla/mc/connection, and delete the option gla_wpcom_rest_api_status
  2. Go to setup mc page
  3. Reconnect MC account, and finish the granting access flow
  4. Go back to setup mc page with an extra query parameter google_wpcom_app_status=error or google_wpcom_app_status=disapproved. E.g.
    • /wp-admin/admin.php?page=wc-admin&path=/google/setup-mc&google_wpcom_app_status=disapproved
  5. The UI shows MC account connected but There was an issue granting access to Google for fetching your products.
    • Screenshot 2024-04-02 at 17 47 53
  6. Click Grant access will redirect to WPCOM app granting access page

Notifications Service is not Enabled

  1. Set the filter woocommerce_gla_notifications_enabled to false
  2. Delete all accounts and delete the option gla_wpcom_rest_api_status
  3. Connect MC account, it will not be redirected to WPCOM granting access page
  4. Set the option gla_wpcom_rest_api_status to approved, disapproved, or error
  5. The MC card will not display new product data fetch notice.

Additional details

Verifying who can set the REST API status by setting a query parameter google_wpcom_app_status will be implemented in another PR.

Changelog entry

@github-actions github-actions bot added changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement. labels Mar 27, 2024
Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (feature/google-api-project-phase-2@b51c815). Click here to learn what that means.

❗ Current head 43104de differs from pull request most recent head 07be97d. Consider uploading reports for the commit 07be97d to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@                         Coverage Diff                          @@
##             feature/google-api-project-phase-2   #2337   +/-   ##
====================================================================
  Coverage                                      ?   62.8%           
  Complexity                                    ?    4481           
====================================================================
  Files                                         ?     765           
  Lines                                         ?   22616           
  Branches                                      ?     543           
====================================================================
  Hits                                          ?   14195           
  Misses                                        ?    7964           
  Partials                                      ?     457           
Flag Coverage Δ
js-unit-tests 55.3% <ø> (?)
php-unit-tests 64.2% <100.0%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/MerchantCenter/MerchantCenterService.php 94.4% <100.0%> (ø)

…-app-in-setting-page' into add/grant-access-to-google-wpcom-app-in-onboarding-flow
If no `step` query param provided, use the step from MC setup.
Note that this step shares the same key with the step `accounts` defined in
`js/src/setup-mc/setup-stepper/stepNameKeyMap.js`, so when this step hasn't
finished, the UI will stay on the setup accounts page.
Base automatically changed from add/grant-access-to-google-wpcom-app-in-setting-page to feature/google-api-project April 2, 2024 08:47
Because we wouldn't want the merchant to disable it during onboarding.

Also remove hideNotificationService since we will always show it in both
onboarding and settings page.
@ianlin ianlin requested a review from a team April 3, 2024 12:35
@ianlin ianlin self-assigned this Apr 3, 2024
@ianlin ianlin marked this pull request as ready for review April 3, 2024 12:35
@puntope
Copy link
Contributor

puntope commented Apr 3, 2024

Just a note here: If this is for next version I guess we should create a separate branch than feature/google-api-project as this one is for the MVP.

@puntope
Copy link
Contributor

puntope commented Apr 4, 2024

❓ Doesn't matter if the grant access gets an error or is approved. You can always continue the setup. I assume this is the expected behaviour

@puntope
Copy link
Contributor

puntope commented Apr 4, 2024

Wonder if we might add some events/tracks regarding the final setup. (ie. If the auth is granted)

@puntope
Copy link
Contributor

puntope commented Apr 4, 2024

What about adding some tests for the UI as well?

@@ -40,12 +40,12 @@ import { getSettingsUrl } from '.~/utils/urls';
* @param {Object} props React props.
* @param {{ id: number }} props.googleMCAccount A data payload object containing the user's Google Merchant Center account ID.
* @param {boolean} [props.hideAccountSwitch=false] Indicate whether hide the account switch block at the card footer.
* @param {boolean} [props.hideNotificationService=true] Indicate whether hide the enable Notification service block at the card footer.
* @param {boolean} [props.hideDisableProductFetch=true] Indicate whether hide the disable product fetch block at the card footer.
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this should be [props.hideDisableProductFetch=false]

import useApiFetchCallback from '.~/hooks/useApiFetchCallback';
import useDispatchCoreNotices from '.~/hooks/useDispatchCoreNotices';

const useRestAPIAuthURLRedirect = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add some JSDOCS for this Hook?


if ( $this->is_mc_contact_information_setup() && $this->checked_pre_launch_checklist() ) {
$step = 'paid_ads';
if ( ! $notifications_enabled || $this->is_rest_api_granted() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of $this->is_rest_api_granted() we might use NotificationsService::is_ready() that does the same so we can avoid adding more code doing the same.

@ianlin ianlin changed the base branch from feature/google-api-project to feature/google-api-project-phase-2 April 8, 2024 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants