diff --git a/perxis/extensions/extension_setup.py b/perxis/extensions/extension_setup.py index 41e9f55fa60b21b9495113203ab9250f0fc2eb62..918f20100dad71243392ec8a9028d8dd71b1a249 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 f32e69f833fd5ed205f662c4eeb06c72c5741975..078ed22feb143938bbc0ed65dae5ae988af4bb97 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 b5ba8e632b01ca0594f1c34e67d15d70c07ba223..d45242aebf6198710f77eeae98e4f40c88c6afca 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