This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 684b8888b1 fix(dashboard): Stop updating chart owners for charts
removed from dashboard (#21720)
684b8888b1 is described below
commit 684b8888b1f60b5e9d440cdd07ecc6c116fcd542
Author: Cody Leff <[email protected]>
AuthorDate: Thu Feb 9 09:50:06 2023 -0800
fix(dashboard): Stop updating chart owners for charts removed from
dashboard (#21720)
Co-authored-by: Michael S. Molina <[email protected]>
---
superset/dashboards/commands/update.py | 2 +-
tests/integration_tests/dashboards/api_tests.py | 59 +++++++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/superset/dashboards/commands/update.py
b/superset/dashboards/commands/update.py
index 8b6704b049..12ac241dcc 100644
--- a/superset/dashboards/commands/update.py
+++ b/superset/dashboards/commands/update.py
@@ -50,13 +50,13 @@ class UpdateDashboardCommand(UpdateMixin, BaseCommand):
self.validate()
try:
dashboard = DashboardDAO.update(self._model, self._properties,
commit=False)
- dashboard = DashboardDAO.update_charts_owners(dashboard,
commit=False)
if self._properties.get("json_metadata"):
dashboard = DashboardDAO.set_dash_metadata(
dashboard,
data=json.loads(self._properties.get("json_metadata",
"{}")),
commit=False,
)
+ dashboard = DashboardDAO.update_charts_owners(dashboard,
commit=False)
db.session.commit()
except DAOUpdateFailedError as ex:
logger.exception(ex.exception)
diff --git a/tests/integration_tests/dashboards/api_tests.py
b/tests/integration_tests/dashboards/api_tests.py
index 995e8784ff..725811ce5f 100644
--- a/tests/integration_tests/dashboards/api_tests.py
+++ b/tests/integration_tests/dashboards/api_tests.py
@@ -1347,6 +1347,65 @@ class TestDashboardApi(SupersetTestCase,
ApiOwnersTestCaseMixin, InsertChartMixi
db.session.delete(user_alpha2)
db.session.commit()
+ @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
+ def test_update_dashboard_chart_owners_propagation(self):
+ """
+ Dashboard API: Test update chart owners propagation
+ """
+ user_alpha1 = self.create_user(
+ "alpha1",
+ "password",
+ "Alpha",
+ email="[email protected]",
+ first_name="alpha1",
+ )
+ admin = self.get_user("admin")
+ slices = []
+
slices.append(db.session.query(Slice).filter_by(slice_name="Trends").one())
+
slices.append(db.session.query(Slice).filter_by(slice_name="Boys").one())
+
+ # Insert dashboard with admin as owner
+ dashboard = self.insert_dashboard(
+ "title1",
+ "slug1",
+ [admin.id],
+ slices=slices,
+ )
+
+ # Updates dashboard without Boys in json_metadata positions
+ # and user_alpha1 as owner
+ dashboard_data = {
+ "owners": [user_alpha1.id],
+ "json_metadata": json.dumps(
+ {
+ "positions": {
+ f"{slices[0].id}": {
+ "type": "CHART",
+ "meta": {"chartId": slices[0].id},
+ },
+ }
+ }
+ ),
+ }
+ self.login(username="admin")
+ uri = f"api/v1/dashboard/{dashboard.id}"
+ rv = self.client.put(uri, json=dashboard_data)
+ self.assertEqual(rv.status_code, 200)
+
+ # Check that chart named Boys does not contain alpha 1 in its owners
+ boys = db.session.query(Slice).filter_by(slice_name="Boys").one()
+ self.assertNotIn(user_alpha1, boys.owners)
+
+ # Revert owners on slice
+ for slice in slices:
+ slice.owners = []
+ db.session.commit()
+
+ # Rollback changes
+ db.session.delete(dashboard)
+ db.session.delete(user_alpha1)
+ db.session.commit()
+
def test_update_partial_dashboard(self):
"""
Dashboard API: Test update partial