google / site-kit-wp Public
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
Comments
|
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. |
|
@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? |
|
That's a good idea. We already provide I'll update the IB |
|
IB updated. Keeping as an |
|
IB sounds great! |
|
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. |



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:
We also show a warning component on the Site Kit Dashboard:
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:
In fact, scopes are insufficient, which is clear from the API response:
Expected behavior
Additional Testing
Screenshots
See above.
Additional Context
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
assets/js/components/notifications/index.jschangeDashboardAuthAlertto be filtered intogooglesitekit.ErrorNotificationinstead ofgooglesitekit.DashboardNotifications(seesetup.needReauthenticate)This hook is available everywhere the
<Header>is rendered (all Site Kit React-based screens) rather than only places where<DashboardNotifications>is renderedDashboardAuthAlertis only rendered onceDashboardAuthAlertcomponent is conditionally filtered in when an error is caught indata.get()Currently this is only done in
data.combinedGetbut the object structure is not consistent with those of errors fromdata.getcalls (see below). This should be checking forresult.data.statusandresult.data.reasoninstead ofresult.error_data[ status ].reasongetandcombinedGetto use a common method for error handlinggoogle-site-kit/v1/data/endpoint to returnWP_Errorsin consistent structure with individual requestsBy default this is done by
\WP_REST_Server::error_to_responsebut only if the response itself is aWP_Error. In our case, the response is an array with one or moreWP_Errorobjects, which causes them to be encoded/returned as-is rather than their error response representations. Becauseerror_to_responseis a protected method of the REST server, we'll need to reimplement this.* AddDashboardNotificationstoSetupWrapperand module dashboard componentsnot 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)
result.xdebug_messagecode incombinedGethandlerQA Brief
To reproduce the insufficient scopes state
this activates the module
Changelog entry
The text was updated successfully, but these errors were encountered: