diff --git a/perxis/extensions/extension_setup.py b/perxis/extensions/extension_setup.py index 9622223b097a4559ec6ddc9d7beea86148c919d6..65a2bfc9fbf63c8be4e8858f3ef9e067df7c7f24 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(