betodealmeida commented on a change in pull request #11751:
URL:
https://github.com/apache/incubator-superset/pull/11751#discussion_r528879357
##########
File path: superset/dashboards/api.py
##########
@@ -641,3 +644,56 @@ def favorite_status(self, **kwargs: Any) -> Response:
for request_id in requested_ids
]
return self.response(200, result=res)
+
+ @expose("/import/", methods=["POST"])
+ @protect()
+ @safe
+ @statsd_metrics
+ def import_(self) -> Response:
+ """Import dashboard(s) with associated charts/datasets/databases
+ ---
+ post:
+ requestBody:
+ content:
+ application/zip:
+ schema:
+ type: string
+ format: binary
+ responses:
+ 200:
+ description: Dashboard import result
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ message:
+ type: string
+ 400:
+ $ref: '#/components/responses/400'
+ 401:
+ $ref: '#/components/responses/401'
+ 422:
+ $ref: '#/components/responses/422'
+ 500:
+ $ref: '#/components/responses/500'
+ """
+ upload = request.files.get("file")
+ if not upload:
+ return self.response_400()
+ with ZipFile(upload) as bundle:
+ contents = {
+ file_name: bundle.read(file_name).decode()
+ for file_name in bundle.namelist()
+ }
+
+ command = ImportDashboardsCommand(contents)
+ try:
+ command.run()
+ return self.response(200, message="OK")
+ except CommandInvalidError as exc:
+ logger.warning("Import dashboard failed")
+ return self.response_422(message=exc.normalized_messages())
+ except Exception as exc: # pylint: disable=broad-except
Review comment:
Will do!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]