refac
This commit is contained in:
@@ -653,7 +653,28 @@ async def get_tools_valves_by_id(
|
|||||||
id: str, user=Depends(get_verified_user), db: Session = Depends(get_session)
|
id: str, user=Depends(get_verified_user), db: Session = Depends(get_session)
|
||||||
):
|
):
|
||||||
tools = Tools.get_tool_by_id(id, db=db)
|
tools = Tools.get_tool_by_id(id, db=db)
|
||||||
if tools:
|
if not tools:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
tools.user_id != user.id
|
||||||
|
and not AccessGrants.has_access(
|
||||||
|
user_id=user.id,
|
||||||
|
resource_type="tool",
|
||||||
|
resource_id=tools.id,
|
||||||
|
permission="write",
|
||||||
|
db=db,
|
||||||
|
)
|
||||||
|
and user.role != "admin"
|
||||||
|
):
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
valves = Tools.get_tool_valves_by_id(id, db=db)
|
valves = Tools.get_tool_valves_by_id(id, db=db)
|
||||||
return valves
|
return valves
|
||||||
@@ -662,11 +683,6 @@ async def get_tools_valves_by_id(
|
|||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
detail=ERROR_MESSAGES.DEFAULT(str(e)),
|
detail=ERROR_MESSAGES.DEFAULT(str(e)),
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
||||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
############################
|
############################
|
||||||
@@ -682,7 +698,28 @@ async def get_tools_valves_spec_by_id(
|
|||||||
db: Session = Depends(get_session),
|
db: Session = Depends(get_session),
|
||||||
):
|
):
|
||||||
tools = Tools.get_tool_by_id(id, db=db)
|
tools = Tools.get_tool_by_id(id, db=db)
|
||||||
if tools:
|
if not tools:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
tools.user_id != user.id
|
||||||
|
and not AccessGrants.has_access(
|
||||||
|
user_id=user.id,
|
||||||
|
resource_type="tool",
|
||||||
|
resource_id=tools.id,
|
||||||
|
permission="write",
|
||||||
|
db=db,
|
||||||
|
)
|
||||||
|
and user.role != "admin"
|
||||||
|
):
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||||
|
)
|
||||||
|
|
||||||
if id in request.app.state.TOOLS:
|
if id in request.app.state.TOOLS:
|
||||||
tools_module = request.app.state.TOOLS[id]
|
tools_module = request.app.state.TOOLS[id]
|
||||||
else:
|
else:
|
||||||
@@ -696,11 +733,6 @@ async def get_tools_valves_spec_by_id(
|
|||||||
schema = resolve_valves_schema_options(Valves, schema, user)
|
schema = resolve_valves_schema_options(Valves, schema, user)
|
||||||
return schema
|
return schema
|
||||||
return None
|
return None
|
||||||
else:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
||||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
############################
|
############################
|
||||||
|
|||||||
Reference in New Issue
Block a user