From a1fe6c6d3420da031c564191d94555930a18d992 Mon Sep 17 00:00:00 2001 From: seolmin Date: Tue, 5 Mar 2024 10:12:34 +0900 Subject: [PATCH] feat: add display_info variable in dashboard object --- .../dashboard/info/private_dashboard_info.py | 1 + .../dashboard/info/public_dashboard_info.py | 1 + .../manager/private_dashboard_manager.py | 6 ------ .../manager/public_dashboard_manager.py | 6 ------ .../dashboard/model/private_dashboard_model.py | 3 +++ .../dashboard/model/public_dashboard_model.py | 3 +++ .../service/private_dashboard_service.py | 17 +++++++++++------ .../service/public_dashboard_service.py | 17 +++++++++++------ 8 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/spaceone/dashboard/info/private_dashboard_info.py b/src/spaceone/dashboard/info/private_dashboard_info.py index a5a5fce..fcfa92f 100644 --- a/src/spaceone/dashboard/info/private_dashboard_info.py +++ b/src/spaceone/dashboard/info/private_dashboard_info.py @@ -12,6 +12,7 @@ def PrivateDashboardInfo(dashboard_vo: PrivateDashboard, minimal=False): "private_dashboard_id": dashboard_vo.private_dashboard_id, "name": dashboard_vo.name, "version": dashboard_vo.version, + "display_info": change_struct_type(dashboard_vo.display_info), "labels": change_list_value_type(dashboard_vo.labels), "user_id": dashboard_vo.user_id, "workspace_id": dashboard_vo.workspace_id, diff --git a/src/spaceone/dashboard/info/public_dashboard_info.py b/src/spaceone/dashboard/info/public_dashboard_info.py index b9f5d50..0ad5f07 100644 --- a/src/spaceone/dashboard/info/public_dashboard_info.py +++ b/src/spaceone/dashboard/info/public_dashboard_info.py @@ -12,6 +12,7 @@ def PublicDashboardInfo(dashboard_vo: PublicDashboard, minimal=False): "public_dashboard_id": dashboard_vo.public_dashboard_id, "name": dashboard_vo.name, "version": dashboard_vo.version, + "display_info": change_struct_type(dashboard_vo.display_info), "labels": change_list_value_type(dashboard_vo.labels), "resource_group": dashboard_vo.resource_group, "project_id": dashboard_vo.project_id, diff --git a/src/spaceone/dashboard/manager/private_dashboard_manager.py b/src/spaceone/dashboard/manager/private_dashboard_manager.py index 24836e5..c17f3bd 100644 --- a/src/spaceone/dashboard/manager/private_dashboard_manager.py +++ b/src/spaceone/dashboard/manager/private_dashboard_manager.py @@ -26,12 +26,6 @@ def _rollback(vo: PrivateDashboard) -> None: return dashboard_vo - def update_private_dashboard(self, params: dict) -> PrivateDashboard: - dashboard_vo: PrivateDashboard = self.get_private_dashboard( - params["private_dashboard_id"], params["workspace_id"], params["domain_id"] - ) - return self.update_private_dashboard_by_vo(params, dashboard_vo) - def update_private_dashboard_by_vo( self, params: dict, dashboard_vo: PrivateDashboard ) -> PrivateDashboard: diff --git a/src/spaceone/dashboard/manager/public_dashboard_manager.py b/src/spaceone/dashboard/manager/public_dashboard_manager.py index b215168..3e335e8 100644 --- a/src/spaceone/dashboard/manager/public_dashboard_manager.py +++ b/src/spaceone/dashboard/manager/public_dashboard_manager.py @@ -26,12 +26,6 @@ def _rollback(vo: PublicDashboard) -> None: return dashboard_vo - def update_public_dashboard(self, params: dict) -> PublicDashboard: - dashboard_vo: PublicDashboard = self.get_public_dashboard( - params["public_dashboard_id"], params["domain_id"] - ) - return self.update_public_dashboard_by_vo(params, dashboard_vo) - def update_public_dashboard_by_vo( self, params: dict, dashboard_vo: PublicDashboard ) -> PublicDashboard: diff --git a/src/spaceone/dashboard/model/private_dashboard_model.py b/src/spaceone/dashboard/model/private_dashboard_model.py index f7f86d1..7ed56b8 100644 --- a/src/spaceone/dashboard/model/private_dashboard_model.py +++ b/src/spaceone/dashboard/model/private_dashboard_model.py @@ -14,6 +14,7 @@ class PrivateDashboard(MongoModel): variables = DictField(default={}) settings = DictField(default={}) variables_schema = DictField(default={}) + display_info = DictField(default={}) labels = ListField(StringField()) tags = DictField(default={}) user_id = StringField(max_length=40) @@ -29,6 +30,7 @@ class PrivateDashboard(MongoModel): "variables", "settings", "variables_schema", + "display_info", "labels", "tags", ], @@ -36,6 +38,7 @@ class PrivateDashboard(MongoModel): "private_dashboard_id", "name", "version", + "display_info", "user_id", "workspace_id", "domain_id", diff --git a/src/spaceone/dashboard/model/public_dashboard_model.py b/src/spaceone/dashboard/model/public_dashboard_model.py index 8c7c5b5..5a32f3f 100644 --- a/src/spaceone/dashboard/model/public_dashboard_model.py +++ b/src/spaceone/dashboard/model/public_dashboard_model.py @@ -14,6 +14,7 @@ class PublicDashboard(MongoModel): variables = DictField(default={}) settings = DictField(default={}) variables_schema = DictField(default={}) + display_info = DictField(default={}) labels = ListField(StringField()) tags = DictField(default={}) resource_group = StringField( @@ -32,6 +33,7 @@ class PublicDashboard(MongoModel): "variables", "settings", "variables_schema", + "display_info", "labels", "tags", ], @@ -39,6 +41,7 @@ class PublicDashboard(MongoModel): "public_dashboard_id", "name", "version", + "display_info", "resource_group", "project_id", "workspace_id", diff --git a/src/spaceone/dashboard/service/private_dashboard_service.py b/src/spaceone/dashboard/service/private_dashboard_service.py index 5078c0e..b759bdc 100644 --- a/src/spaceone/dashboard/service/private_dashboard_service.py +++ b/src/spaceone/dashboard/service/private_dashboard_service.py @@ -105,10 +105,15 @@ def update(self, params): params["name"] = dashboard_vo.name if "settings" in params: - params["settings"] = self._merge_settings( + params["settings"] = self._merge_dict( dashboard_vo.settings, params["settings"] ) + if "display_info" in params: + params["display_info"] = self._merge_dict( + dashboard_vo.display_info, params["display_info"] + ) + version_change_keys = ["layouts", "variables", "variables_schema"] if self._has_version_key_in_params(dashboard_vo, params, version_change_keys): self.dashboard_mgr.increase_version(dashboard_vo) @@ -402,11 +407,11 @@ def _has_version_key_in_params( return False @staticmethod - def _merge_settings(old_settings: dict, new_settings: dict) -> dict: - settings = copy.deepcopy(old_settings) + def _merge_dict(old_dict: dict, new_dict: dict) -> dict: + settings = copy.deepcopy(old_dict) - if old_settings: - settings.update(new_settings) + if old_dict: + settings.update(new_dict) return settings else: - return new_settings + return new_dict diff --git a/src/spaceone/dashboard/service/public_dashboard_service.py b/src/spaceone/dashboard/service/public_dashboard_service.py index d5e4f63..cb97f03 100644 --- a/src/spaceone/dashboard/service/public_dashboard_service.py +++ b/src/spaceone/dashboard/service/public_dashboard_service.py @@ -123,10 +123,15 @@ def update(self, params): params["name"] = dashboard_vo.name if "settings" in params: - params["settings"] = self._merge_settings( + params["settings"] = self._merge_dict( dashboard_vo.settings, params["settings"] ) + if "display_info" in params: + params["display_info"] = self._merge_dict( + dashboard_vo.display_info, params["display_info"] + ) + version_change_keys = ["layouts", "variables", "variables_schema"] if self._has_version_key_in_params(dashboard_vo, params, version_change_keys): self.dashboard_mgr.increase_version(dashboard_vo) @@ -427,11 +432,11 @@ def _has_version_key_in_params( return False @staticmethod - def _merge_settings(old_settings: dict, new_settings: dict) -> dict: - settings = copy.deepcopy(old_settings) + def _merge_dict(old_dict: dict, new_dict: dict) -> dict: + settings = copy.deepcopy(old_dict) - if old_settings: - settings.update(new_settings) + if old_dict: + settings.update(new_dict) return settings else: - return new_settings + return new_dict