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

Updates RunQueries permission checks on front end #2550

Merged
merged 4 commits into from
May 21, 2024

Conversation

mknowlton89
Copy link
Collaborator

@mknowlton89 mknowlton89 commented May 20, 2024

Features and Changes

While doing some testing, I found that we weren't doing any permission checks before trying to generate or re-generate an information schema for a particular datasource, resulting in not only permission errors, but permission errors that weren't being handled and causing the app to crash.

Now, we are checking for permission on the frontend before we attempt to generate/regenerate a datasource's information schema.

Additionally, we didn't have any protections around the Test Queries permissions - now, in the EditSQLModal we are disabling the Test Query button and adding a tooltip if the user doesn't have
canRunTestQueries permission.

Likewise, we are automatically unchecking the Test queries before saving if the user doesn't have test query permissions, and disabling the input + wrapping it in a tooltip.

Reproduction steps / Testing

  • Create a custom role with the following policies - DatasourcesFullAccess, DataSourceConfiguration, and MetricsFullAccess.
  • Apply this role to a user and then attempt to create a metric on a datasource that supports information_schemas
  • Click the Edit SQL button and see that there is no information schema or the info schema for the connected datasource is out of date and needs to be refreshed.
  • Ensure that the CTA is disabled with a tooltip.

Screenshots

Screenshot of the info schema table refresh button when user doesn't have permission
Screen Shot 2024-05-20 at 9 13 16 AM

Screenshot of the info schema databaes refresh button when user doesn't have permission
Screen Shot 2024-05-20 at 9 13 09 AM

Screenshot of the disabled input when user doesn't have test queries permission
Screen Shot 2024-05-20 at 9 12 29 AM

Screenshot of the disabled Test Query button if the user doesn't have test queries permission
Screen Shot 2024-05-20 at 9 08 24 AM

Screenshot of the disabled retry button when the user doesn't have canRunSchemaQueries permission
Screen Shot 2024-05-20 at 9 08 28 AM

@mknowlton89 mknowlton89 self-assigned this May 20, 2024
@mknowlton89 mknowlton89 changed the title Updates the info schema front-end permission checks. Updates RunQueries permission checks on front end May 20, 2024
@mknowlton89 mknowlton89 marked this pull request as ready for review May 20, 2024 13:24
Copy link

github-actions bot commented May 20, 2024

Your preview environment pr-2550-bttf has been deployed.

Preview environment endpoints are available at:

@mknowlton89
Copy link
Collaborator Author

NOTE: I've also updated the underlying policies that resulted in this issue in PR 2551 - That likely removes most of the need for this PR, but I still think adding this protection on the frontend makes sense, especially since these errors caused the app to crash.

@mknowlton89 mknowlton89 requested a review from jdorn May 20, 2024 13:59
@jdorn
Copy link
Member

jdorn commented May 21, 2024

If the app was crashing, it's not because we were missing permission checks. It's because we're making an async call in a click handler without catching errors. Adding permission checks is good, but we should also fix the underlying issue. Otherwise, the crashing bug will still happen if the network request fails for any other reason.

@mknowlton89
Copy link
Collaborator Author

If the app was crashing, it's not because we were missing permission checks. It's because we're making an async call in a click handler without catching errors. Adding permission checks is good, but we should also fix the underlying issue. Otherwise, the crashing bug will still happen if the network request fails for any other reason.

Good call - after looking into it further, we weren't awaiting the response in the refreshOrCreateInfoSchema call, resulting in the uncaught exception. This is now async and will await the response and catch the error correctly.

See the change in this commit.

@mknowlton89 mknowlton89 merged commit 2dd943a into main May 21, 2024
3 checks passed
@mknowlton89 mknowlton89 deleted the mk/info-schema-permission-error branch May 21, 2024 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants