You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/01/16 23:55:42 UTC

[GitHub] [incubator-superset] mistercrunch commented on a change in pull request #8972: [dashboards] New, API for Bulk delete

mistercrunch commented on a change in pull request #8972: [dashboards] New, API for Bulk delete
URL: https://github.com/apache/incubator-superset/pull/8972#discussion_r367709402
 
 

 ##########
 File path: superset/views/dashboard/api.py
 ##########
 @@ -320,6 +326,88 @@ def post(self):
         except SQLAlchemyError as e:
             return self.response_422(message=str(e))
 
+    @expose("/", methods=["DELETE"])
+    @protect()
+    @safe
+    @rison(get_delete_ids_schema)
+    def multiple_delete(self, **kwargs):  # pylint: disable=arguments-differ
+        """Delete multiple Dashboards
+        ---
+        delete:
+          parameters:
+          - in: query
+            name: q
+            content:
+              application/json:
+                schema:
+                  type: array
+                  items:
+                    type: integer
+          responses:
+            200:
+              description: Dashboard multiple delete
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      message:
+                        type: string
+                      count:
+                        description: Number of deleted dashboards
+                        type: integer
+            401:
+              $ref: '#/components/responses/401'
+            403:
+              description: Dashboard multiple delete
+              content:
+                application/json:
+                  schema:
+                    type: object
+                    properties:
+                      message:
+                        type: string
+                      count:
+                        description: Number of deleted dashboards
+                        type: integer
+            404:
+              $ref: '#/components/responses/404'
+            422:
+              $ref: '#/components/responses/422'
+            500:
+              $ref: '#/components/responses/500'
+        """
+        query = self.datamodel.session.query(Dashboard).filter(
+            Dashboard.id.in_(kwargs["rison"])
+        )
+        items = self._base_filters.apply_all(query).all()
+        if not items:
+            return self.response_404()
+        delete_count = 0
+        status_code = 200
+        for item in items:
+            try:
+                check_ownership(item)
+                self.datamodel.delete(item, raise_exception=True)
+                delete_count += 1
+            except SupersetSecurityException as e:
+                logger.warning(
+                    f"Dashboard {item} was not deleted, "
+                    f"because the user ({g.user}) does not own it"
+                )
+                status_code = 403
+            except SQLAlchemyError as e:
+                return self.response_422(message=str(e))
+        if len(items) != delete_count and delete_count > 0:
+            return self.response(
+                status_code, message="Some dashboards deleted", count=delete_count
 
 Review comment:
   Also i18n

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org