mirror of
https://github.com/apache/superset.git
synced 2026-05-12 03:15:55 +00:00
feat(dao): admin can remove self from object owners (#15149)
(cherry picked from commit d6f9c48aa1)
This commit is contained in:
committed by
Steven Uray
parent
af1a63b672
commit
f0fb37fda9
@@ -1110,7 +1110,7 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
|
||||
for slice in slices:
|
||||
self.assertIn(user_alpha1, slice.owners)
|
||||
self.assertIn(user_alpha2, slice.owners)
|
||||
self.assertIn(admin, slice.owners)
|
||||
self.assertNotIn(admin, slice.owners)
|
||||
# Revert owners on slice
|
||||
slice.owners = []
|
||||
db.session.commit()
|
||||
@@ -1150,22 +1150,45 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
|
||||
db.session.delete(model)
|
||||
db.session.commit()
|
||||
|
||||
def test_update_dashboard_new_owner(self):
|
||||
def test_update_dashboard_new_owner_not_admin(self):
|
||||
"""
|
||||
Dashboard API: Test update set new owner to current user
|
||||
Dashboard API: Test update set new owner implicitly adds logged in owner
|
||||
"""
|
||||
gamma_id = self.get_user("gamma").id
|
||||
gamma = self.get_user("gamma")
|
||||
alpha = self.get_user("alpha")
|
||||
dashboard_id = self.insert_dashboard("title1", "slug1", [alpha.id]).id
|
||||
dashboard_data = {"dashboard_title": "title1_changed", "owners": [gamma.id]}
|
||||
self.login(username="alpha")
|
||||
uri = f"api/v1/dashboard/{dashboard_id}"
|
||||
rv = self.client.put(uri, json=dashboard_data)
|
||||
self.assertEqual(rv.status_code, 200)
|
||||
model = db.session.query(Dashboard).get(dashboard_id)
|
||||
self.assertIn(gamma, model.owners)
|
||||
self.assertIn(alpha, model.owners)
|
||||
for slc in model.slices:
|
||||
self.assertIn(gamma, slc.owners)
|
||||
self.assertIn(alpha, slc.owners)
|
||||
db.session.delete(model)
|
||||
db.session.commit()
|
||||
|
||||
def test_update_dashboard_new_owner_admin(self):
|
||||
"""
|
||||
Dashboard API: Test update set new owner as admin to other than current user
|
||||
"""
|
||||
gamma = self.get_user("gamma")
|
||||
admin = self.get_user("admin")
|
||||
dashboard_id = self.insert_dashboard("title1", "slug1", [gamma_id]).id
|
||||
dashboard_data = {"dashboard_title": "title1_changed"}
|
||||
dashboard_id = self.insert_dashboard("title1", "slug1", [admin.id]).id
|
||||
dashboard_data = {"dashboard_title": "title1_changed", "owners": [gamma.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)
|
||||
model = db.session.query(Dashboard).get(dashboard_id)
|
||||
self.assertIn(admin, model.owners)
|
||||
self.assertIn(gamma, model.owners)
|
||||
self.assertNotIn(admin, model.owners)
|
||||
for slc in model.slices:
|
||||
self.assertIn(admin, slc.owners)
|
||||
self.assertIn(gamma, slc.owners)
|
||||
self.assertNotIn(admin, slc.owners)
|
||||
db.session.delete(model)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user