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

chore: log when permissions can't be mapped #167

Merged
merged 1 commit into from
Dec 13, 2022
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
5 changes: 5 additions & 0 deletions src/preset_cli/api/clients/superset.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ def export_rls(self) -> Iterator[RuleType]:
def import_role(self, role: RoleType) -> None:
"""
Import a given role.

Note: this only works with Preset workspaces for now, since it translates the
Superset permissions to the Preset permissions.
"""
user_id_map = {user["email"]: user["id"] for user in self.export_users()}
user_ids = [
Expand Down Expand Up @@ -894,6 +897,8 @@ def import_role(self, role: RoleType) -> None:

if permission in permission_id_map:
permission_ids.append(permission_id_map[permission])
else:
_logger.warning("Permission %s not found in target", permission)

data = {
"name": role["name"],
Expand Down
14 changes: 14 additions & 0 deletions tests/api/clients/superset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import json
from io import BytesIO
from unittest import mock
from urllib.parse import unquote_plus
from uuid import UUID
from zipfile import ZipFile, is_zipfile
Expand Down Expand Up @@ -1926,6 +1927,7 @@ def test_import_role(mocker: MockerFixture, requests_mock: Mocker) -> None:
"""
Test the ``import_role`` method.
"""
_logger = mocker.patch("preset_cli.api.clients.superset._logger")
requests_mock.get(
"https://superset.example.org/roles/add",
text="""
Expand Down Expand Up @@ -1966,6 +1968,18 @@ def test_import_role(mocker: MockerFixture, requests_mock: Mocker) -> None:
== "name=Admin&user=1&user=2&permissions=1&permissions=2"
)

assert _logger.warning.mock_calls == [
mock.call(
"Permission %s not found in target",
"can do something that is not in Preset",
),
mock.call("Permission %s not found in target", "Database access on Not added"),
mock.call(
"Permission %s not found in target",
"Dataset access on Not added.nope",
),
]


def test_import_rls(requests_mock: Mocker) -> None:
"""
Expand Down