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

feat: cleanup permissions when db updated/deleted #17449

Closed
wants to merge 5 commits into from

Conversation

jfrag1
Copy link
Member

@jfrag1 jfrag1 commented Nov 16, 2021

SUMMARY

Up until now, when deleting or renaming a database connection, permissions for the old connection name would persist. Additionally, when renaming a database connection, permissions for access on that database's existing datasets would not be created with the new connection name.

This PR introduces a way to clean up unneeded permissions after a database is renamed or deleted, and also ensures that permissions for a database's associated datasets are kept up-to-date if the database connection is renamed.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

  • Create a database connection and associated datasets
  • Rename the database connection
  • See that permissions for the old name are gone and permissions for the new database name have been created

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

@jfrag1 jfrag1 marked this pull request as ready for review November 16, 2021 17:46
@geido
Copy link
Member

geido commented Nov 17, 2021

Hey @jfrag1 this is great. It would be optimal if you could add some test cases too. Thank you!

@pull-request-size pull-request-size bot added size/L and removed size/M labels Nov 18, 2021
@codecov
Copy link

codecov bot commented Nov 18, 2021

Codecov Report

Merging #17449 (4ed8867) into master (c07a707) will increase coverage by 0.03%.
The diff coverage is 78.94%.

❗ Current head 4ed8867 differs from pull request most recent head 80574e9. Consider uploading reports for the commit 80574e9 to get more accurate results

@@            Coverage Diff             @@
##           master   #17449      +/-   ##
==========================================
+ Coverage   66.51%   66.54%   +0.03%     
==========================================
  Files        1667     1667              
  Lines       64415    64448      +33     
  Branches     6503     6503              
==========================================
+ Hits        42846    42890      +44     
+ Misses      19884    19873      -11     
  Partials     1685     1685              
Flag Coverage Δ
hive 52.66% <18.42%> (-0.04%) ⬇️
mysql ?
postgres 81.59% <78.94%> (-0.02%) ⬇️
presto 52.51% <18.42%> (?)
python 81.98% <78.94%> (+0.05%) ⬆️
sqlite 81.37% <78.94%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
superset/models/core.py 88.30% <ø> (-0.51%) ⬇️
superset/databases/commands/delete.py 85.71% <62.50%> (-5.72%) ⬇️
superset/databases/commands/update.py 88.52% <73.33%> (-5.36%) ⬇️
superset/security/manager.py 95.02% <92.30%> (-0.08%) ⬇️
superset/databases/commands/exceptions.py 96.15% <100.00%> (+0.15%) ⬆️
superset/common/utils/dataframe_utils.py 85.71% <0.00%> (-7.15%) ⬇️
superset/db_engine_specs/mysql.py 93.97% <0.00%> (-3.62%) ⬇️
superset/reports/commands/log_prune.py 85.71% <0.00%> (-3.58%) ⬇️
superset/commands/importers/v1/utils.py 92.20% <0.00%> (-1.30%) ⬇️
superset/common/query_object.py 95.18% <0.00%> (-0.54%) ⬇️
... and 5 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 c07a707...80574e9. Read the comment docs.

@jfrag1
Copy link
Member Author

jfrag1 commented Nov 18, 2021

@geido I added some tests. I'm not very familiar with Superset testing patterns/organization; please let me know if these are sufficient/in the right place :)

@jfrag1 jfrag1 closed this Nov 18, 2021
@jfrag1 jfrag1 reopened this Nov 18, 2021
@jfrag1 jfrag1 closed this Nov 18, 2021
@jfrag1 jfrag1 reopened this Nov 18, 2021
@geido
Copy link
Member

geido commented Nov 24, 2021

Hello @jfrag1 thanks for that! I requested some more reviews.

if old_db_name != database.database_name:
security_manager.add_permission_view_menu("database_access", database.perm)
for dataset in database.tables:
security_manager.add_permission_view_menu(
Copy link
Member

Choose a reason for hiding this comment

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

missing test coverage, can you check?

Copy link
Member Author

@jfrag1 jfrag1 Dec 14, 2021

Choose a reason for hiding this comment

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

There are currently no tests covering these database update/delete commands - I spent about an hour looking into adding some, but I kept running into issues/couldn't figure out how to properly set everything up. I don't have the time right now to dive in and figure out how to add these missing tests.

@jfrag1 jfrag1 force-pushed the jack/cleanup-db-permissions branch from 647e4d7 to 80574e9 Compare March 21, 2022 16:22
@dpgaspar
Copy link
Member

dpgaspar commented Sep 2, 2022

@jfrag1 closing, this was done here: #21161 and #20081.

Feel free to reopen if you think this is still valid

@dpgaspar dpgaspar closed this Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants