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

chore: Migrate /superset/schemas_access_for_file_upload to v1 #23227

Merged
merged 5 commits into from
Mar 15, 2023

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Feb 28, 2023

SUMMARY

replacing #23033

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

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

…/migrate-schemas-access-for-file-upload-to-v1
@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Merging #23227 (cd17f8b) into master (42db7e5) will increase coverage by 0.03%.
The diff coverage is 71.25%.

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

@@            Coverage Diff             @@
##           master   #23227      +/-   ##
==========================================
+ Coverage   67.47%   67.51%   +0.03%     
==========================================
  Files        1906     1907       +1     
  Lines       73403    73472      +69     
  Branches     7958     7976      +18     
==========================================
+ Hits        49527    49601      +74     
+ Misses      21835    21822      -13     
- Partials     2041     2049       +8     
Flag Coverage Δ
hive 52.77% <64.86%> (+0.05%) ⬆️
postgres 78.50% <85.40%> (+0.01%) ⬆️
presto 52.70% <64.86%> (+0.07%) ⬆️
python 82.23% <88.10%> (+0.01%) ⬆️
sqlite 76.97% <83.78%> (+0.01%) ⬆️
unit 52.48% <46.48%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...et-ui-chart-controls/src/operators/sortOperator.ts 100.00% <ø> (ø)
...rt-controls/src/shared-controls/customControls.tsx 17.39% <0.00%> (-7.61%) ⬇️
...s/plugin-chart-pivot-table/src/PivotTableChart.tsx 0.00% <0.00%> (ø)
...tend/plugins/plugin-chart-table/src/TableChart.tsx 45.16% <0.00%> (-0.25%) ⬇️
...frontend/src/components/DatabaseSelector/index.tsx 91.66% <ø> (ø)
...et-frontend/src/components/TableSelector/index.tsx 79.22% <ø> (ø)
...t-frontend/src/dashboard/actions/dashboardState.js 55.76% <0.00%> (+1.30%) ⬆️
superset-frontend/src/dashboard/actions/hydrate.js 2.08% <0.00%> (+0.21%) ⬆️
...src/dashboard/components/DashboardBuilder/state.ts 70.37% <ø> (-2.05%) ⬇️
...dashboard/components/SliceHeaderControls/index.tsx 72.22% <ø> (+1.81%) ⬆️
... and 146 more

... and 4 files with indirect coverage changes

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

mock_can_access_database,
mock_schemas_accessible,
):
self.login(username="admin")
Copy link
Member

Choose a reason for hiding this comment

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

nit: we could have used gamma user, since it has no predefined access to any database.

So we should have a test with gamma user testing data permissions.
And a simple test with admin (or not) to a non existing database.


try:
schemas_allowed = database.get_schema_access_for_file_upload()
if security_manager.can_access_database(database):
Copy link
Member

Choose a reason for hiding this comment

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

I found it a bit confusing at first, why do we need to check can_access_database again, but the initial filter applied to DatabaseDAO.find_by_id will show the databases that the user has access directly and by child dependency, datasets and schemas.

On the other hand get_schemas_accessible_by_user will check security_manager.can_access_database(database) and return schemas_allowed has is, so the following check is not needed

# and the list schemas_allowed_processed returned from security_manager
# should not be empty either,
# otherwise the database should have been filtered out
# in CsvToDatabaseForm
Copy link
Member

Choose a reason for hiding this comment

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

if we call it using:

security_manager.get_schemas_accessible_by_user(
                database, schemas_allowed, True
)

we can remove the previous is security_manager.can_access_database(database)

database, schemas_allowed, False
)
return self.response(200, schemas=schemas_allowed_processed)
except Exception as ex: # pylint: disable=broad-except
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the broad exception catch, since Superset has a catch all exceptions on the API, so the broad exception will return HTTP 500 using our defaults

@hughhhh hughhhh requested a review from dpgaspar March 13, 2023 21:46
Copy link
Member

@eschutho eschutho left a comment

Choose a reason for hiding this comment

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

LGTM

):
self.login(username="gamma")
self.create_fake_db()
mock_can_access_all_datasources.return_value = False
Copy link
Member

Choose a reason for hiding this comment

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

using user gamma we should not need to mock can_access_database and can_access_all_datasources

mock_schemas_accessible.return_value = ["this_schema_is_allowed_too"]
rv = self.client.get(f"/api/v1/database/120ff/schemas_access_for_file_upload")
self.assertEqual(rv.status_code, 404)
self.delete_fake_db()
Copy link
Member

Choose a reason for hiding this comment

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

can you add another simple test to assert a database id that does not exist returns a 404 from this endpoint?

@hughhhh hughhhh merged commit 9920ab3 into master Mar 15, 2023
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 13, 2024
@mistercrunch mistercrunch deleted the hugh/migrate-schemas-access-for-file-upload-to-v1 branch March 26, 2024 17:56
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 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants