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

fix(sqllab): remove link to sqllab if missing perms #22566

Merged
merged 12 commits into from
Jan 9, 2023

Conversation

villebro
Copy link
Member

@villebro villebro commented Jan 2, 2023

SUMMARY

Currently the "View in SQL Lab" option is available in the Dataset menu in Explore view even when the user doesn't belong to the sql_lab role. In addition, SQL Lab is accessible (albeit doesn't work properly) when the necessary permissions are missing.

This PR does the following:

  • Removes the "View in SQL Lab" option from the Dataset menu
  • Redirects the user to the welcome page when trying to access SQL Lab without necessary permissions.
  • Remove "Saved Queries" from Welcome page if user is missing sql_lab role

AFTER

Now when a user that doesn't have the sql_lab role will no longer see the "View in SQL Lab" menu item:

image

For admin and users with sql_lab role the menu is unchanged:

image

When attempting to access SQL Lab without correct perms via a direct URL, the user gets redirected to the welcome page with an error toast. Also, the welcome page doesn't show the "Saved Queries" section if the user doesn't belong to the sql_lab role (we could optionally check the specific perms for saved queries, but maybe we can do that in a follow up if that's really needed):

image

Note that due to the way we're currently caching bootstrap data, toasts don't always appear correctly (they can appear delayed or not get cleared after displaying). I will follow up separately to fix this.

TESTING INSTRUCTIONS

For testing instructions, please see the following comment in this PR: #22566 (comment)

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented Jan 3, 2023

Codecov Report

Merging #22566 (e317744) into master (a7a4561) will increase coverage by 0.10%.
The diff coverage is 64.28%.

@@            Coverage Diff             @@
##           master   #22566      +/-   ##
==========================================
+ Coverage   66.91%   67.02%   +0.10%     
==========================================
  Files        1851     1859       +8     
  Lines       70709    71046     +337     
  Branches     7766     7771       +5     
==========================================
+ Hits        47316    47619     +303     
- Misses      21371    21404      +33     
- Partials     2022     2023       +1     
Flag Coverage Δ
hive 52.61% <100.00%> (+0.14%) ⬆️
javascript 53.86% <59.45%> (+<0.01%) ⬆️
mysql 78.02% <100.00%> (+0.06%) ⬆️
postgres 78.09% <100.00%> (+0.06%) ⬆️
presto 52.51% <100.00%> (+0.15%) ⬆️
python 81.35% <100.00%> (+0.08%) ⬆️
sqlite 76.47% <100.00%> (-0.03%) ⬇️
unit 51.47% <60.00%> (+0.28%) ⬆️

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

Impacted Files Coverage Δ
.../src/views/CRUD/data/savedquery/SavedQueryList.tsx 63.30% <ø> (ø)
...-frontend/src/views/CRUD/welcome/ActivityTable.tsx 41.81% <28.57%> (-0.29%) ⬇️
...perset-frontend/src/views/CRUD/welcome/Welcome.tsx 71.18% <59.09%> (+0.49%) ⬆️
...set-frontend/src/dashboard/util/permissionUtils.ts 86.66% <80.00%> (-3.34%) ⬇️
...re/components/controls/DatasourceControl/index.jsx 84.90% <100.00%> (+0.29%) ⬆️
superset/security/manager.py 95.77% <100.00%> (+0.01%) ⬆️
superset/dashboards/filter_state/commands/utils.py 80.00% <0.00%> (-10.00%) ⬇️
...uperset/dashboards/filter_state/commands/delete.py 91.30% <0.00%> (-4.35%) ⬇️
superset/databases/commands/update.py 75.86% <0.00%> (-4.14%) ⬇️
...uperset/dashboards/filter_state/commands/update.py 96.66% <0.00%> (-3.34%) ⬇️
... and 39 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@zhaoyongjie zhaoyongjie self-requested a review January 3, 2023 09:25
@zhaoyongjie
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2023

@zhaoyongjie Ephemeral environment spinning up at http://18.236.102.188:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@villebro
Copy link
Member Author

villebro commented Jan 3, 2023

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2023

@villebro Ephemeral environment spinning up at http://34.219.163.111:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

or "sql_lab" in (role.name for role in security_manager.get_user_roles())
):
flash(__("You do not have access to SQL Lab"), "danger")
return redirect("/")
Copy link
Member

Choose a reason for hiding this comment

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

This probably makes more sense to fix on security manager, where all roles are created

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I'll move it over 👍

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

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

Frontend part looks great to me!

@villebro villebro requested a review from dpgaspar January 4, 2023 07:53
@villebro
Copy link
Member Author

villebro commented Jan 4, 2023

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2023

@villebro Ephemeral environment spinning up at http://54.187.147.88:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@villebro
Copy link
Member Author

villebro commented Jan 4, 2023

For testing I've created the following users on the eph env:

UID: gamma
PWD: gamma
Test case: directly accessing /superset/sqllab redirects to welcome page with an error toast and "View in SQL Lab" is missing in Dataset menu:
image

UID: sqlgamma
PWD: sqlgamma
Test case: SQL Lab works and "View in SQL Lab" is present in Dataset menu:
image

Comment on lines +25 to +29
import {
canUserAccessSqlLab,
canUserEditDashboard,
isUserAdmin,
} from './permissionUtils';
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: these should probably be moved to a general util outside the dashboard section, but refactoring it seems outside the scope of this PR

@@ -157,12 +157,12 @@ def test_get_list_saved_query_gamma(self):
"""
Saved Query API: Test get list saved query
"""
gamma = self.get_user("gamma")
user = self.get_user("gamma_sqllab")
Copy link
Member Author

Choose a reason for hiding this comment

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

The gamma_sqllab test user has both Gamma and sql_lab roles.

Copy link
Member

Choose a reason for hiding this comment

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

did we had to change this user for the tests to pass?

@villebro
Copy link
Member Author

villebro commented Jan 6, 2023

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2023

@villebro Ephemeral environment spinning up at http://35.89.82.98:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@villebro
Copy link
Member Author

villebro commented Jan 6, 2023

FYI, I've recreated the ephemeral environment with the same test users as previously (same UID/PWD):

  • admin: the regular admin user
  • gamma: gamma user with access to Examples database
  • sqlgamma: gamma user with access to Examples database and sql_lab role

The users that have access to SQL Lab also have a saved query which one should be able to see from the Welcome page

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

image

Test in the ephemeral env and it works as expected. Thanks for lots of refactor codes. LGTM.

@@ -157,12 +157,12 @@ def test_get_list_saved_query_gamma(self):
"""
Saved Query API: Test get list saved query
"""
gamma = self.get_user("gamma")
user = self.get_user("gamma_sqllab")
Copy link
Member

Choose a reason for hiding this comment

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

did we had to change this user for the tests to pass?

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

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

Re-tested after latest changes, LGTM!

@villebro villebro merged commit 5b2ca97 into apache:master Jan 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2023

Ephemeral environment shutdown and build artifacts deleted.

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants