Skip to content

Commit

Permalink
NAS-5251: cleaned up Catalog classes for dashboard permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechtoman committed Oct 25, 2023
1 parent 6ab0099 commit 247e1dd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 33 deletions.
5 changes: 3 additions & 2 deletions gooddata-sdk/gooddata_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@
)
from gooddata_sdk.catalog.permission.declarative_model.manage_dashboard_permissions import (
CatalogDashboardAssigneeIdentifier,
CatalogPermissionsAssignment,
CatalogPermissionsForAssignee,
CatalogPermissionsForAssigneeRule,
)
from gooddata_sdk.catalog.permission.declarative_model.permission import (
CatalogDeclarativeDashboardPermissionsAssignment,
CatalogDeclarativeDashboardPermissionsForAssignee,
CatalogDeclarativeDashboardPermissionsForAssigneeRule,
CatalogDeclarativeDataSourcePermission,
CatalogDeclarativeSingleWorkspacePermission,
CatalogDeclarativeWorkspaceHierarchyPermission,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# (C) 2023 GoodData Corporation
from typing import List, Optional, Type
from typing import List, Type

import attr

Expand All @@ -9,28 +9,26 @@
from gooddata_sdk.catalog.rule import CatalogAssigneeRule


# Kept for backward compatibility only
@attr.s(auto_attribs=True, kw_only=True)
class CatalogDashboardAssigneeIdentifier(CatalogAssigneeIdentifier):
pass


@attr.s(auto_attribs=True, kw_only=True)
class CatalogPermissionsAssignment(Base):
class CatalogPermissionsForAssignee(Base):
permissions: List[str] = attr.field(factory=list)
assignee_identifier: Optional[CatalogAssigneeIdentifier] = None
assignee_rule: Optional[CatalogAssigneeRule] = None
assignee_identifier: CatalogAssigneeIdentifier

@staticmethod
def client_class() -> Type[ManageDashboardPermissionsRequestInner]:
return ManageDashboardPermissionsRequestInner


# Kept for backward compatibility only
@attr.s(auto_attribs=True, kw_only=True)
class CatalogDashboardAssigneeIdentifier(CatalogAssigneeIdentifier):
pass


# Kept for backward compatibility only
@attr.s(auto_attribs=True, kw_only=True)
class CatalogPermissionsForAssignee(Base):
class CatalogPermissionsForAssigneeRule(Base):
permissions: List[str] = attr.field(factory=list)
assignee_identifier: CatalogDashboardAssigneeIdentifier
assignee_rule: CatalogAssigneeRule

@staticmethod
def client_class() -> Type[ManageDashboardPermissionsRequestInner]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# (C) 2022 GoodData Corporation
from __future__ import annotations

from typing import List, Optional, Type
from typing import List, Type

import attr

from gooddata_api_client.model.declarative_analytical_dashboard_permissions_inner import (
DeclarativeAnalyticalDashboardPermissionsInner,
from gooddata_api_client.model.declarative_analytical_dashboard_permission_for_assignee import (
DeclarativeAnalyticalDashboardPermissionForAssignee,
)
from gooddata_api_client.model.declarative_analytical_dashboard_permission_for_assignee_rule import (
DeclarativeAnalyticalDashboardPermissionForAssigneeRule,
)
from gooddata_api_client.model.declarative_data_source_permission import DeclarativeDataSourcePermission
from gooddata_api_client.model.declarative_single_workspace_permission import DeclarativeSingleWorkspacePermission
Expand Down Expand Up @@ -58,11 +61,20 @@ def client_class() -> Type[DeclarativeWorkspacePermissions]:


@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeDashboardPermissionsAssignment(Base):
class CatalogDeclarativeDashboardPermissionsForAssignee(Base):
name: str = attr.field(validator=value_in_allowed)
assignee_identifier: CatalogAssigneeIdentifier

@staticmethod
def client_class() -> Type[DeclarativeAnalyticalDashboardPermissionForAssignee]:
return DeclarativeAnalyticalDashboardPermissionForAssignee


@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeDashboardPermissionsForAssigneeRule(Base):
name: str = attr.field(validator=value_in_allowed)
assignee_identifier: Optional[CatalogAssigneeIdentifier] = None
assignee_rule: Optional[CatalogAssigneeRule] = None
assignee_rule: CatalogAssigneeRule

@staticmethod
def client_class() -> Type[DeclarativeAnalyticalDashboardPermissionsInner]:
return DeclarativeAnalyticalDashboardPermissionsInner
def client_class() -> Type[DeclarativeAnalyticalDashboardPermissionForAssigneeRule]:
return DeclarativeAnalyticalDashboardPermissionForAssigneeRule
8 changes: 6 additions & 2 deletions gooddata-sdk/gooddata_sdk/catalog/permission/service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# (C) 2022 GoodData Corporation
from typing import List
from typing import List, Union

from gooddata_sdk import (
CatalogAvailableAssignees,
CatalogDashboardPermissions,
CatalogDeclarativeWorkspacePermissions,
CatalogPermissionsForAssignee,
CatalogPermissionsForAssigneeRule,
GoodDataApiClient,
)
from gooddata_sdk.catalog.catalog_service_base import CatalogServiceBase
Expand Down Expand Up @@ -81,7 +82,10 @@ def list_dashboard_permissions(self, workspace_id: str, dashboard_id: str) -> Ca
)

def manage_dashboard_permissions(
self, workspace_id: str, dashboard_id: str, permissions_for_assignee: List[CatalogPermissionsForAssignee]
self,
workspace_id: str,
dashboard_id: str,
permissions_for_assignee: List[Union[CatalogPermissionsForAssignee, CatalogPermissionsForAssigneeRule]],
) -> None:
"""Provide managing dashboard permissions for user and user groups.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, Dict, List, Optional, Type, TypeVar, Union

import attr
from cattrs import global_converter, structure

from gooddata_api_client.model.declarative_analytical_dashboard import DeclarativeAnalyticalDashboard
from gooddata_api_client.model.declarative_analytical_dashboard_extension import DeclarativeAnalyticalDashboardExtension
Expand All @@ -14,7 +15,10 @@
from gooddata_api_client.model.declarative_filter_context import DeclarativeFilterContext
from gooddata_api_client.model.declarative_metric import DeclarativeMetric
from gooddata_api_client.model.declarative_visualization_object import DeclarativeVisualizationObject
from gooddata_sdk import CatalogDeclarativeDashboardPermissionsAssignment
from gooddata_sdk import (
CatalogDeclarativeDashboardPermissionsForAssignee,
CatalogDeclarativeDashboardPermissionsForAssigneeRule,
)
from gooddata_sdk.catalog.base import Base
from gooddata_sdk.catalog.identifier import CatalogUserIdentifier
from gooddata_sdk.utils import create_directory, get_sorted_yaml_files, read_layout_from_file, write_layout_to_file
Expand Down Expand Up @@ -218,12 +222,35 @@ class CatalogAnalyticsBaseMeta(CatalogAnalyticsBase):

@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeAnalyticalDashboard(CatalogAnalyticsBaseMeta):
permissions: Optional[List[CatalogDeclarativeDashboardPermissionsAssignment]] = None
permissions: Optional[
List[
Union[
CatalogDeclarativeDashboardPermissionsForAssignee, CatalogDeclarativeDashboardPermissionsForAssigneeRule
]
]
] = None

@staticmethod
def client_class() -> Type[DeclarativeAnalyticalDashboard]:
return DeclarativeAnalyticalDashboard

@staticmethod
def structure_permissions(
v: Dict[str, Any], _: Any
) -> Union[
CatalogDeclarativeDashboardPermissionsForAssignee, CatalogDeclarativeDashboardPermissionsForAssigneeRule
]:
if v.get("assignee_identifier") is not None:
return structure(v, CatalogDeclarativeDashboardPermissionsForAssignee)
else:
return structure(v, CatalogDeclarativeDashboardPermissionsForAssigneeRule)


global_converter.register_structure_hook(
Union[CatalogDeclarativeDashboardPermissionsForAssignee, CatalogDeclarativeDashboardPermissionsForAssigneeRule],
CatalogDeclarativeAnalyticalDashboard.structure_permissions,
)


@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeDashboardPlugin(CatalogAnalyticsBaseMeta):
Expand All @@ -234,7 +261,9 @@ def client_class() -> Type[DeclarativeDashboardPlugin]:

@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeAnalyticalDashboardExtension(CatalogAnalyticsObjectBase):
permissions: List[CatalogDeclarativeDashboardPermissionsAssignment]
permissions: List[
Union[CatalogDeclarativeDashboardPermissionsForAssignee, CatalogDeclarativeDashboardPermissionsForAssigneeRule]
]

@staticmethod
def client_class() -> Type[DeclarativeAnalyticalDashboardExtension]:
Expand Down
9 changes: 4 additions & 5 deletions gooddata-sdk/tests/catalog/test_catalog_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
CatalogDeclarativeSingleWorkspacePermission,
CatalogDeclarativeWorkspaceHierarchyPermission,
CatalogDeclarativeWorkspacePermissions,
CatalogPermissionsAssignment,
CatalogPermissionsForAssignee,
CatalogPermissionsForAssigneeRule,
GoodDataApiClient,
GoodDataSdk,
)
Expand Down Expand Up @@ -129,11 +129,11 @@ def test_list_dashboard_permissions(test_config):
"demo",
"campaign",
[
CatalogPermissionsAssignment(
CatalogPermissionsForAssignee(
assignee_identifier=CatalogAssigneeIdentifier(id="visitorsGroup", type="userGroup"),
permissions=["VIEW"],
),
CatalogPermissionsAssignment(
CatalogPermissionsForAssigneeRule(
assignee_rule=CatalogAssigneeRule(type="allWorkspaceUsers"),
permissions=["VIEW"],
),
Expand All @@ -149,12 +149,11 @@ def test_list_dashboard_permissions(test_config):
"demo",
"campaign",
[
# CatalogPermissionsForAssignee used to test backward compatibility
CatalogPermissionsForAssignee(
assignee_identifier=CatalogDashboardAssigneeIdentifier(id="visitorsGroup", type="userGroup"),
permissions=[],
),
CatalogPermissionsAssignment(
CatalogPermissionsForAssigneeRule(
assignee_rule=CatalogAssigneeRule(type="allWorkspaceUsers"),
permissions=[],
),
Expand Down

0 comments on commit 247e1dd

Please sign in to comment.