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

[WIP] refactor: replace "csv" with "file" used in common (excel) upload cases #13805

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def get_foreign_keys(
) -> List[Dict[str, Any]]:
return self.inspector.get_foreign_keys(table_name, schema)

def get_schema_access_for_csv_upload( # pylint: disable=invalid-name
def get_schema_access_for_file_upload( # pylint: disable=invalid-name
self,
) -> List[str]:
allowed_databases = self.get_extra().get("schemas_allowed_for_csv_upload", [])
Expand Down
2 changes: 1 addition & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,7 @@ def schemas_access_for_csv_upload(self) -> FlaskResponse:
db_id = int(request.args["db_id"])
database = db.session.query(Database).filter_by(id=db_id).one()
try:
schemas_allowed = database.get_schema_access_for_csv_upload()
schemas_allowed = database.get_schema_access_for_file_upload()
if security_manager.can_access_database(database):
return self.json_response(schemas_allowed)
# the list schemas_allowed should not be empty here
Expand Down
4 changes: 2 additions & 2 deletions superset/views/database/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def at_least_one_schema_is_allowed(database: Database) -> bool:
"""
if security_manager.can_access_database(database):
return True
schemas = database.get_schema_access_for_csv_upload()
schemas = database.get_schema_access_for_file_upload()
if schemas and security_manager.get_schemas_accessible_by_user(
database, schemas, False
):
Expand Down Expand Up @@ -265,7 +265,7 @@ def at_least_one_schema_is_allowed(database: Database) -> bool:
"""
if security_manager.can_access_database(database):
return True
schemas = database.get_schema_access_for_csv_upload()
schemas = database.get_schema_access_for_file_upload()
if schemas and security_manager.schemas_accessible_by_user(
database, schemas, False
):
Expand Down
4 changes: 2 additions & 2 deletions superset/views/database/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def sqlalchemy_uri_validator(
)


def schema_allows_csv_upload(database: Database, schema: Optional[str]) -> bool:
def schema_allows_file_upload(database: Database, schema: Optional[str]) -> bool:
if not database.allow_csv_upload:
return False
schemas = database.get_schema_access_for_csv_upload()
schemas = database.get_schema_access_for_file_upload()
if schemas:
return schema in schemas
return security_manager.can_access_database(database)
6 changes: 3 additions & 3 deletions superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from .forms import CsvToDatabaseForm, ExcelToDatabaseForm
from .mixins import DatabaseMixin
from .validators import schema_allows_csv_upload, sqlalchemy_uri_validator
from .validators import schema_allows_file_upload, sqlalchemy_uri_validator

if TYPE_CHECKING:
from werkzeug.datastructures import FileStorage # pylint: disable=unused-import
Expand Down Expand Up @@ -128,7 +128,7 @@ def form_post(self, form: CsvToDatabaseForm) -> Response:
database = form.con.data
csv_table = Table(table=form.name.data, schema=form.schema.data)

if not schema_allows_csv_upload(database, csv_table.schema):
if not schema_allows_file_upload(database, csv_table.schema):
message = _(
'Database "%(database_name)s" schema "%(schema_name)s" '
"is not allowed for csv uploads. Please contact your Superset Admin.",
Expand Down Expand Up @@ -285,7 +285,7 @@ def form_post(self, form: ExcelToDatabaseForm) -> Response:
database = form.con.data
excel_table = Table(table=form.name.data, schema=form.schema.data)

if not schema_allows_csv_upload(database, excel_table.schema):
if not schema_allows_file_upload(database, excel_table.schema):
message = _(
'Database "%(database_name)s" schema "%(schema_name)s" '
"is not allowed for excel uploads. Please contact your Superset Admin.",
Expand Down