Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tags. #1131

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions moonstreamapi/moonstreamapi/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,10 +1181,10 @@ def create_resource_for_user(
return resource


def chekc_user_resource_access(
def check_user_resource_access(
customer_id: uuid.UUID,
user_token: uuid.UUID,
) -> bool:
) -> Optional[BugoutResource]:
"""
Check if user has access to customer_id
"""
Expand All @@ -1198,10 +1198,10 @@ def chekc_user_resource_access(

except BugoutResponseException as e:
if e.status_code == 404:
return False
return None
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
except Exception as e:
logger.error(f"Error get customer: {str(e)}")
raise MoonstreamHTTPException(status_code=500, internal_error=e)

return str(response.id) == customer_id
return response
38 changes: 26 additions & 12 deletions moonstreamapi/moonstreamapi/routes/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
EntityJournalNotFoundException,
apply_moonworm_tasks,
check_if_smart_contract,
chekc_user_resource_access,
check_user_resource_access,
get_entity_subscription_journal_id,
get_list_of_support_interfaces,
get_moonworm_tasks,
Expand Down Expand Up @@ -104,17 +104,19 @@ async def add_subscription_handler(

if customer_id is not None:

results = chekc_user_resource_access(
results = check_user_resource_access(
customer_id=customer_id,
user_token=token,
)

if not results:
if results is None:
raise MoonstreamHTTPException(
status_code=403,
detail="User has no access to this customer",
status_code=404,
detail="Not found customer",
)

customer_instance_name = results.resource_data["name"]

active_subscription_types_response = subscription_types.list_subscription_types(
active_only=True
)
Expand Down Expand Up @@ -172,6 +174,18 @@ async def add_subscription_handler(
{"user_id": f"{user.id}"},
]

if customer_id is not None and customer_instance_name is not None:
required_fields.extend(
[
{
"customer_id": f"{customer_id}",
},
{
"instance_name": f"{customer_instance_name}",
},
]
)

if allowed_required_fields:
required_fields.extend(allowed_required_fields)

Expand Down Expand Up @@ -218,7 +232,7 @@ async def add_subscription_handler(
f"{key}:{value}"
for tag in entity_required_fields
for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS or key == "instance_name"
]

if entity_secondary_fields.get("abi") and customer_id is not None:
Expand Down Expand Up @@ -402,7 +416,7 @@ async def get_subscriptions_handler(
f"{key}:{value}"
for tag in tags
for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS or key == "instance_name"
]

subscriptions.append(
Expand Down Expand Up @@ -460,15 +474,15 @@ async def update_subscriptions_handler(

if customer_id is not None:

results = chekc_user_resource_access(
results = check_user_resource_access(
customer_id=customer_id,
user_token=token,
)

if not results:
if results is None:
raise MoonstreamHTTPException(
status_code=403,
detail="User has no access to this customer",
status_code=404,
detail="Not found customer",
)

try:
Expand Down Expand Up @@ -624,7 +638,7 @@ async def update_subscriptions_handler(
f"{key}:{value}"
for tag in subscription_required_fields
for key, value in tag.items()
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS
if key not in MOONSTREAM_ENTITIES_RESERVED_TAGS or key == "instance_name"
]

return data.SubscriptionResourceData(
Expand Down
2 changes: 2 additions & 0 deletions moonstreamapi/moonstreamapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@
"user_id",
"address",
"blockchain",
"customer_id",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about journal entities changes (at spire). We added here reserved tags, but not modified the source. Why just not to use required_fields https://spire.bugout.dev/journals/docs#tag/entities/operation/create_journal_entity__journal_id__entities_post
?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old one remain same. New one will have new tags

"instance_name",
]

## Moonstream resources types
Expand Down
Loading