Skip to content

Commit

Permalink
fix(superset): Fixed API for bulk delete of embedded dashboards (#21911)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhashubham95 authored Oct 22, 2022
1 parent 3da9687 commit 7edf1fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions superset/dashboards/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions tests/integration_tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7edf1fb

Please sign in to comment.