From db7c727f36d17ddda3490bd14383aab84e265dc3 Mon Sep 17 00:00:00 2001 From: Maxim Podosochnyy <podosochnyy@perx.ru> Date: Tue, 25 Mar 2025 14:20:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=BB=D0=B0=D0=B3=D0=B8=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D1=83=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=BF=D1=83=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20/=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20item'?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- perxis/extensions/extension_setup.py | 9 ++++++++- perxis/extensions/item_models.py | 20 ++++++++++++++++++-- perxis/extensions/utils.py | 18 +++++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/perxis/extensions/extension_setup.py b/perxis/extensions/extension_setup.py index 41e9f55..918f201 100644 --- a/perxis/extensions/extension_setup.py +++ b/perxis/extensions/extension_setup.py @@ -666,11 +666,14 @@ class ExtensionSetup: try: if item_in_perxis: + # Если установлен запрет на изменение item'ов + if not item.with_update: + continue + # Для того чтобы не затереть изменения в perxis # Нужно смержить данные. Логика работы: # 1. Данные которые указаны в `data` в расширении - в приоритете, они замещают то что в perxis # 2. Данные которые есть в perxis но нет в расширении - дополняются - await wrapper.update( collection_id=item.collection_id, item_id=item_in_perxis.id, @@ -723,6 +726,10 @@ class ExtensionSetup: if not all_rules_satisfied: continue + # Если установлен запрет на удаление item'ов + if not item.with_delete: + continue + try: message = await wrapper.find( collection_id=item.collection_id, diff --git a/perxis/extensions/item_models.py b/perxis/extensions/item_models.py index f32e69f..078ed22 100644 --- a/perxis/extensions/item_models.py +++ b/perxis/extensions/item_models.py @@ -16,6 +16,8 @@ class AbstractItem(metaclass=abc.ABCMeta): rules: list[AbstractRule] identifier_field: str = "id" + with_update: bool + with_delete: bool @property def identifier(self): @@ -61,6 +63,8 @@ class Item(AbstractItem): self, collection_id: str, data: dict, + with_update: bool = True, + with_delete: bool = True, identifier_field: str = "id", rules: list[AbstractRule] | None = None ): @@ -68,6 +72,8 @@ class Item(AbstractItem): self.data = data self.identifier_field = identifier_field self.rules = rules or [] + self.with_update = with_update + self.with_delete = with_delete class DataSourceItem(AbstractItem): @@ -81,7 +87,9 @@ class DataSourceItem(AbstractItem): rules: list[AbstractRule] | None = None, query: str = "", content_type: str = "", - exclude: bool = False + exclude: bool = False, + with_update: bool = True, + with_delete: bool = True, ): self.collection_id = "web_datasources" self.rules = rules or [IfCollectionExists()] @@ -93,6 +101,9 @@ class DataSourceItem(AbstractItem): "exclude": exclude, } + self.with_update = with_update + self.with_delete = with_delete + class SyncPolicyItem(AbstractItem): """ @@ -114,6 +125,8 @@ class SyncPolicyItem(AbstractItem): deny_read: bool = False, hidden: bool = False, rules: list[AbstractRule] | None = None, + with_update: bool = True, + with_delete: bool = True, ): self.collection_id = "hoop_item_sync_policies" self.rules = rules or [IfExtensionInstalled("perxishoop")] @@ -129,4 +142,7 @@ class SyncPolicyItem(AbstractItem): "deny_create": deny_create, "deny_read": deny_read, "hidden": hidden, - } \ No newline at end of file + } + + self.with_update = with_update + self.with_delete = with_delete \ No newline at end of file diff --git a/perxis/extensions/utils.py b/perxis/extensions/utils.py index b5ba8e6..d45242a 100644 --- a/perxis/extensions/utils.py +++ b/perxis/extensions/utils.py @@ -4,21 +4,31 @@ from perxis.extensions import manager_service_pb2 from perxis.extensions.item_models import DataSourceItem, SyncPolicyItem -def datasource_items_from_collections(collections_map: dict[str, str]) -> list[DataSourceItem]: +def datasource_items_from_collections( + collections_map: dict[str, str], + with_update: bool = True, + with_delete: bool = True, +) -> list[DataSourceItem]: """ Создание записей источников данных на базе маппинга коллекций """ return [ DataSourceItem( - collection_id=collection_id + collection_id=collection_id, + with_delete=with_delete, + with_update=with_update ) for collection_id in collections_map if collection_id ] -def sync_policies_from_collections(collections_map: dict[str, str]) -> list[SyncPolicyItem]: +def sync_policies_from_collections( + collections_map: dict[str, str], + with_update: bool = True, + with_delete: bool = True, +) -> list[SyncPolicyItem]: """ Создание записей синхронизации коллекций на базе маппинга коллекций """ @@ -27,6 +37,8 @@ def sync_policies_from_collections(collections_map: dict[str, str]) -> list[Sync SyncPolicyItem( collection_id=collection_id, name=collection_name, + with_update=with_update, + with_delete=with_delete, ) for collection_id, collection_name in collections_map.items() if collection_id -- GitLab