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(charts): View in SQL Lab with relevant perm #24903

Merged
merged 1 commit into from
Aug 10, 2023

Conversation

giftig
Copy link
Contributor

@giftig giftig commented Aug 7, 2023

SUMMARY

Do not switch this button on the basis of the name of the role, instead use the relevant permission: [SQL Lab].[menu_access], which is allocated to that role as standard.

This prevents issues where the user has the correct permission but via some other role.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

screenshot_2023-08-07_11-30-03_bb67fd5e

TESTING INSTRUCTIONS

As a user with permissions to use SQL Lab, but not the role named sql_lab, click the three dots next to the datasource name in the chart editor and note that the "View in SQL Lab" button now appears as expected.

ADDITIONAL INFORMATION

@giftig
Copy link
Contributor Author

giftig commented Aug 7, 2023

Looks like I broke the frontend test; maybe the sql_lab role in the tests wasn't configured to actually have the correct permission. I'll take a look.

@giftig
Copy link
Contributor Author

giftig commented Aug 7, 2023

Yeah that's the problem: https://github.com/apache/superset/pull/22566/files#diff-886aee5ca8271a9274abc1cb77a23c33481dd94edf3170a1ea57dbe717ef1ba3R71

it's just a dummy role with no permissions because the existing functionality is gated on role name. Easy to fix.

@giftig giftig force-pushed the issue-24902 branch 2 times, most recently from 7289cec to 824e8fe Compare August 7, 2023 13:47
@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Merging #24903 (65ffc4a) into master (7397ab3) will increase coverage by 0.03%.
Report is 9 commits behind head on master.
The diff coverage is 76.66%.

❗ Current head 65ffc4a differs from pull request most recent head b42dfac. Consider uploading reports for the commit b42dfac to get more accurate results

@@            Coverage Diff             @@
##           master   #24903      +/-   ##
==========================================
+ Coverage   68.96%   69.00%   +0.03%     
==========================================
  Files        1906     1906              
  Lines       74122    74132      +10     
  Branches     8208     8209       +1     
==========================================
+ Hits        51116    51152      +36     
+ Misses      20883    20857      -26     
  Partials     2123     2123              
Flag Coverage Δ
javascript 55.83% <61.53%> (+<0.01%) ⬆️

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

Files Changed Coverage Δ
...tend/plugins/legacy-preset-chart-nvd3/src/utils.js 15.82% <0.00%> (-0.11%) ⬇️
...set-frontend/src/dashboard/util/permissionUtils.ts 85.71% <50.00%> (-0.96%) ⬇️
.../src/dashboard/components/gridComponents/Chart.jsx 59.29% <60.00%> (+1.03%) ⬆️
superset/db_engine_specs/shillelagh.py 87.50% <71.42%> (-12.50%) ⬇️
...re/components/controls/DatasourceControl/index.jsx 91.50% <100.00%> (ø)
superset-frontend/src/pages/Home/index.tsx 69.67% <100.00%> (ø)
superset/db_engine_specs/gsheets.py 76.47% <100.00%> (-0.18%) ⬇️
superset/db_engine_specs/sqlite.py 97.22% <100.00%> (+0.55%) ⬆️

... and 9 files with indirect coverage changes

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

@rusackas rusackas added the review:checkpoint Last PR reviewed during the daily review standup label Aug 7, 2023
@michael-s-molina michael-s-molina removed the review:checkpoint Last PR reviewed during the daily review standup label Aug 8, 2023
@pull-request-size pull-request-size bot added size/M and removed size/S labels Aug 9, 2023
@giftig giftig force-pushed the issue-24902 branch 2 times, most recently from efd3864 to 51e6f4d Compare August 9, 2023 08:48
Do not switch this button on the basis of the name of the role, instead
use the relevant permission: [SQL Lab].[menu_access], which is allocated
to that role as standard.

This prevents issues where the user has the correct permission but via
some other role.
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM with a minor improvement idea

test('userHasPermission always returns false for undefined user', () => {
arbitraryPermissions.forEach(permissionView => {
expect(
userHasPermission(undefinedUser, permissionView[1], permissionView[0]),
Copy link
Member

Choose a reason for hiding this comment

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

A minor nit, and I agree that the order of first having the view name, and then the perm makes sense, but from a usability perspective, might it be less error prone to just ask for the permissionView as the second arg to the userHasPermission function? Like so:

const userHasPermission = userHasPermission(underfinedUser, permissionView);

Especially, as both viewName and permissionName are both string, making it easy to mix them up. Having a tuple [string, string] feels less error prone.

Copy link
Contributor Author

@giftig giftig Aug 10, 2023

Choose a reason for hiding this comment

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

I was considering a couple of versions of this because it irked me that it's usually expressed like View.permission when printed from the backend but the ordering is ["permission", "View"] in the frontend tuple, so whichever order you use it's inconsistent with something.

But here, surely it's just as easy to mess up a [string, string] tuple by putting arguments in the wrong order as it is messing up individual arguments? Your tuple still requires two strings and the only syntactic difference ends up being the square brackets for the tuple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also toyed with a much less error prone interface like {view: "Something", permission: "can_read"} but that'd be inconsistent with the tuples found on the user, so I don't think that's great either.

Copy link
Member

Choose a reason for hiding this comment

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

@giftig you're right, there's probably no super safe way to do this. However, I assume perms usually come back in tuple format, so for that reason [string, string] could be good. But we can do that later, this is already a really good improvement.

@villebro villebro merged commit ce65a3b into apache:master Aug 10, 2023
26 checks passed
@michael-s-molina michael-s-molina added the v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch label Aug 10, 2023
@giftig giftig deleted the issue-24902 branch August 11, 2023 08:27
michael-s-molina pushed a commit that referenced this pull request Aug 14, 2023
@mistercrunch mistercrunch added 🍒 3.0.3 🍒 3.0.4 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 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/M v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch 🍒 3.0.0 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants