Skip to content
Snippets Groups Projects
Commit db7c727f authored by Podosochnyy Maxim's avatar Podosochnyy Maxim
Browse files

Добавлены флаги для возможности указания допусимости изменения / удаления item'ов

parent dae36cef
No related branches found
No related tags found
No related merge requests found
...@@ -666,11 +666,14 @@ class ExtensionSetup: ...@@ -666,11 +666,14 @@ class ExtensionSetup:
try: try:
if item_in_perxis: if item_in_perxis:
# Если установлен запрет на изменение item'ов
if not item.with_update:
continue
# Для того чтобы не затереть изменения в perxis # Для того чтобы не затереть изменения в perxis
# Нужно смержить данные. Логика работы: # Нужно смержить данные. Логика работы:
# 1. Данные которые указаны в `data` в расширении - в приоритете, они замещают то что в perxis # 1. Данные которые указаны в `data` в расширении - в приоритете, они замещают то что в perxis
# 2. Данные которые есть в perxis но нет в расширении - дополняются # 2. Данные которые есть в perxis но нет в расширении - дополняются
await wrapper.update( await wrapper.update(
collection_id=item.collection_id, collection_id=item.collection_id,
item_id=item_in_perxis.id, item_id=item_in_perxis.id,
...@@ -723,6 +726,10 @@ class ExtensionSetup: ...@@ -723,6 +726,10 @@ class ExtensionSetup:
if not all_rules_satisfied: if not all_rules_satisfied:
continue continue
# Если установлен запрет на удаление item'ов
if not item.with_delete:
continue
try: try:
message = await wrapper.find( message = await wrapper.find(
collection_id=item.collection_id, collection_id=item.collection_id,
......
...@@ -16,6 +16,8 @@ class AbstractItem(metaclass=abc.ABCMeta): ...@@ -16,6 +16,8 @@ class AbstractItem(metaclass=abc.ABCMeta):
rules: list[AbstractRule] rules: list[AbstractRule]
identifier_field: str = "id" identifier_field: str = "id"
with_update: bool
with_delete: bool
@property @property
def identifier(self): def identifier(self):
...@@ -61,6 +63,8 @@ class Item(AbstractItem): ...@@ -61,6 +63,8 @@ class Item(AbstractItem):
self, self,
collection_id: str, collection_id: str,
data: dict, data: dict,
with_update: bool = True,
with_delete: bool = True,
identifier_field: str = "id", identifier_field: str = "id",
rules: list[AbstractRule] | None = None rules: list[AbstractRule] | None = None
): ):
...@@ -68,6 +72,8 @@ class Item(AbstractItem): ...@@ -68,6 +72,8 @@ class Item(AbstractItem):
self.data = data self.data = data
self.identifier_field = identifier_field self.identifier_field = identifier_field
self.rules = rules or [] self.rules = rules or []
self.with_update = with_update
self.with_delete = with_delete
class DataSourceItem(AbstractItem): class DataSourceItem(AbstractItem):
...@@ -81,7 +87,9 @@ class DataSourceItem(AbstractItem): ...@@ -81,7 +87,9 @@ class DataSourceItem(AbstractItem):
rules: list[AbstractRule] | None = None, rules: list[AbstractRule] | None = None,
query: str = "", query: str = "",
content_type: str = "", content_type: str = "",
exclude: bool = False exclude: bool = False,
with_update: bool = True,
with_delete: bool = True,
): ):
self.collection_id = "web_datasources" self.collection_id = "web_datasources"
self.rules = rules or [IfCollectionExists()] self.rules = rules or [IfCollectionExists()]
...@@ -93,6 +101,9 @@ class DataSourceItem(AbstractItem): ...@@ -93,6 +101,9 @@ class DataSourceItem(AbstractItem):
"exclude": exclude, "exclude": exclude,
} }
self.with_update = with_update
self.with_delete = with_delete
class SyncPolicyItem(AbstractItem): class SyncPolicyItem(AbstractItem):
""" """
...@@ -114,6 +125,8 @@ class SyncPolicyItem(AbstractItem): ...@@ -114,6 +125,8 @@ class SyncPolicyItem(AbstractItem):
deny_read: bool = False, deny_read: bool = False,
hidden: bool = False, hidden: bool = False,
rules: list[AbstractRule] | None = None, rules: list[AbstractRule] | None = None,
with_update: bool = True,
with_delete: bool = True,
): ):
self.collection_id = "hoop_item_sync_policies" self.collection_id = "hoop_item_sync_policies"
self.rules = rules or [IfExtensionInstalled("perxishoop")] self.rules = rules or [IfExtensionInstalled("perxishoop")]
...@@ -130,3 +143,6 @@ class SyncPolicyItem(AbstractItem): ...@@ -130,3 +143,6 @@ class SyncPolicyItem(AbstractItem):
"deny_read": deny_read, "deny_read": deny_read,
"hidden": hidden, "hidden": hidden,
} }
self.with_update = with_update
self.with_delete = with_delete
\ No newline at end of file
...@@ -4,21 +4,31 @@ from perxis.extensions import manager_service_pb2 ...@@ -4,21 +4,31 @@ from perxis.extensions import manager_service_pb2
from perxis.extensions.item_models import DataSourceItem, SyncPolicyItem 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 [ return [
DataSourceItem( DataSourceItem(
collection_id=collection_id collection_id=collection_id,
with_delete=with_delete,
with_update=with_update
) )
for collection_id in collections_map for collection_id in collections_map
if collection_id 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 ...@@ -27,6 +37,8 @@ def sync_policies_from_collections(collections_map: dict[str, str]) -> list[Sync
SyncPolicyItem( SyncPolicyItem(
collection_id=collection_id, collection_id=collection_id,
name=collection_name, name=collection_name,
with_update=with_update,
with_delete=with_delete,
) )
for collection_id, collection_name in collections_map.items() for collection_id, collection_name in collections_map.items()
if collection_id if collection_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment