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: remove expose #19700

Merged
merged 2 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):

edit_columns = add_columns

search_filters = {
"allow_file_upload": [DatabaseUploadEnabledFilter],
"expose_in_sqllab": [DatabaseFilter],
}
search_filters = {"allow_file_upload": [DatabaseUploadEnabledFilter]}

list_select_columns = list_columns + ["extra", "sqlalchemy_uri", "password"]
order_columns = [
Expand Down
13 changes: 1 addition & 12 deletions superset/databases/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class DatabaseUploadEnabledFilter(BaseFilter): # pylint: disable=too-few-public
def apply(self, query: Query, value: Any) -> Query:
filtered_query = query.filter(Database.allow_file_upload)

database_perms = security_manager.user_view_menu_names("database_access")
schema_access_databases = can_access_databases("schema_access")
Copy link
Member

@eschutho eschutho Apr 15, 2022

Choose a reason for hiding this comment

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

if I compare this filter to the actual csv file upload validator, the validator checks for
security_manager.can_access_database(database)
and
schema in database.get_schema_access_for_file_upload() We're covering the latter in lines 74 - 88, and I'm assuming that datasource_access_databases = can_access_databases("datasource_access") should return the same as the former check in the validator.

datasource_access_databases = can_access_databases("datasource_access")

if hasattr(g, "user"):
Expand All @@ -82,19 +80,10 @@ def apply(self, query: Query, value: Any) -> Query:
if len(allowed_schemas):
return filtered_query

filtered_query = filtered_query.filter(
return filtered_query.filter(
or_(
cast(Database.extra, JSON)["schemas_allowed_for_file_upload"]
is not None,
cast(Database.extra, JSON)["schemas_allowed_for_file_upload"] != [],
)
)

return filtered_query.filter(
or_(
self.model.perm.in_(database_perms),
self.model.database_name.in_(
[*schema_access_databases, *datasource_access_databases]
),
)
)
2 changes: 1 addition & 1 deletion tests/integration_tests/databases/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def test_get_allow_file_upload_false_csv(self):
uri = f"api/v1/database/?q={prison.dumps(arguments)}"
rv = self.client.get(uri)
data = json.loads(rv.data.decode("utf-8"))
assert data["count"] == 0
assert data["count"] == 1

def test_get_allow_file_upload_filter_no_permission(self):
"""
Expand Down