kopia lustrzana https://github.com/bugout-dev/moonstream
Remove user interactions with resources(only list).
rodzic
974128528e
commit
52aafc328b
|
@ -15,6 +15,9 @@ from bugout.data import (
|
||||||
BugoutResources,
|
BugoutResources,
|
||||||
BugoutSearchResult,
|
BugoutSearchResult,
|
||||||
BugoutSearchResults,
|
BugoutSearchResults,
|
||||||
|
BugoutResourceHolder,
|
||||||
|
HolderType,
|
||||||
|
ResourcePermissions,
|
||||||
)
|
)
|
||||||
from bugout.exceptions import BugoutResponseException
|
from bugout.exceptions import BugoutResponseException
|
||||||
from bugout.journal import SearchOrder
|
from bugout.journal import SearchOrder
|
||||||
|
@ -952,3 +955,55 @@ def check_if_smart_contract(
|
||||||
is_contract = True
|
is_contract = True
|
||||||
|
|
||||||
return blockchain_type, address, is_contract
|
return blockchain_type, address, is_contract
|
||||||
|
|
||||||
|
|
||||||
|
def create_resource_for_user(
|
||||||
|
user_id: uuid.UUID,
|
||||||
|
resource_data: Dict[str, Any],
|
||||||
|
) -> BugoutResource:
|
||||||
|
"""
|
||||||
|
Create resource for user
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
resource = bc.create_resource(
|
||||||
|
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||||
|
application_id=MOONSTREAM_APPLICATION_ID,
|
||||||
|
resource_data=resource_data,
|
||||||
|
)
|
||||||
|
except BugoutResponseException as e:
|
||||||
|
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error creating resource: {str(e)}")
|
||||||
|
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
||||||
|
|
||||||
|
try:
|
||||||
|
bc.add_resource_holder_permissions(
|
||||||
|
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||||
|
resource_id=resource.id,
|
||||||
|
holder_permissions=BugoutResourceHolder(
|
||||||
|
holder_type=HolderType.user,
|
||||||
|
holder_id=user_id,
|
||||||
|
permission_list=[
|
||||||
|
ResourcePermissions.ADMIN,
|
||||||
|
ResourcePermissions.READ,
|
||||||
|
ResourcePermissions.UPDATE,
|
||||||
|
ResourcePermissions.DELETE,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
except BugoutResponseException as e:
|
||||||
|
logger.error(
|
||||||
|
f"Error adding resource holder permissions to resource resource {str(resource.id)} {str(e)}"
|
||||||
|
)
|
||||||
|
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
|
||||||
|
except Exception as e:
|
||||||
|
bc.delete_resource(
|
||||||
|
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||||
|
resource_id=resource.id,
|
||||||
|
)
|
||||||
|
logger.error(
|
||||||
|
f"Error adding resource holder permissions to resource {str(resource.id)} {str(e)}"
|
||||||
|
)
|
||||||
|
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
||||||
|
|
||||||
|
return resource
|
||||||
|
|
|
@ -25,6 +25,7 @@ from ..actions import (
|
||||||
get_query_by_name,
|
get_query_by_name,
|
||||||
name_normalization,
|
name_normalization,
|
||||||
query_parameter_hash,
|
query_parameter_hash,
|
||||||
|
create_resource_for_user,
|
||||||
)
|
)
|
||||||
from ..middleware import MoonstreamHTTPException
|
from ..middleware import MoonstreamHTTPException
|
||||||
from ..settings import (
|
from ..settings import (
|
||||||
|
@ -130,24 +131,16 @@ async def create_query_handler(
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
||||||
|
|
||||||
try:
|
create_resource_for_user(
|
||||||
# create resource query_name_resolver
|
user_id=user.id,
|
||||||
bc.create_resource(
|
resource_data={
|
||||||
token=token,
|
"type": data.BUGOUT_RESOURCE_QUERY_RESOLVER,
|
||||||
application_id=MOONSTREAM_APPLICATION_ID,
|
"user_id": str(user.id),
|
||||||
resource_data={
|
"user": str(user.username),
|
||||||
"type": data.BUGOUT_RESOURCE_QUERY_RESOLVER,
|
"name": query_name,
|
||||||
"user_id": str(user.id),
|
"entry_id": str(entry.id),
|
||||||
"user": str(user.username),
|
},
|
||||||
"name": query_name,
|
)
|
||||||
"entry_id": str(entry.id),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
except BugoutResponseException as e:
|
|
||||||
logger.error(f"Error creating name resolving resource: {str(e)}")
|
|
||||||
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
|
|
||||||
except Exception as e:
|
|
||||||
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bc.update_tags(
|
bc.update_tags(
|
||||||
|
@ -355,7 +348,7 @@ async def update_query_handler(
|
||||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||||
journal_id=MOONSTREAM_QUERIES_JOURNAL_ID,
|
journal_id=MOONSTREAM_QUERIES_JOURNAL_ID,
|
||||||
entry_id=query_id,
|
entry_id=query_id,
|
||||||
title=query_name,
|
title=f"Query:{query_name}",
|
||||||
content=request_update.query,
|
content=request_update.query,
|
||||||
tags=["preapprove"],
|
tags=["preapprove"],
|
||||||
)
|
)
|
||||||
|
@ -620,7 +613,9 @@ async def remove_query_handler(
|
||||||
raise MoonstreamHTTPException(status_code=404, detail="Query does not exists")
|
raise MoonstreamHTTPException(status_code=404, detail="Query does not exists")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bc.delete_resource(token=token, resource_id=query_ids[query_name][0])
|
bc.delete_resource(
|
||||||
|
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, resource_id=query_ids[query_name][0]
|
||||||
|
)
|
||||||
except BugoutResponseException as e:
|
except BugoutResponseException as e:
|
||||||
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
|
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Ładowanie…
Reference in New Issue