refactor: Repeated boilerplate code between upload to database forms (#16756)

* abstract boilerplate code into class and rename csv to file

* add db migration

* fix some stuff

* more renaming of csv to file

* rename in translations

* update down revision

* update down revision

* bump chart version

* switch to alter column name approach in db migration

* fix db migration for MySQL

* db migration conflict
This commit is contained in:
Shiva Raisinghani 2021-10-25 03:53:06 -07:00 committed by GitHub
parent 4f1d202430
commit ef3afbde82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 205 additions and 251 deletions

View File

@ -185,12 +185,12 @@ Data source definitions can be automatically declared by providing key/value yam
extraConfigs:
datasources-init.yaml: |
databases:
- allow_csv_upload: true
- allow_file_upload: true
allow_ctas: true
allow_cvas: true
database_name: example-db
extra: "{\r\n \"metadata_params\": {},\r\n \"engine_params\": {},\r\n \"\
metadata_cache_timeout\": {},\r\n \"schemas_allowed_for_csv_upload\": []\r\n\
metadata_cache_timeout\": {},\r\n \"schemas_allowed_for_file_upload\": []\r\n\
}"
sqlalchemy_uri: example://example-db.local
tables: []

View File

@ -22,7 +22,7 @@ maintainers:
- name: craig-rueda
email: craig@craigrueda.com
url: https://github.com/craig-rueda
version: 0.3.10
version: 0.3.11
dependencies:
- name: postgresql
version: 10.2.0

View File

@ -80,12 +80,12 @@ extraSecretEnv: {}
extraConfigs: {}
# datasources-init.yaml: |
# databases:
# - allow_csv_upload: true
# - allow_file_upload: true
# allow_ctas: true
# allow_cvas: true
# database_name: example-db
# extra: "{\r\n \"metadata_params\": {},\r\n \"engine_params\": {},\r\n \"\
# metadata_cache_timeout\": {},\r\n \"schemas_allowed_for_csv_upload\": []\r\n\
# metadata_cache_timeout\": {},\r\n \"schemas_allowed_for_file_upload\": []\r\n\
# }"
# sqlalchemy_uri: example://example-db.local
# tables: []

View File

@ -66,7 +66,7 @@ beforeEach(() => {
description_columns: {},
ids: [1, 2],
label_columns: {
allow_csv_upload: 'Allow Csv Upload',
allow_file_upload: 'Allow Csv Upload',
allow_ctas: 'Allow Ctas',
allow_cvas: 'Allow Cvas',
allow_dml: 'Allow Dml',
@ -88,7 +88,7 @@ beforeEach(() => {
id: 'Id',
},
list_columns: [
'allow_csv_upload',
'allow_file_upload',
'allow_ctas',
'allow_cvas',
'allow_dml',
@ -110,7 +110,7 @@ beforeEach(() => {
],
list_title: 'List Database',
order_columns: [
'allow_csv_upload',
'allow_file_upload',
'allow_dml',
'allow_run_async',
'changed_on',
@ -121,7 +121,7 @@ beforeEach(() => {
],
result: [
{
allow_csv_upload: false,
allow_file_upload: false,
allow_ctas: false,
allow_cvas: false,
allow_dml: false,

View File

@ -54,7 +54,7 @@ const mockdatabases = [...new Array(3)].map((_, i) => ({
backend: 'postgresql',
allow_run_async: true,
allow_dml: false,
allow_csv_upload: true,
allow_file_upload: true,
expose_in_sqllab: false,
changed_on_delta_humanized: `${i} day(s) ago`,
changed_on: new Date().toISOString,

View File

@ -267,13 +267,13 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
size: 'sm',
},
{
accessor: 'allow_csv_upload',
accessor: 'allow_file_upload',
Header: t('CSV upload'),
Cell: ({
row: {
original: { allow_csv_upload: allowCSVUpload },
original: { allow_file_upload: allowFileUpload },
},
}: any) => <BooleanDisplay value={allowCSVUpload} />,
}: any) => <BooleanDisplay value={allowFileUpload} />,
size: 'md',
},
{

View File

@ -371,9 +371,9 @@ const ExtraOptions = ({
<div className="input-container">
<input
type="text"
name="schemas_allowed_for_csv_upload"
name="schemas_allowed_for_file_upload"
value={(
db?.extra_json?.schemas_allowed_for_csv_upload || []
db?.extra_json?.schemas_allowed_for_file_upload || []
).join(',')}
placeholder="schema1,schema2"
onChange={onExtraInputChange}
@ -410,9 +410,9 @@ const ExtraOptions = ({
<StyledInputContainer css={{ ...no_margin_bottom }}>
<div className="input-container">
<IndeterminateCheckbox
id="allow_csv_upload"
id="allow_file_upload"
indeterminate={false}
checked={!!db?.allow_csv_upload}
checked={!!db?.allow_file_upload}
onChange={onInputChange}
labelText={t('Allow data upload')}
/>

View File

@ -237,12 +237,12 @@ function dbReducer(
},
};
}
if (action.payload.name === 'schemas_allowed_for_csv_upload') {
if (action.payload.name === 'schemas_allowed_for_file_upload') {
return {
...trimmedState,
extra_json: {
...trimmedState.extra_json,
schemas_allowed_for_csv_upload: (action.payload.value || '').split(
schemas_allowed_for_file_upload: (action.payload.value || '').split(
',',
),
},
@ -346,8 +346,8 @@ function dbReducer(
...JSON.parse(action.payload.extra || ''),
metadata_params: JSON.stringify(extra_json?.metadata_params),
engine_params: JSON.stringify(extra_json?.engine_params),
schemas_allowed_for_csv_upload:
extra_json?.schemas_allowed_for_csv_upload,
schemas_allowed_for_file_upload:
extra_json?.schemas_allowed_for_file_upload,
};
}
@ -412,8 +412,8 @@ const serializeExtra = (extraJson: DatabaseObject['extra_json']) =>
engine_params: JSON.parse(
((extraJson?.engine_params as unknown) as string) || '{}',
),
schemas_allowed_for_csv_upload: (
extraJson?.schemas_allowed_for_csv_upload || []
schemas_allowed_for_file_upload: (
extraJson?.schemas_allowed_for_file_upload || []
).filter(schema => schema !== ''),
});

View File

@ -72,7 +72,7 @@ export type DatabaseObject = {
// Security
encrypted_extra?: string;
server_cert?: string;
allow_csv_upload?: boolean;
allow_file_upload?: boolean;
impersonate_user?: boolean;
parameters_schema?: Record<string, any>;
@ -87,7 +87,7 @@ export type DatabaseObject = {
table_cache_timeout?: number; // in Performance
}; // No field, holds schema and table timeout
allows_virtual_table_explore?: boolean; // in SQL Lab
schemas_allowed_for_csv_upload?: string[]; // in Security
schemas_allowed_for_file_upload?: string[]; // in Security
cancel_query_on_windows_unload?: boolean; // in Performance
version?: string;

View File

@ -863,7 +863,7 @@ def CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC( # pylint: disable=invalid-name
UPLOADED_CSV_HIVE_NAMESPACE: Optional[str] = None
# Function that computes the allowed schemas for the CSV uploads.
# Allowed schemas will be a union of schemas_allowed_for_csv_upload
# Allowed schemas will be a union of schemas_allowed_for_file_upload
# db configuration and a result of this function.
# mypy doesn't catch that if case ensures list content being always str

View File

@ -104,7 +104,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"cache_timeout",
"expose_in_sqllab",
"allow_run_async",
"allow_csv_upload",
"allow_file_upload",
"configuration_method",
"allow_ctas",
"allow_cvas",
@ -121,7 +121,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"sqlalchemy_uri",
]
list_columns = [
"allow_csv_upload",
"allow_file_upload",
"allow_ctas",
"allow_cvas",
"allow_dml",
@ -148,7 +148,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"cache_timeout",
"expose_in_sqllab",
"allow_run_async",
"allow_csv_upload",
"allow_file_upload",
"allow_ctas",
"allow_cvas",
"allow_dml",
@ -164,7 +164,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
list_select_columns = list_columns + ["extra", "sqlalchemy_uri", "password"]
order_columns = [
"allow_csv_upload",
"allow_file_upload",
"allow_dml",
"allow_run_async",
"changed_on",

View File

@ -39,11 +39,11 @@ def parse_extra(extra_payload: str) -> Dict[str, Any]:
logger.info("Unable to decode `extra` field: %s", extra_payload)
return {}
# Fix for DBs saved with an invalid ``schemas_allowed_for_csv_upload``
schemas_allowed_for_csv_upload = extra.get("schemas_allowed_for_csv_upload")
if isinstance(schemas_allowed_for_csv_upload, str):
extra["schemas_allowed_for_csv_upload"] = json.loads(
schemas_allowed_for_csv_upload
# Fix for DBs saved with an invalid ``schemas_allowed_for_file_upload``
schemas_allowed_for_file_upload = extra.get("schemas_allowed_for_file_upload")
if isinstance(schemas_allowed_for_file_upload, str):
extra["schemas_allowed_for_file_upload"] = json.loads(
schemas_allowed_for_file_upload
)
return extra

View File

@ -54,7 +54,7 @@ allow_run_async_description = (
"as a results backend. Refer to the installation docs "
"for more information."
)
allow_csv_upload_description = (
allow_file_upload_description = (
"Allow to upload CSV file data into this database"
"If selected, please set the schemas allowed for csv upload in Extra."
)
@ -108,9 +108,9 @@ extra_description = markdown(
'"table_cache_timeout": 600}**. '
"If unset, cache will not be enabled for the functionality. "
"A timeout of 0 indicates that the cache never expires.<br/>"
"3. The ``schemas_allowed_for_csv_upload`` is a comma separated list "
"3. The ``schemas_allowed_for_file_upload`` is a comma separated list "
"of schemas that CSVs are allowed to upload to. "
'Specify it as **"schemas_allowed_for_csv_upload": '
'Specify it as **"schemas_allowed_for_file_upload": '
'["public", "csv_upload"]**. '
"If database flavor does not support schema or any schema is allowed "
"to be accessed, just leave the list empty<br/>"
@ -355,7 +355,7 @@ class DatabasePostSchema(Schema, DatabaseParametersSchemaMixin):
)
expose_in_sqllab = fields.Boolean(description=expose_in_sqllab_description)
allow_run_async = fields.Boolean(description=allow_run_async_description)
allow_csv_upload = fields.Boolean(description=allow_csv_upload_description)
allow_file_upload = fields.Boolean(description=allow_file_upload_description)
allow_ctas = fields.Boolean(description=allow_ctas_description)
allow_cvas = fields.Boolean(description=allow_cvas_description)
allow_dml = fields.Boolean(description=allow_dml_description)
@ -397,7 +397,7 @@ class DatabasePutSchema(Schema, DatabaseParametersSchemaMixin):
)
expose_in_sqllab = fields.Boolean(description=expose_in_sqllab_description)
allow_run_async = fields.Boolean(description=allow_run_async_description)
allow_csv_upload = fields.Boolean(description=allow_csv_upload_description)
allow_file_upload = fields.Boolean(description=allow_file_upload_description)
allow_ctas = fields.Boolean(description=allow_ctas_description)
allow_cvas = fields.Boolean(description=allow_cvas_description)
allow_dml = fields.Boolean(description=allow_dml_description)
@ -558,15 +558,15 @@ class ImportV1DatabaseExtraSchema(Schema):
self, data: Dict[str, Any], **kwargs: Any
) -> Dict[str, Any]:
"""
Fix ``schemas_allowed_for_csv_upload`` being a string.
Fix ``schemas_allowed_for_file_upload`` being a string.
Due to a bug in the database modal, some databases might have been
saved and exported with a string for ``schemas_allowed_for_csv_upload``.
saved and exported with a string for ``schemas_allowed_for_file_upload``.
"""
schemas_allowed_for_csv_upload = data.get("schemas_allowed_for_csv_upload")
if isinstance(schemas_allowed_for_csv_upload, str):
data["schemas_allowed_for_csv_upload"] = json.loads(
schemas_allowed_for_csv_upload
schemas_allowed_for_file_upload = data.get("schemas_allowed_for_file_upload")
if isinstance(schemas_allowed_for_file_upload, str):
data["schemas_allowed_for_file_upload"] = json.loads(
schemas_allowed_for_file_upload
)
return data
@ -574,7 +574,7 @@ class ImportV1DatabaseExtraSchema(Schema):
metadata_params = fields.Dict(keys=fields.Str(), values=fields.Raw())
engine_params = fields.Dict(keys=fields.Str(), values=fields.Raw())
metadata_cache_timeout = fields.Dict(keys=fields.Str(), values=fields.Integer())
schemas_allowed_for_csv_upload = fields.List(fields.String())
schemas_allowed_for_file_upload = fields.List(fields.String())
cost_estimate_enabled = fields.Boolean()
@ -587,7 +587,7 @@ class ImportV1DatabaseSchema(Schema):
allow_run_async = fields.Boolean()
allow_ctas = fields.Boolean()
allow_cvas = fields.Boolean()
allow_csv_upload = fields.Boolean()
allow_file_upload = fields.Boolean()
extra = fields.Nested(ImportV1DatabaseExtraSchema)
uuid = fields.UUID(required=True)
version = fields.String(required=True)

View File

@ -0,0 +1,48 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""rename_csv_to_file
Revision ID: b92d69a6643c
Revises: 32646df09c64
Create Date: 2021-09-19 14:42:20.130368
"""
# revision identifiers, used by Alembic.
revision = "b92d69a6643c"
down_revision = "32646df09c64"
import sqlalchemy as sa
from alembic import op
def upgrade():
with op.batch_alter_table("dbs") as batch_op:
batch_op.alter_column(
"allow_csv_upload",
new_column_name="allow_file_upload",
existing_type=sa.Boolean(),
)
def downgrade():
with op.batch_alter_table("dbs") as batch_op:
batch_op.alter_column(
"allow_file_upload",
new_column_name="allow_csv_upload",
existing_type=sa.Boolean(),
)

View File

@ -129,7 +129,7 @@ class Database(
String(255), server_default=ConfigurationMethod.SQLALCHEMY_FORM.value
)
allow_run_async = Column(Boolean, default=False)
allow_csv_upload = Column(Boolean, default=False)
allow_file_upload = Column(Boolean, default=False)
allow_ctas = Column(Boolean, default=False)
allow_cvas = Column(Boolean, default=False)
allow_dml = Column(Boolean, default=False)
@ -145,7 +145,7 @@ class Database(
"metadata_params": {},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": []
"schemas_allowed_for_file_upload": []
}
"""
),
@ -161,7 +161,7 @@ class Database(
"allow_run_async",
"allow_ctas",
"allow_cvas",
"allow_csv_upload",
"allow_file_upload",
"extra",
]
extra_import_fields = ["password"]
@ -679,10 +679,10 @@ class Database(
) -> 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", [])
allowed_databases = self.get_extra().get("schemas_allowed_for_file_upload", [])
if isinstance(allowed_databases, str):
allowed_databases = literal_eval(allowed_databases)

View File

@ -2016,7 +2016,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7324,9 +7324,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -1922,7 +1922,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7323,9 +7323,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -2181,7 +2181,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7411,9 +7411,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -2305,7 +2305,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7504,9 +7504,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -2053,7 +2053,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7372,9 +7372,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -2411,7 +2411,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -8050,9 +8050,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:632
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of "
"3. The schemas_allowed_for_file_upload is a comma separated list of "
"schemas that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -2108,7 +2108,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7831,9 +7831,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:652
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of "
"3. The schemas_allowed_for_file_upload is a comma separated list of "
"schemas that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -8050,9 +8050,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:632
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of "
"3. The schemas_allowed_for_file_upload is a comma separated list of "
"schemas that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -2201,7 +2201,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7378,9 +7378,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -2660,8 +2660,8 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
"2. O metadata_cache_timeout é uma configuração de limite de tempo do cache em segundos para a busca dos metadados deste banco de dados. Especifique como \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. Se não configurado, o cache não será habilitado para a funcionalidade. Um limite de tempo de 0 indica que o cache nunca expira."
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. O schemas_allowed_for_csv_upload é uma lista de esquemas separada por vírgula nos quais é permitida a carga de CSVs. Especifique como \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. Se o banco de dados não suporta esquema ou a carga é permitida em qualque esquema, apenas deixe a lista vazia."
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. O schemas_allowed_for_file_upload é uma lista de esquemas separada por vírgula nos quais é permitida a carga de CSVs. Especifique como \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. Se o banco de dados não suporta esquema ou a carga é permitida em qualque esquema, apenas deixe a lista vazia."
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [
"4. O campo de versão é um texto especificando a versão do banco de dados. Isto deve ser utilizado com os bancos de dados Presto para garantir que a sintaxe esteja correta."

View File

@ -7817,15 +7817,15 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""
"3. O schemas_allowed_for_csv_upload é uma lista de esquemas separada por "
"3. O schemas_allowed_for_file_upload é uma lista de esquemas separada por "
"vírgula nos quais é permitida a carga de CSVs. Especifique como "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. Se o banco "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. Se o banco "
"de dados não suporta esquema ou a carga é permitida em qualque esquema, "
"apenas deixe a lista vazia."

View File

@ -2536,7 +2536,7 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
""
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
""
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [

View File

@ -7649,9 +7649,9 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""

View File

@ -3073,8 +3073,8 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
"2. metadata_cache_timeout je trajanje predpomnilnik v sekundah za pridobivanje metapodatkov za to podatkovno bazo. Definirajte ga kot \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. Če ni definirano, predpomnilnik ne bo omogčen pri tej funkciji. Trajanje 0 določa, da se predpomnilnik ne izteče."
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. schemas_allowed_for_csv_upload je z vejicami ločen seznam shem, ki jih je dovoljeno nalagati s CSV-ji. Definirajte ga kot \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. Če tip podatkovne baza ne podpira sheme ali pa je dovoljen dostop do vseh shem, pustite seznam prazen."
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. schemas_allowed_for_file_upload je z vejicami ločen seznam shem, ki jih je dovoljeno nalagati s CSV-ji. Definirajte ga kot \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. Če tip podatkovne baza ne podpira sheme ali pa je dovoljen dostop do vseh shem, pustite seznam prazen."
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [
"4. Polje \"version\" je znakovni niz, ki določa verzijo podatkovne baze. Uporabljeno mora biti s Presto bazo, da je sintaksa pravilna."

View File

@ -9289,15 +9289,15 @@ msgstr ""
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal/ExtraOptions.tsx:360
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr ""
"3. schemas_allowed_for_csv_upload je z vejicami ločen seznam shem, ki jih je "
"3. schemas_allowed_for_file_upload je z vejicami ločen seznam shem, ki jih je "
"dovoljeno nalagati s CSV-ji. Definirajte ga kot "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. Če tip "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. Če tip "
"podatkovne baza ne podpira sheme ali pa je dovoljen dostop do vseh shem, "
"pustite seznam prazen."

View File

@ -2299,8 +2299,8 @@
"2. The metadata_cache_timeout is a cache timeout setting in seconds for metadata fetch of this database. Specify it as \"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}. If unset, cache will not be enabled for the functionality. A timeout of 0 indicates that the cache never expires.": [
"2. metadata_cache_timeout 是获取该数据库元数据的缓存超时设置(秒)。可以这样进行设置:\"metadata_cache_timeout\": {\"schema_cache_timeout\": 600, \"table_cache_timeout\": 600}。如果未设置则不会为该功能启用缓存。如果超时时间设置为0则表示缓存永不过期。"
],
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. schemas_allowed_for_csv_upload 是CSV文件允许上传的schema该结构以逗号进行分割。 可以这样进行设置:\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]。如果数据库风格不支持schema或任何schema都被允许请将列表留空。"
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas that CSVs are allowed to upload to. Specify it as \"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If database flavor does not support schema or any schema is allowed to be accessed, just leave the list empty.": [
"3. schemas_allowed_for_file_upload 是CSV文件允许上传的schema该结构以逗号进行分割。 可以这样进行设置:\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]。如果数据库风格不支持schema或任何schema都被允许请将列表留空。"
],
"4. The version field is a string specifying this db's version. This should be used with Presto DBs so that the syntax is correct.": [
"4. version 字段是指定此数据库版本的字符串。这应该与Presto DBs一起使用以便语法正确。"

View File

@ -7464,13 +7464,13 @@ msgstr "2. metadata_cache_timeout 是获取该数据库元数据的缓存超时
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:669
msgid ""
"3. The schemas_allowed_for_csv_upload is a comma separated list of schemas "
"3. The schemas_allowed_for_file_upload is a comma separated list of schemas "
"that CSVs are allowed to upload to. Specify it as "
"\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]. If "
"\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]. If "
"database flavor does not support schema or any schema is allowed to be "
"accessed, just leave the list empty."
msgstr "3. schemas_allowed_for_csv_upload 是CSV文件允许上传的schema该结构以逗号进行分割。 "
"可以这样进行设置:\"schemas_allowed_for_csv_upload\": [\"public\", \"csv_upload\"]。"
msgstr "3. schemas_allowed_for_file_upload 是CSV文件允许上传的schema该结构以逗号进行分割。 "
"可以这样进行设置:\"schemas_allowed_for_file_upload\": [\"public\", \"csv_upload\"]。"
"如果数据库风格不支持schema或任何schema都被允许请将列表留空。"
#: superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx:678

View File

@ -164,7 +164,7 @@ DAR = DatasourceAccessRequest
logger = logging.getLogger(__name__)
DATABASE_KEYS = [
"allow_csv_upload",
"allow_file_upload",
"allow_ctas",
"allow_cvas",
"allow_dml",
@ -2875,7 +2875,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
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

View File

@ -42,53 +42,55 @@ from superset.models.core import Database
config = app.config
class CsvToDatabaseForm(DynamicForm):
class UploadToDatabaseForm(DynamicForm):
# pylint: disable=E0211
def csv_allowed_dbs() -> List[Database]: # type: ignore
csv_enabled_dbs = (
db.session.query(Database).filter_by(allow_csv_upload=True).all()
def file_allowed_dbs() -> List[Database]: # type: ignore
file_enabled_dbs = (
db.session.query(Database).filter_by(allow_file_upload=True).all()
)
return [
csv_enabled_db
for csv_enabled_db in csv_enabled_dbs
if CsvToDatabaseForm.at_least_one_schema_is_allowed(csv_enabled_db)
file_enabled_db
for file_enabled_db in file_enabled_dbs
if UploadToDatabaseForm.at_least_one_schema_is_allowed(file_enabled_db)
]
@staticmethod
def at_least_one_schema_is_allowed(database: Database) -> bool:
"""
If the user has access to the database or all datasource
1. if schemas_allowed_for_csv_upload is empty
1. if schemas_allowed_for_file_upload is empty
a) if database does not support schema
user is able to upload csv without specifying schema name
b) if database supports schema
user is able to upload csv to any schema
2. if schemas_allowed_for_csv_upload is not empty
2. if schemas_allowed_for_file_upload is not empty
a) if database does not support schema
This situation is impossible and upload will fail
b) if database supports schema
user is able to upload to schema in schemas_allowed_for_csv_upload
user is able to upload to schema in schemas_allowed_for_file_upload
elif the user does not access to the database or all datasource
1. if schemas_allowed_for_csv_upload is empty
1. if schemas_allowed_for_file_upload is empty
a) if database does not support schema
user is unable to upload csv
b) if database supports schema
user is unable to upload csv
2. if schemas_allowed_for_csv_upload is not empty
2. if schemas_allowed_for_file_upload is not empty
a) if database does not support schema
This situation is impossible and user is unable to upload csv
b) if database supports schema
user is able to upload to schema in schemas_allowed_for_csv_upload
user is able to upload to schema in schemas_allowed_for_file_upload
"""
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
):
return True
return False
class CsvToDatabaseForm(UploadToDatabaseForm):
name = StringField(
_("Table Name"),
description=_("Name of table to be created from csv data."),
@ -116,7 +118,7 @@ class CsvToDatabaseForm(DynamicForm):
)
con = QuerySelectField(
_("Database"),
query_factory=csv_allowed_dbs,
query_factory=UploadToDatabaseForm.file_allowed_dbs,
get_pk=lambda a: a.id,
get_label=lambda a: a.database_name,
)
@ -239,54 +241,7 @@ class CsvToDatabaseForm(DynamicForm):
)
class ExcelToDatabaseForm(DynamicForm):
# pylint: disable=E0211
def excel_allowed_dbs() -> List[Database]: # type: ignore
# TODO: change allow_csv_upload to allow_file_upload
excel_enabled_dbs = (
db.session.query(Database).filter_by(allow_csv_upload=True).all()
)
return [
excel_enabled_db
for excel_enabled_db in excel_enabled_dbs
if ExcelToDatabaseForm.at_least_one_schema_is_allowed(excel_enabled_db)
]
@staticmethod
def at_least_one_schema_is_allowed(database: Database) -> bool:
"""
If the user has access to the database or all datasource
1. if schemas_allowed_for_csv_upload is empty
a) if database does not support schema
user is able to upload excel without specifying schema name
b) if database supports schema
user is able to upload excel to any schema
2. if schemas_allowed_for_csv_upload is not empty
a) if database does not support schema
This situation is impossible and upload will fail
b) if database supports schema
user is able to upload to schema in schemas_allowed_for_csv_upload
elif the user does not access to the database or all datasource
1. if schemas_allowed_for_csv_upload is empty
a) if database does not support schema
user is unable to upload excel
b) if database supports schema
user is unable to upload excel
2. if schemas_allowed_for_csv_upload is not empty
a) if database does not support schema
This situation is impossible and user is unable to upload excel
b) if database supports schema
user is able to upload to schema in schemas_allowed_for_csv_upload
"""
if security_manager.can_access_database(database):
return True
schemas = database.get_schema_access_for_csv_upload()
if schemas and security_manager.schemas_accessible_by_user(
database, schemas, False
):
return True
return False
class ExcelToDatabaseForm(UploadToDatabaseForm):
name = StringField(
_("Table Name"),
description=_("Name of table to be created from excel data."),
@ -322,7 +277,7 @@ class ExcelToDatabaseForm(DynamicForm):
con = QuerySelectField(
_("Database"),
query_factory=excel_allowed_dbs,
query_factory=UploadToDatabaseForm.file_allowed_dbs,
get_pk=lambda a: a.id,
get_label=lambda a: a.database_name,
)
@ -419,56 +374,7 @@ class ExcelToDatabaseForm(DynamicForm):
)
class ColumnarToDatabaseForm(DynamicForm):
# pylint: disable=E0211
def columnar_allowed_dbs() -> List[Database]: # type: ignore
# TODO: change allow_csv_upload to allow_file_upload
columnar_enabled_dbs = (
db.session.query(Database).filter_by(allow_csv_upload=True).all()
)
return [
columnar_enabled_db
for columnar_enabled_db in columnar_enabled_dbs
if ColumnarToDatabaseForm.at_least_one_schema_is_allowed(
columnar_enabled_db
)
]
@staticmethod
def at_least_one_schema_is_allowed(database: Database) -> bool:
"""
If the user has access to the database or all datasource
1. if schemas_allowed_for_csv_upload is empty
a) if database does not support schema
user is able to upload columnar without specifying schema name
b) if database supports schema
user is able to upload columnar to any schema
2. if schemas_allowed_for_csv_upload is not empty
a) if database does not support schema
This situation is impossible and upload will fail
b) if database supports schema
user is able to upload to schema in schemas_allowed_for_csv_upload
elif the user does not access to the database or all datasource
1. if schemas_allowed_for_csv_upload is empty
a) if database does not support schema
user is unable to upload columnar
b) if database supports schema
user is unable to upload columnar
2. if schemas_allowed_for_csv_upload is not empty
a) if database does not support schema
This situation is impossible and user is unable to upload columnar
b) if database supports schema
user is able to upload to schema in schemas_allowed_for_csv_upload
"""
if security_manager.can_access_database(database):
return True
schemas = database.get_schema_access_for_csv_upload()
if schemas and security_manager.schemas_accessible_by_user(
database, schemas, False
):
return True
return False
class ColumnarToDatabaseForm(UploadToDatabaseForm):
name = StringField(
_("Table Name"),
description=_("Name of table to be created from columnar data."),
@ -499,7 +405,7 @@ class ColumnarToDatabaseForm(DynamicForm):
con = QuerySelectField(
_("Database"),
query_factory=columnar_allowed_dbs,
query_factory=UploadToDatabaseForm.file_allowed_dbs,
get_pk=lambda a: a.id,
get_label=lambda a: a.database_name,
)

View File

@ -48,7 +48,7 @@ class DatabaseMixin:
"allow_run_async",
"allow_dml",
"modified",
"allow_csv_upload",
"allow_file_upload",
"expose_in_sqllab",
]
add_columns = [
@ -57,7 +57,7 @@ class DatabaseMixin:
"cache_timeout",
"expose_in_sqllab",
"allow_run_async",
"allow_csv_upload",
"allow_file_upload",
"allow_ctas",
"allow_cvas",
"allow_dml",
@ -136,9 +136,9 @@ class DatabaseMixin:
'"table_cache_timeout": 600}**. '
"If unset, cache will not be enabled for the functionality. "
"A timeout of 0 indicates that the cache never expires.<br/>"
"3. The ``schemas_allowed_for_csv_upload`` is a comma separated list "
"3. The ``schemas_allowed_for_file_upload`` is a comma separated list "
"of schemas that CSVs are allowed to upload to. "
'Specify it as **"schemas_allowed_for_csv_upload": '
'Specify it as **"schemas_allowed_for_file_upload": '
'["public", "csv_upload"]**. '
"If database flavor does not support schema or any schema is allowed "
"to be accessed, just leave the list empty<br/>"
@ -177,7 +177,7 @@ class DatabaseMixin:
"A timeout of 0 indicates that the cache never expires. "
"Note this defaults to the global timeout if undefined."
),
"allow_csv_upload": _(
"allow_file_upload": _(
"If selected, please set the schemas allowed for csv upload in Extra."
),
}
@ -198,7 +198,7 @@ class DatabaseMixin:
"server_cert": _("Root certificate"),
"allow_run_async": _("Async Execution"),
"impersonate_user": _("Impersonate the logged on user"),
"allow_csv_upload": _("Allow Csv Upload"),
"allow_file_upload": _("Allow Csv Upload"),
"modified": _("Modified"),
"allow_multi_schema_metadata_fetch": _("Allow Multi Schema Metadata Fetch"),
"backend": _("Backend"),

View File

@ -48,10 +48,10 @@ def sqlalchemy_uri_validator(
) from ex
def schema_allows_csv_upload(database: Database, schema: Optional[str]) -> bool:
if not database.allow_csv_upload:
def schema_allows_file_upload(database: Database, schema: Optional[str]) -> bool:
if not database.allow_file_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)

View File

@ -43,7 +43,7 @@ from superset.views.base import DeleteMixin, SupersetModelView, YamlExportMixin
from .forms import ColumnarToDatabaseForm, 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
@ -132,7 +132,7 @@ class CsvToDatabaseView(SimpleFormView):
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.",
@ -279,7 +279,7 @@ class ExcelToDatabaseView(SimpleFormView):
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.",
@ -448,7 +448,7 @@ class ColumnarToDatabaseView(SimpleFormView):
"columns": form.usecols.data if form.usecols.data else None,
}
if not schema_allows_csv_upload(database, columnar_table.schema):
if not schema_allows_file_upload(database, columnar_table.schema):
message = _(
'Database "%(database_name)s" schema "%(schema_name)s" '
"is not allowed for columnar uploads. "

View File

@ -398,7 +398,7 @@ class SupersetTestCase(TestCase):
database_name = FAKE_DB_NAME
db_id = 100
extra = """{
"schemas_allowed_for_csv_upload":
"schemas_allowed_for_file_upload":
["this_schema_is_allowed", "this_schema_is_allowed_too"]
}"""

View File

@ -843,7 +843,7 @@ class TestCore(SupersetTestCase):
def enable_csv_upload(self, database: models.Database) -> None:
"""Enables csv upload in the given database."""
database.allow_csv_upload = True
database.allow_file_upload = True
db.session.commit()
add_datasource_page = self.get_resp("/databaseview/list/")
self.assertIn("Upload a CSV", add_datasource_page)

View File

@ -67,7 +67,7 @@ def setup_csv_upload():
extra = upload_db.get_extra()
extra["explore_database_id"] = utils.get_example_database().id
upload_db.extra = json.dumps(extra)
upload_db.allow_csv_upload = True
upload_db.allow_file_upload = True
db.session.commit()
yield

View File

@ -161,10 +161,10 @@ class TestDatabaseApi(SupersetTestCase):
self.assertEqual(rv.status_code, 200)
response = json.loads(rv.data.decode("utf-8"))
expected_columns = [
"allow_csv_upload",
"allow_ctas",
"allow_cvas",
"allow_dml",
"allow_file_upload",
"allow_multi_schema_metadata_fetch",
"allow_run_async",
"allows_cost_estimate",
@ -232,7 +232,7 @@ class TestDatabaseApi(SupersetTestCase):
"metadata_params": {},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": [],
"schemas_allowed_for_file_upload": [],
}
self.login(username="admin")
@ -265,7 +265,7 @@ class TestDatabaseApi(SupersetTestCase):
"metadata_params": {},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": [],
"schemas_allowed_for_file_upload": [],
}
self.login(username="admin")
@ -296,7 +296,7 @@ class TestDatabaseApi(SupersetTestCase):
"metadata_params": {},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": [],
"schemas_allowed_for_file_upload": [],
}
self.login(username="admin")
@ -386,7 +386,7 @@ class TestDatabaseApi(SupersetTestCase):
"metadata_params": {"wrong_param": "some_value"},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": [],
"schemas_allowed_for_file_upload": [],
}
self.login(username="admin")
database_data = {
@ -906,7 +906,7 @@ class TestDatabaseApi(SupersetTestCase):
"metadata_params": {},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": [],
"schemas_allowed_for_file_upload": [],
}
# need to temporarily allow sqlite dbs, teardown will undo this
app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = False

View File

@ -83,7 +83,7 @@ class TestExportDatabasesCommand(SupersetTestCase):
"engine_params": {},
"metadata_cache_timeout": {},
"metadata_params": {},
"schemas_allowed_for_csv_upload": [],
"schemas_allowed_for_file_upload": [],
}
if backend() == "presto":
expected_extra = {
@ -107,7 +107,7 @@ class TestExportDatabasesCommand(SupersetTestCase):
metadata = yaml.safe_load(contents["databases/examples.yaml"])
assert metadata == (
{
"allow_csv_upload": True,
"allow_file_upload": True,
"allow_ctas": True,
"allow_cvas": True,
"allow_run_async": False,
@ -305,7 +305,7 @@ class TestExportDatabasesCommand(SupersetTestCase):
"allow_run_async",
"allow_ctas",
"allow_cvas",
"allow_csv_upload",
"allow_file_upload",
"extra",
"uuid",
"version",
@ -325,7 +325,7 @@ class TestImportDatabasesCommand(SupersetTestCase):
database = (
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
)
assert database.allow_csv_upload
assert database.allow_file_upload
assert database.allow_ctas
assert database.allow_cvas
assert not database.allow_run_async
@ -355,11 +355,11 @@ class TestImportDatabasesCommand(SupersetTestCase):
database = (
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
)
assert database.allow_csv_upload
assert database.allow_file_upload
# update allow_csv_upload to False
# update allow_file_upload to False
new_config = database_config.copy()
new_config["allow_csv_upload"] = False
new_config["allow_file_upload"] = False
contents = {
"databases/imported_database.yaml": yaml.safe_dump(new_config),
"metadata.yaml": yaml.safe_dump(database_metadata_config),
@ -370,7 +370,7 @@ class TestImportDatabasesCommand(SupersetTestCase):
database = (
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
)
assert not database.allow_csv_upload
assert not database.allow_file_upload
# test that only one database was created
new_num_databases = db.session.query(Database).count()

View File

@ -18,5 +18,5 @@ default_db_extra = """{
"metadata_params": {},
"engine_params": {},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": []
"schemas_allowed_for_file_upload": []
}"""

View File

@ -347,7 +347,7 @@ saved_queries_metadata_config: Dict[str, Any] = {
"timestamp": "2021-03-30T20:37:54.791187+00:00",
}
database_config: Dict[str, Any] = {
"allow_csv_upload": True,
"allow_file_upload": True,
"allow_ctas": True,
"allow_cvas": True,
"allow_run_async": False,

View File

@ -133,7 +133,7 @@ class TestDatabaseModel(SupersetTestCase):
}
},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": []
"schemas_allowed_for_file_upload": []
}
"""
@ -206,7 +206,7 @@ class TestDatabaseModel(SupersetTestCase):
}
},
"metadata_cache_timeout": {},
"schemas_allowed_for_csv_upload": []
"schemas_allowed_for_file_upload": []
}
"""