Sponsored Content
The Wayback Machine - https://web.archive.org/web/20220409015324/https://github.com/google/site-kit-wp/issues/729
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

Ensure 'insufficient scopes' warning shows correctly #729

Closed
adamsilverstein opened this issue Oct 28, 2019 · 7 comments
Closed

Ensure 'insufficient scopes' warning shows correctly #729

adamsilverstein opened this issue Oct 28, 2019 · 7 comments
Labels
P1 Type: Bug
Milestone

Comments

@adamsilverstein
Copy link
Collaborator

@adamsilverstein adamsilverstein commented Oct 28, 2019 •

Bug Description

This issue was noted during QA on #633.

Insufficient scopes warnings should show in more places.

Steps to reproduce

Current Behavior

When the user does not have sufficient scopes to use an enabled module, Site Kit shows a warning that the user needs to reauthenticate to add the missing scopes. We show this warning across wp-admin as a WordPress admin notice:

image

We also show a warning component on the Site Kit Dashboard:

image

However, currently on the module pages themselves we don't show any error. For example, the analytics setup page - the page itself incorrectly indicates that the user does not have an analytics account:

image

In fact, scopes are insufficient, which is clear from the API response:

image

Expected behavior

  • The insufficient scopes warning should show on module page headers and during module setup when scopes are missing.
  • The analytics module setup component should detect the insufficient scopes error and show a less misleading/more helpful error message.

Additional Testing

  • The AdSense module page and setup should also be tested, also show the warning on the search console module page and the settings page.
  • Test single post admin bar dropdown - should this contain a scope warning?

Screenshots

See above.

Additional Context

  • PHP Version: 7.3
  • OS: [e.g. iOS] OSX
  • Browser [e.g. chrome, safari] Chrome Dev
  • Plugin Version [e.g. 22] develop branch
  • Device: [e.g. iPhone6] Macbook Pro

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The insufficient scopes warning currently displayed in the dashboard under these circumstances should also be able to appear on
    • single module pages (Search Console, Analytics, AdSense)
    • each module's setup flow
  • As it already does, the notice should appear if a relevant scope is missing from what the user has already granted access to.

Implementation Brief

  • In assets/js/components/notifications/index.js change DashboardAuthAlert to be filtered into googlesitekit.ErrorNotification instead of googlesitekit.DashboardNotifications (see setup.needReauthenticate)
    This hook is available everywhere the <Header> is rendered (all Site Kit React-based screens) rather than only places where <DashboardNotifications> is rendered
  • Ensure DashboardAuthAlert is only rendered once
  • Ensure the DashboardAuthAlert component is conditionally filtered in when an error is caught in data.get()
    Currently this is only done in data.combinedGet but the object structure is not consistent with those of errors from data.get calls (see below). This should be checking for result.data.status and result.data.reason instead of result.error_data[ status ].reason
    • Update data get and combinedGet to use a common method for error handling
    • Update google-site-kit/v1/data/ endpoint to return WP_Errors in consistent structure with individual requests
      By default this is done by \WP_REST_Server::error_to_response but only if the response itself is a WP_Error. In our case, the response is an array with one or more WP_Error objects, which causes them to be encoded/returned as-is rather than their error response representations. Because error_to_response is a protected method of the REST server, we'll need to reimplement this.
      * Add DashboardNotifications to SetupWrapper and module dashboard components
      not sure if this is the correct component for this although it does display the scopes warning when necessary - needs testing to make sure other notifications don't show up where not relevant (i.e. publisher wins)
  • Remove old unused result.xdebug_message code in combinedGet handler

QA Brief

To reproduce the insufficient scopes state

  1. Reset Site Kit and perform initial setup.
  2. Click connect Analytics module but do not approve scopes on subsequent oauth screen
    this activates the module
  3. Click back or navigate back to wp-admin directly
  4. Copy Analytics settings from another install using wp-cli
    # in other install with Analytics setup:
    wp option get googlesitekit_analytics_settings --format=json
    # in current install for testing:
    wp option set googlesitekit_analytics_settings --format=json 'output from last command'

    Note the single quotes around the json in the second command are important

  5. Navigate to Analytics module page (should be in the menu on left now - may need to refresh to appear)
  6. See notification about problem accessing data

Changelog entry

  • Display warnings about insufficient scopes across all Site Kit screens instead of only the dashboard, since they are just as relevant during setup.
@adamsilverstein adamsilverstein added the Type: Bug label Oct 28, 2019
@felixarntz felixarntz added the P1 label Oct 28, 2019
@felixarntz felixarntz assigned felixarntz and unassigned felixarntz Oct 28, 2019
@aaemnnosttv aaemnnosttv self-assigned this Nov 11, 2019
@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Nov 22, 2019

Marking this as M for now as this has taken a good deal of digging to figure out. Could potentially be an L if more is discovered during implementation.

I'm attaching a WIP PR here as a proof of concept and starting point for implementation.

@felixarntz
Copy link
Member

@felixarntz felixarntz commented Nov 26, 2019 •

@aaemnnosttv IB looks good. In addition to those request failures however, we might as well want to consider the PHP part, which actually gives us information about insufficient scopes without a request being made. Whenever the current user's scopes don't match the currently required ones, we already know that in PHP, so could output such a notice in our Site Kit screens even on initial load (we already have a regular WP admin notice for that, outside of our screens). What do you think?

@felixarntz felixarntz assigned aaemnnosttv and unassigned felixarntz Nov 26, 2019
@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Dec 10, 2019

That's a good idea. We already provide requiredScopes and grantedScopes in googlesitekit.setup. We can additionally check these to conditionally display the insufficient scopes notice. It should only display once though regardless of where it comes from.

I'll update the IB 👍

@aaemnnosttv
Copy link
Collaborator

@aaemnnosttv aaemnnosttv commented Dec 10, 2019

IB updated. Keeping as an M to account for all the definition and discovery, although I think it's probably closer to an S from here.

@felixarntz
Copy link
Member

@felixarntz felixarntz commented Dec 12, 2019

IB sounds great! ✅

@felixarntz felixarntz removed their assignment Dec 12, 2019
@aaemnnosttv aaemnnosttv self-assigned this Dec 17, 2019
@eclarke1 eclarke1 added this to the 1.1.5 milestone Dec 18, 2019
@felixarntz felixarntz assigned aaemnnosttv and unassigned felixarntz Dec 30, 2019
@aaemnnosttv aaemnnosttv assigned felixarntz and unassigned aaemnnosttv Jan 2, 2020
@tofumatt
Copy link
Collaborator

@tofumatt tofumatt commented Jan 8, 2020

I see this error when following the QA steps:

Screenshot 2020-01-08 17 55 06

Assuming that's the intended outcome (it seems like it) then QA ✅

Let me know if that's not the right screen 😅

@tofumatt tofumatt removed their assignment Jan 8, 2020
@marrrmarrr
Copy link
Collaborator

@marrrmarrr marrrmarrr commented Jan 15, 2020

The notification is triggered as expected, but the message on the dashboard below ("Analytics gathering data") is misleading -- no data are being gathered, since the user doesn't have scope permissions.
Will open a separate issue for this.

@marrrmarrr marrrmarrr closed this Jan 15, 2020
@ThierryA ThierryA removed this from the 1.2.0 milestone Feb 3, 2020
@ThierryA ThierryA added this to the Sprint 14 milestone Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Type: Bug
Projects
None yet
Development

No branches or pull requests

8 participants