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: update Permissions for right nav #19051

Merged
merged 13 commits into from
Apr 11, 2022

Conversation

AAfghahi
Copy link
Member

@AAfghahi AAfghahi commented Mar 7, 2022

SUMMARY

Updating the permissions in the right nav bar to check that a user can upload csv and excel files to a database before showing them the options. Makes it so that non-Admin users only see menu items when they have a shared database.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After:
as Admin

Screen.Recording.2022-03-09.at.1.35.55.PM.mov

TESTING INSTRUCTIONS

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

@superset-github-bot superset-github-bot bot added the Superset-Community-Partners Preset community partner program participants label Mar 7, 2022
@AAfghahi AAfghahi force-pushed the ch36353_upload_menus branch 2 times, most recently from 7d8416b to fea9336 Compare March 9, 2022 18:41
@AAfghahi AAfghahi marked this pull request as ready for review March 9, 2022 18:43
@AAfghahi AAfghahi force-pushed the ch36353_upload_menus branch 2 times, most recently from 36f736c to fe33eaf Compare March 9, 2022 18:49
@@ -105,19 +129,22 @@ const RightMenu = ({
label: t('Upload CSV to database'),
name: 'Upload a CSV',
url: '/csvtodatabaseview/form',
perm: CSV_EXTENSIONS,
perm: CSV_EXTENSIONS && showUploads,
upload: true,
Copy link
Member

Choose a reason for hiding this comment

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

would these need to be variable for the upload param?

@AAfghahi AAfghahi force-pushed the ch36353_upload_menus branch 2 times, most recently from 3f476c0 to 611b14b Compare March 9, 2022 19:18
@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #19051 (5538994) into master (d693f4e) will increase coverage by 0.17%.
The diff coverage is 81.42%.

❗ Current head 5538994 differs from pull request most recent head 0d2ec22. Consider uploading reports for the commit 0d2ec22 to get more accurate results

@@            Coverage Diff             @@
##           master   #19051      +/-   ##
==========================================
+ Coverage   66.30%   66.47%   +0.17%     
==========================================
  Files        1681     1681              
  Lines       64408    64465      +57     
  Branches     6593     6607      +14     
==========================================
+ Hits        42704    42856     +152     
+ Misses      20020    19915     -105     
- Partials     1684     1694      +10     
Flag Coverage Δ
javascript 51.15% <69.04%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
superset-frontend/src/views/components/Menu.tsx 60.00% <ø> (ø)
superset-frontend/src/views/components/SubMenu.tsx 85.96% <50.00%> (-1.54%) ⬇️
...perset-frontend/src/views/components/MenuRight.tsx 67.81% <66.66%> (+0.12%) ⬆️
...tend/src/views/CRUD/data/database/DatabaseList.tsx 69.23% <73.33%> (+1.28%) ⬆️
...rset-frontend/src/dashboard/util/findPermission.ts 100.00% <100.00%> (ø)
superset/databases/api.py 94.03% <100.00%> (+0.04%) ⬆️
superset/databases/filters.py 100.00% <100.00%> (ø)
superset-frontend/src/views/CRUD/utils.tsx 64.51% <0.00%> (-1.62%) ⬇️
superset/utils/core.py 89.83% <0.00%> (+0.11%) ⬆️
superset/models/core.py 89.07% <0.00%> (+0.23%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d693f4e...0d2ec22. Read the comment docs.

@@ -105,19 +129,19 @@ const RightMenu = ({
label: t('Upload CSV to database'),
name: 'Upload a CSV',
url: '/csvtodatabaseview/form',
perm: CSV_EXTENSIONS,
perm: CSV_EXTENSIONS && showUploads,
Copy link
Member

Choose a reason for hiding this comment

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

Nice like the dual perms checking!

@pkdotson
Copy link
Member

pkdotson commented Mar 9, 2022

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2022

@pkdotson Container image not yet published for this PR. Please try again when build is complete.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2022

@pkdotson Ephemeral environment creation failed. Please check the Actions logs for details.

$ref: '#/components/responses/500'
"""
dbs_with_uploads = (
db.session.query(Database).filter_by(allow_file_upload=True).all()
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the ORM query fails? Can we add try catch to manage what we'd return to the user?

Copy link
Member

Choose a reason for hiding this comment

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

You could prolly just wrap it in a try/catch with a SupersetException then return a SIP-40 compliant error

Copy link
Member Author

Choose a reason for hiding this comment

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

What would a SIP-40 compliant error be? Also it is currently failing a test with:
No fallback response defined for GET to http://localhost/api/v1/database/upload_enabled".]

seems to be in a fetchMock. Are those related?

@@ -63,6 +79,9 @@ const StyledAnchor = styled.a`

const { SubMenu } = Menu;

// stole this from findPermission.ts
const ADMIN_ROLE_NAME = 'admin';
Copy link
Member

Choose a reason for hiding this comment

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

do you want to export this from findPermission.ts so that if it changes there, it will change here, too?

superset/databases/api.py Outdated Show resolved Hide resolved
Copy link
Member

@lyndsiWilliams lyndsiWilliams left a comment

Choose a reason for hiding this comment

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

Found a couple of nits, nothing blocking

Comment on lines 179 to 181
useEffect(() => {
hasFileUploadEnabled();
}, []);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
useEffect(() => {
hasFileUploadEnabled();
}, []);
useEffect(() => hasFileUploadEnabled(), []);

Small nit, not blocking, but this can be written on one line.

@@ -165,14 +201,39 @@ const RightMenu = ({
setShowModal(false);
};

const isDisabled = isUserAdmin && !allowUploads;

const tooltipText = "Enable 'Allow data upload' in any database's settings";
Copy link
Member

Choose a reason for hiding this comment

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

Should this string be t() translated?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes! Thank you.

@AAfghahi AAfghahi force-pushed the ch36353_upload_menus branch 2 times, most recently from 5eb27e4 to 7527656 Compare March 10, 2022 16:54
@lyndsiWilliams lyndsiWilliams removed the Superset-Community-Partners Preset community partner program participants label Mar 10, 2022
@AAfghahi AAfghahi force-pushed the ch36353_upload_menus branch 7 times, most recently from 2945ef1 to be027d0 Compare March 11, 2022 17:29
selectable={false}
mode="horizontal"
onClick={handleMenuSelection}
onOpenChange={() => hasFileUploadEnabled()}
Copy link
Member

Choose a reason for hiding this comment

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

nit, this can just be

onOpenChange={hasFileUploadEnabled}

but also when testing it looks like this is also triggering on close, which you prob don't need.

@yousoph
Copy link
Member

yousoph commented Apr 8, 2022

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

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

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

Ephemeral environment shutdown and build artifacts deleted.

@yousoph yousoph reopened this Apr 8, 2022
@AAfghahi
Copy link
Member Author

AAfghahi commented Apr 8, 2022

/testenv up

@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

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

@pkdotson
Copy link
Member

@AAfghahi I think we need to add these perms to the database crud view dropdown as well.
Screen Shot 2022-04-11 at 10 02 12 AM

@AAfghahi
Copy link
Member Author

@pkdotson

Screen.Recording.2022-04-11.at.12.21.14.PM.mov

Copy link
Member

@pkdotson pkdotson left a comment

Choose a reason for hiding this comment

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

lgtm!

@AAfghahi AAfghahi force-pushed the ch36353_upload_menus branch 3 times, most recently from b485d0d to 7bfbe43 Compare April 11, 2022 19:22
@AAfghahi AAfghahi merged commit 4bf4d58 into apache:master Apr 11, 2022
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

philipher29 pushed a commit to ValtechMobility/superset that referenced this pull request Jun 9, 2022
* draft pr

* finished styling

* add filter

* added testing

* added tests

* added permissions tests

* Empty-Commit

* new test

* Update superset-frontend/src/views/components/MenuRight.tsx

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>

* revisions

* added to CRUD view

Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.0.0 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 need:qa-review Requires QA review size/XL 🚢 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants