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

TRIVIAL: fix workspace setting #393

Merged
1 commit merged into from
Oct 23, 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
3 changes: 2 additions & 1 deletion gooddata-sdk/gooddata_sdk/catalog/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

from gooddata_api_client.model.declarative_custom_application_setting import DeclarativeCustomApplicationSetting
from gooddata_api_client.model.declarative_setting import DeclarativeSetting
from gooddata_sdk.catalog.base import Base
from gooddata_sdk.catalog.base import Base, value_in_allowed


@attr.s(auto_attribs=True, kw_only=True)
class CatalogDeclarativeSetting(Base):
id: str
type: str = attr.field(validator=value_in_allowed)
content: Optional[Dict[str, Any]] = None

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# (C) 2023 GoodData Corporation
from __future__ import annotations

from typing import Type, Union
import functools
from typing import Any, Dict, Type, Union

import attr

Expand All @@ -13,26 +14,29 @@
from gooddata_api_client.model.json_api_workspace_setting_post_optional_id_document import (
JsonApiWorkspaceSettingPostOptionalIdDocument,
)
from gooddata_sdk.catalog.entity import AttrCatalogEntity
from gooddata_sdk.catalog.base import Base, value_in_allowed
from gooddata_sdk.utils import safeget


@attr.s(auto_attribs=True, kw_only=True)
class CatalogWorkspaceSetting(AttrCatalogEntity):
class CatalogWorkspaceSetting(Base):
id: str = attr.field(default=None)

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

setting_type: str = attr.field(
validator=functools.partial(value_in_allowed, client_class=JsonApiOrganizationSettingInAttributes)
)
content: dict = attr.field(
repr=False,
default=attr.Factory(lambda self: safeget(self.json_api_entity.attributes, ["content"]), takes_self=True),
)

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

def _attributes(self) -> JsonApiOrganizationSettingInAttributes:
return JsonApiOrganizationSettingInAttributes(
content=self.content,
type=self.setting_type,
)

def to_api(
Expand All @@ -50,3 +54,11 @@ def to_api(
return JsonApiWorkspaceSettingInDocument(
data=JsonApiWorkspaceSettingIn(id=self.id, attributes=self._attributes())
)

@classmethod
def from_api(cls, entity: Dict[str, Any]) -> CatalogWorkspaceSetting:
return cls(
id=entity["id"],
setting_type=entity["attributes"]["type"],
content=entity["attributes"]["content"],
)
5 changes: 3 additions & 2 deletions gooddata-sdk/gooddata_sdk/catalog/workspace/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,11 @@ def provision_workspace_with_locales(
self.delete_workspace_setting(new_workspace.id, "formatLocale")
# Create/update locale settings to target language
self.create_or_update_workspace_setting(
new_workspace.id, CatalogWorkspaceSetting(id="locale", content={"value": to_locale})
new_workspace.id, CatalogWorkspaceSetting(id="locale", content={"value": to_locale}, setting_type="LOCALE")
)
self.create_or_update_workspace_setting(
new_workspace.id, CatalogWorkspaceSetting(id="formatLocale", content={"value": to_locale})
new_workspace.id,
CatalogWorkspaceSetting(id="formatLocale", content={"value": to_locale}, setting_type="FORMAT_LOCALE"),
)

def translate_if_requested(
Expand Down
Loading