diff --git a/superset/dashboards/dao.py b/superset/dashboards/dao.py index 36db7e341a114..9f3d5178d7bb6 100644 --- a/superset/dashboards/dao.py +++ b/superset/dashboards/dao.py @@ -160,6 +160,7 @@ def bulk_delete(models: Optional[List[Dashboard]], commit: bool = True) -> None: for model in models: model.slices = [] model.owners = [] + model.embedded = [] db.session.merge(model) # bulk delete itself try: diff --git a/tests/integration_tests/dashboards/api_tests.py b/tests/integration_tests/dashboards/api_tests.py index 363ba9232051b..35f59f363923c 100644 --- a/tests/integration_tests/dashboards/api_tests.py +++ b/tests/integration_tests/dashboards/api_tests.py @@ -803,6 +803,46 @@ def test_delete_bulk_dashboards(self): model = db.session.query(Dashboard).get(dashboard_id) self.assertEqual(model, None) + def test_delete_bulk_embedded_dashboards(self): + """ + Dashboard API: Test delete bulk embedded + """ + user = self.get_user("admin") + dashboard_count = 4 + dashboard_ids = list() + for dashboard_name_index in range(dashboard_count): + dashboard_ids.append( + self.insert_dashboard( + f"title{dashboard_name_index}", + None, + [user.id], + ).id + ) + self.login(username=user.username) + for dashboard_id in dashboard_ids: + # post succeeds and returns value + allowed_domains = ["test.example", "embedded.example"] + resp = self.post_assert_metric( + f"api/v1/dashboard/{dashboard_id}/embedded", + {"allowed_domains": allowed_domains}, + "set_embedded", + ) + self.assertEqual(resp.status_code, 200) + result = json.loads(resp.data.decode("utf-8"))["result"] + self.assertIsNotNone(result["uuid"]) + self.assertNotEqual(result["uuid"], "") + self.assertEqual(result["allowed_domains"], allowed_domains) + argument = dashboard_ids + uri = f"api/v1/dashboard/?q={prison.dumps(argument)}" + rv = self.delete_assert_metric(uri, "bulk_delete") + self.assertEqual(rv.status_code, 200) + response = json.loads(rv.data.decode("utf-8")) + expected_response = {"message": f"Deleted {dashboard_count} dashboards"} + self.assertEqual(response, expected_response) + for dashboard_id in dashboard_ids: + model = db.session.query(Dashboard).get(dashboard_id) + self.assertEqual(model, None) + def test_delete_bulk_dashboards_bad_request(self): """ Dashboard API: Test delete bulk bad request