Skip to content

Commit

Permalink
fix(databases): GSheets and Clickhouse DBs are not allowed to upload …
Browse files Browse the repository at this point in the history
…files (#21065)
  • Loading branch information
Antonio-RiveroMartnez authored Sep 26, 2022
1 parent 82bd5a3 commit b36bd3f
Show file tree
Hide file tree
Showing 16 changed files with 625 additions and 46 deletions.
13 changes: 13 additions & 0 deletions docs/static/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3557,6 +3557,9 @@
},
"name": {
"type": "string"
},
"engine_information": {
"type": "object"
}
},
"type": "object"
Expand Down Expand Up @@ -3738,6 +3741,9 @@
"sqlalchemy_uri": {
"maxLength": 1024,
"type": "string"
},
"engine_information": {
"readOnly": true
}
},
"required": [
Expand Down Expand Up @@ -3817,6 +3823,9 @@
"id": {
"format": "int32",
"type": "integer"
},
"engine_information": {
"readOnly": true
}
},
"required": [
Expand Down Expand Up @@ -13634,6 +13643,10 @@
"sqlalchemy_uri_placeholder": {
"description": "Example placeholder for the SQLAlchemy URI",
"type": "string"
},
"engine_information": {
"description": "Object with properties we want to expose from our DB engine",
"type": "object"
}
},
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,13 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
SupersetClient.get({
endpoint: `/api/v1/database/?q=${rison.encode(payload)}`,
}).then(({ json }: Record<string, any>) => {
setAllowUploads(json.count >= 1);
// There might be some existings Gsheets and Clickhouse DBs
// with allow_file_upload set as True which is not possible from now on
const allowedDatabasesWithFileUpload =
json?.result?.filter(
(database: any) => database?.engine_information?.supports_file_upload,
) || [];
setAllowUploads(allowedDatabasesWithFileUpload?.length >= 1);
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const ExtraOptions = ({
}) => {
const expandableModalIsOpen = !!db?.expose_in_sqllab;
const createAsOpen = !!(db?.allow_ctas || db?.allow_cvas);
const isFileUploadSupportedByEngine =
db?.engine_information?.supports_file_upload;

return (
<Collapse
Expand Down Expand Up @@ -364,28 +366,9 @@ const ExtraOptions = ({
)}
</div>
</StyledInputContainer>
<StyledInputContainer>
<div className="control-label">
{t('Schemas allowed for CSV upload')}
</div>
<div className="input-container">
<input
type="text"
name="schemas_allowed_for_file_upload"
value={(
db?.extra_json?.schemas_allowed_for_file_upload || []
).join(',')}
placeholder="schema1,schema2"
onChange={onExtraInputChange}
/>
</div>
<div className="helper">
{t(
'A comma-separated list of schemas that CSVs are allowed to upload to.',
)}
</div>
</StyledInputContainer>
<StyledInputContainer css={{ no_margin_bottom }}>
<StyledInputContainer
css={!isFileUploadSupportedByEngine ? no_margin_bottom : {}}
>
<div className="input-container">
<IndeterminateCheckbox
id="impersonate_user"
Expand All @@ -407,22 +390,44 @@ const ExtraOptions = ({
/>
</div>
</StyledInputContainer>
<StyledInputContainer css={{ ...no_margin_bottom }}>
<div className="input-container">
<IndeterminateCheckbox
id="allow_file_upload"
indeterminate={false}
checked={!!db?.allow_file_upload}
onChange={onInputChange}
labelText={t('Allow data upload')}
/>
<InfoTooltip
tooltip={t(
'If selected, please set the schemas allowed for data upload in Extra.',
{isFileUploadSupportedByEngine && (
<StyledInputContainer
css={!db?.allow_file_upload ? no_margin_bottom : {}}
>
<div className="input-container">
<IndeterminateCheckbox
id="allow_file_upload"
indeterminate={false}
checked={!!db?.allow_file_upload}
onChange={onInputChange}
labelText={t('Allow file uploads to database')}
/>
</div>
</StyledInputContainer>
)}
{isFileUploadSupportedByEngine && !!db?.allow_file_upload && (
<StyledInputContainer css={no_margin_bottom}>
<div className="control-label">
{t('Schemas allowed for File upload')}
</div>
<div className="input-container">
<input
type="text"
name="schemas_allowed_for_file_upload"
value={(
db?.extra_json?.schemas_allowed_for_file_upload || []
).join(',')}
placeholder="schema1,schema2"
onChange={onExtraInputChange}
/>
</div>
<div className="helper">
{t(
'A comma-separated list of schemas that files are allowed to upload to.',
)}
/>
</div>
</StyledInputContainer>
</div>
</StyledInputContainer>
)}
</Collapse.Panel>
<Collapse.Panel
header={
Expand Down
Loading

0 comments on commit b36bd3f

Please sign in to comment.