-
Notifications
You must be signed in to change notification settings - Fork 293
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
Requests for settings fail for view-only users on dashboard #5310
Comments
@aaemnnosttv Did you have any idea on how this could be achieved? I wasn't quite sure how this could be possible. Would be ideal though! 🙂 |
@jimmymadon and I chatted about this and while ideally this could be done without changes to each selector call, I don't think it's possible. At best you'd need to use a modified The straightforward and probably best way is the approach suggested in the IB. IB looks good, but are there places where we can add tests for this behaviour? Any of these components that have testing infrastructure in place would be easy candidates to add a test for this—can we add some tests to this IB before moving it forward? |
I was thinking maybe we could create an alternate This would still require changes in each use but we could avoid adding conditions inline to each selector we have now. How does that sound @tofumatt ? |
@aaemnnosttv That sounds more roundabout to me… we'd need to pass some sort of function to control whether or not a selector is used in that component… and also logic on how to assemble it because the link URLs rely on report data arguments. For instance, in site-kit-wp/assets/js/modules/adsense/components/dashboard/DashboardTopEarningPagesWidget.js Lines 107 to 110 in 7fe9ecf
It seems silly to do that and have to pass through a function to control the condition of the select when we can very easily add it inline to each selector—it'd be as simple as: if ( viewOnlyDashboard ) {
return null;
} for any select. If anything, I'd be okay with a new hook that ran a |
For me, this IB looks good, but assigning it to @aaemnnosttv to get his thoughts on the approach suggested and alternative approaches here. |
Just to clarify here: conditions need to happen inside selector calls at some point, because the whole issue here is that selectors are triggering resolvers they shouldn't. We can't conditionally call hooks, so we need to place the conditional inside the function that calls these selectors at some point. I think it's most straightforward to place them inside the existing If we start passing functions that determine the conditions to trigger the selectors, well, we still need inline So I think this IB here is good-to-go, but if I'm being daft and missing something that a proof-of-concept could show with a more straightforward approach, please leave it here or make a draft PR and we can adjust the approach taken here 😅 IB ✅ |
Indeed, the custom hooks aren't composable - didn't realise that! I tried The above, while comprehensible, is not as straightforward as adding |
In my example above, I used a fictitious new component called
@jimmymadon the point of the value prop would be to allow the guard to work either way (I.e. |
@tofumatt @aaemnnosttv After replacing all site-kit-wp/assets/js/modules/adsense/components/dashboard/DashboardTopEarningPagesWidget.js Line 121 in 6874c2e
|
QA Update ❌On develop branch Traffic Widget analytics source link is not navigating to correct address. Link navigating to (Site/wp-admin/admin.php?page=googlesitekit-dashboard¬ification=authentication_success&slug=adsense#traffic) cc @wpdarren |
Thanks @mohitwp, good spot. As Jimmy's off the rest of this week I've picked this up and created a followup PR to fix it. |
Back to you for another pass @mohitwp 👍 |
QA Update ✅Verified 👍
|
Thanks for raising those, @jimmymadon. I've created an issue for the |
Bug Description
In #4815, we added conditional logic to prevent source links for widgets from displaying because we don't know if the user will be able to follow the deep link or not due to their lack of Google authentication. This issue addressed the visual aspect of the problem but there is now a residual technical problem related to the selectors used to generate the deep link.
The
SourceLink
itself no longer renders in view-only contexts but the URL given to it is selected in the parent. Since view-only users do not currently have access to modulesettings
endpoints, the settings do not get preloaded and when requested on the client (triggered by a setting selector for some data needed in a service URL), it triggers a fetch request which again fails for the same reason it was not preloaded (lack of permissions).Steps to reproduce
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
getService*URL
selectors should be updated such that the selector is only invoked in a non-view-only contextImplementation Brief
Files to update:
DataBlock.js
andLayoutFooter.js
contain the<SourceLink>
but they or their parents do not currently makegetService*URL
requests.Within the files to update above, identify the
getService*URL
selectors the result of which are eventually used within the<SourceLink>
component. In those selectors, return null early if theuseViewOnly
hook istrue
. E.g. inModuleOverviewWidget/Footer.js
:Test Coverage
SourceLink.test.js
for simpler components in the files to update list above. Simple components could be those which only render the<SourceLink>
component with a single or couple of selectors. E.g.assets/js/modules/analytics/components/module/ModulePopularPagesWidget/Footer.js
QA Brief
Google Site Kit API Error method:GET datapoint:settings type:modules identifier:analytics error:"Sorry, you are not allowed to do that."
Changelog entry
The text was updated successfully, but these errors were encountered: