From fad8949978edf3e88b976552ad16e82d5f50eb96 Mon Sep 17 00:00:00 2001 From: Maxim Podosochnyy <podosochnyy@perx.ru> Date: Tue, 4 Jul 2023 15:09:02 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- perxis/extensions/extension_setup.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/perxis/extensions/extension_setup.py b/perxis/extensions/extension_setup.py index 9622223..65a2bfc 100644 --- a/perxis/extensions/extension_setup.py +++ b/perxis/extensions/extension_setup.py @@ -8,6 +8,7 @@ import typing from deepdiff import DeepDiff from perxis.collections import collections_pb2_grpc, collections_pb2 from perxis.roles import roles_pb2_grpc, roles_pb2 +from perxis.common import common_pb2 from perxis.clients import clients_pb2_grpc, clients_pb2 from perxis.environments import environments_pb2_grpc, environments_pb2 @@ -112,6 +113,25 @@ class ExtensionSetup: cloned_role.environments[:] = role.environments + # Произвести мерж правил доступа + for exist_rule in role.rules: + was_found = False + + for local_rule in cloned_role.rules: + if local_rule.collection_id == exist_rule.collection_id: + was_found = True + + local_rule.actions[:] = list(set(local_rule.actions + exist_rule.actions)) + + break + + # Если правило для коллекций не было найдено - его нужно добавить + if not was_found: + cloned_role.rules.append(common_pb2.Rule( + collection_id=exist_rule.collection_id, + actions=exist_rule.actions + )) + try: self.roles_service.Update.with_call( roles_pb2.UpdateRequest( -- GitLab