Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove update_charts_owners #25843

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions superset/daos/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,6 @@ def validate_update_slug_uniqueness(dashboard_id: int, slug: str | None) -> bool
return not db.session.query(dashboard_query.exists()).scalar()
return True

@staticmethod
def update_charts_owners(model: Dashboard, commit: bool = True) -> Dashboard:
owners = list(model.owners)
for slc in model.slices:
slc.owners = list(set(owners) | set(slc.owners))
if commit:
db.session.commit()
return model

@staticmethod
def set_dash_metadata( # pylint: disable=too-many-locals
dashboard: Dashboard,
Expand Down
3 changes: 1 addition & 2 deletions superset/dashboards/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
def run(self) -> Model:
self.validate()
try:
dashboard = DashboardDAO.create(attributes=self._properties, commit=False)
dashboard = DashboardDAO.update_charts_owners(dashboard, commit=True)
dashboard = DashboardDAO.create(attributes=self._properties, commit=True)

Check warning on line 43 in superset/dashboards/commands/create.py

View check run for this annotation

Codecov / codecov/patch

superset/dashboards/commands/create.py#L43

Added line #L43 was not covered by tests
except DAOCreateFailedError as ex:
logger.exception(ex.exception)
raise DashboardCreateFailedError() from ex
Expand Down
1 change: 0 additions & 1 deletion superset/dashboards/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def run(self) -> Model:
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)
Expand Down
49 changes: 0 additions & 49 deletions tests/integration_tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,55 +1378,6 @@ def test_dashboard_get_no_username(self):
db.session.delete(model)
db.session.commit()

@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_update_dashboard_chart_owners(self):
"""
Dashboard API: Test update chart owners
"""
user_alpha1 = self.create_user(
"alpha1", "password", "Alpha", email="[email protected]"
)
user_alpha2 = self.create_user(
"alpha2", "password", "Alpha", email="[email protected]"
)
admin = self.get_user("admin")
slices = []
slices.append(
db.session.query(Slice).filter_by(slice_name="Girl Name Cloud").first()
)
slices.append(db.session.query(Slice).filter_by(slice_name="Trends").first())
slices.append(db.session.query(Slice).filter_by(slice_name="Boys").first())

dashboard = self.insert_dashboard(
"title1",
"slug1",
[admin.id],
slices=slices,
)
self.login(username="admin")
uri = f"api/v1/dashboard/{dashboard.id}"
dashboard_data = {"owners": [user_alpha1.id, user_alpha2.id]}
rv = self.client.put(uri, json=dashboard_data)
self.assertEqual(rv.status_code, 200)

# verify slices owners include alpha1 and alpha2 users
slices_ids = [slice.id for slice in slices]
# Refetch Slices
slices = db.session.query(Slice).filter(Slice.id.in_(slices_ids)).all()
for slice in slices:
self.assertIn(user_alpha1, slice.owners)
self.assertIn(user_alpha2, slice.owners)
self.assertNotIn(admin, slice.owners)
# Revert owners on slice
slice.owners = []
db.session.commit()

# Rollback changes
db.session.delete(dashboard)
db.session.delete(user_alpha1)
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):
"""
Expand Down
Loading