Refactor filter.

pull/1131/head
Andrey 2024-10-02 17:41:46 +03:00
rodzic f6e7f194e1
commit 1fcd69dc98
2 zmienionych plików z 33 dodań i 22 usunięć

Wyświetl plik

@ -158,12 +158,12 @@ async def add_subscription_handler(
if description: if description:
content["description"] = description content["description"] = description
excluded_keys = MOONSTREAM_ENTITIES_RESERVED_TAGS
allowed_required_fields: List[Any] = [] allowed_required_fields: List[Any] = []
if tags: if tags:
allowed_required_fields = [ allowed_required_fields = [
item item for item in tags if not any(key in item for key in excluded_keys)
for item in tags
if not any(key in item for key in MOONSTREAM_ENTITIES_RESERVED_TAGS)
] ]
required_fields: List[Dict[str, Union[str, bool, int, List[Any]]]] = [ required_fields: List[Dict[str, Union[str, bool, int, List[Any]]]] = [
@ -228,11 +228,15 @@ async def add_subscription_handler(
entity_secondary_fields = ( entity_secondary_fields = (
entity.secondary_fields if entity.secondary_fields is not None else {} entity.secondary_fields if entity.secondary_fields is not None else {}
) )
# We remove the instance_name for return that tag to the frontend
excluded_keys = excluded_keys - {"instance_name"}
normalized_entity_tags = [ normalized_entity_tags = [
f"{key}:{value}" f"{key}:{value}"
for tag in entity_required_fields for tag in entity_required_fields
for key, value in tag.items() for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS or key == "instance_name" if key not in excluded_keys
] ]
if entity_secondary_fields.get("abi") and customer_id is not None: if entity_secondary_fields.get("abi") and customer_id is not None:
@ -324,7 +328,7 @@ async def delete_subscription_handler(
f"{key}:{value}" f"{key}:{value}"
for tag in tags_raw for tag in tags_raw
for key, value in tag.items() for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS if key not in (MOONSTREAM_ENTITIES_RESERVED_TAGS - {"instance_name"})
] ]
if deleted_entity.secondary_fields is not None: if deleted_entity.secondary_fields is not None:
@ -397,6 +401,9 @@ async def get_subscriptions_handler(
List[BugoutSearchResultAsEntity], subscriptions_list.results List[BugoutSearchResultAsEntity], subscriptions_list.results
) )
# We remove the instance_name for return that tag to the frontend
excluded_keys = MOONSTREAM_ENTITIES_RESERVED_TAGS - {"instance_name"}
for subscription in user_subscriptions_results: for subscription in user_subscriptions_results:
tags = subscription.required_fields tags = subscription.required_fields
@ -416,7 +423,7 @@ async def get_subscriptions_handler(
f"{key}:{value}" f"{key}:{value}"
for tag in tags for tag in tags
for key, value in tag.items() for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS or key == "instance_name" if key not in excluded_keys
] ]
subscriptions.append( subscriptions.append(
@ -485,6 +492,8 @@ async def update_subscriptions_handler(
detail="Not found customer", detail="Not found customer",
) )
excluded_keys = MOONSTREAM_ENTITIES_RESERVED_TAGS
try: try:
journal_id = get_entity_subscription_journal_id( journal_id = get_entity_subscription_journal_id(
resource_type=BUGOUT_RESOURCE_TYPE_ENTITY_SUBSCRIPTION, resource_type=BUGOUT_RESOURCE_TYPE_ENTITY_SUBSCRIPTION,
@ -504,7 +513,7 @@ async def update_subscriptions_handler(
update_required_fields = [ update_required_fields = [
field field
for field in subscription_entity.required_fields for field in subscription_entity.required_fields
if any(key in field for key in MOONSTREAM_ENTITIES_RESERVED_TAGS) if any(key in field for key in excluded_keys)
] ]
update_secondary_fields = ( update_secondary_fields = (
@ -570,9 +579,7 @@ async def update_subscriptions_handler(
if tags: if tags:
allowed_required_fields = [ allowed_required_fields = [
item item for item in tags if not any(key in item for key in excluded_keys)
for item in tags
if not any(key in item for key in MOONSTREAM_ENTITIES_RESERVED_TAGS)
] ]
if allowed_required_fields: if allowed_required_fields:
@ -633,12 +640,14 @@ async def update_subscriptions_handler(
if subscription.secondary_fields is not None if subscription.secondary_fields is not None
else {} else {}
) )
# We remove the instance_name for return that tag to the frontend
excluded_keys = excluded_keys - {"instance_name"}
normalized_entity_tags = [ normalized_entity_tags = [
f"{key}:{value}" f"{key}:{value}"
for tag in subscription_required_fields for tag in subscription_required_fields
for key, value in tag.items() for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS or key == "instance_name" if key not in excluded_keys
] ]
return data.SubscriptionResourceData( return data.SubscriptionResourceData(

Wyświetl plik

@ -301,17 +301,19 @@ if MOONSTREAM_S3_QUERIES_BUCKET_PREFIX == "":
) )
# Entities reserved tags # Entities reserved tags
MOONSTREAM_ENTITIES_RESERVED_TAGS = [ MOONSTREAM_ENTITIES_RESERVED_TAGS = set(
"type", [
"subscription_type_id", "type",
"color", "subscription_type_id",
"label", "color",
"user_id", "label",
"address", "user_id",
"blockchain", "address",
"customer_id", "blockchain",
"instance_name", "customer_id",
] "instance_name",
]
)
## Moonstream resources types ## Moonstream resources types