Skip to content
Open
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
2 changes: 1 addition & 1 deletion superset/commands/dashboard/importers/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def import_dashboard( # noqa: C901
if dashboard.id is None:
db.session.flush()

if (user := get_user()) and user not in dashboard.owners:
if not existing and (user := get_user()) and user not in dashboard.owners:
dashboard.owners.append(user)

return dashboard
49 changes: 49 additions & 0 deletions tests/unit_tests/dashboards/commands/importers/v1/import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,55 @@ def test_import_existing_dashboard_with_permission(
mock_can_access_dashboard.assert_called_once_with(dashboard)


def test_import_existing_dashboard_does_not_add_importer_as_owner(
mocker: MockerFixture,
session_with_data: Session,
) -> None:
"""
Importing an existing dashboard must NOT add the importer as an owner.
Regression test for GitHub issue #36244.
"""
mocker.patch.object(security_manager, "can_access", return_value=True)
mocker.patch.object(security_manager, "can_access_dashboard", return_value=True)
mocker.patch.object(security_manager, "is_admin", return_value=True)

admin = User(
first_name="Alice",
last_name="Doe",
email="adoe@example.org",
username="admin",
roles=[Role(name="Admin")],
)

with override_user(admin):
result = import_dashboard(dashboard_config, overwrite=True)

assert admin not in result.owners


def test_import_new_dashboard_adds_importer_as_owner(
mocker: MockerFixture,
session_with_schema: Session,
) -> None:
"""
Importing a new dashboard (UUID not in DB) should add the importer as owner.
"""
mocker.patch.object(security_manager, "can_access", return_value=True)

user = User(
first_name="Bob",
last_name="Smith",
email="bsmith@example.org",
username="bob",
roles=[Role(name="Gamma")],
)

with override_user(user):
result = import_dashboard(dashboard_config)

assert user in result.owners


def test_import_tag_logic_for_dashboards(session_with_schema: Session):
contents = {
"tags.yaml": yaml.dump(
Expand Down
Loading