This commit is contained in:
Tim Baek
2026-03-24 14:37:03 -05:00
parent 6d7744c219
commit f949d17db1
+65 -18
View File
@@ -762,7 +762,28 @@ async def update_tools_valves_by_id(
@router.get('/id/{id}/valves/user', response_model=Optional[dict]) @router.get('/id/{id}/valves/user', response_model=Optional[dict])
async def get_tools_user_valves_by_id(id: str, user=Depends(get_verified_user), db: Session = Depends(get_session)): async def get_tools_user_valves_by_id(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='read',
db=db,
)
and user.role != 'admin'
):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
)
try: try:
user_valves = Tools.get_user_valves_by_id_and_user_id(id, user.id, db=db) user_valves = Tools.get_user_valves_by_id_and_user_id(id, user.id, db=db)
return user_valves return user_valves
@@ -771,11 +792,6 @@ async def get_tools_user_valves_by_id(id: str, user=Depends(get_verified_user),
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,
)
@router.get('/id/{id}/valves/user/spec', response_model=Optional[dict]) @router.get('/id/{id}/valves/user/spec', response_model=Optional[dict])
@@ -786,7 +802,28 @@ async def get_tools_user_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='read',
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:
@@ -800,11 +837,6 @@ async def get_tools_user_valves_spec_by_id(
schema = resolve_valves_schema_options(UserValves, schema, user) schema = resolve_valves_schema_options(UserValves, schema, user)
return schema return schema
return None return None
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.NOT_FOUND,
)
@router.post('/id/{id}/valves/user/update', response_model=Optional[dict]) @router.post('/id/{id}/valves/user/update', response_model=Optional[dict])
@@ -816,8 +848,28 @@ async def update_tools_user_valves_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 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='read',
db=db,
)
and user.role != 'admin'
):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
)
if tools:
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:
@@ -844,8 +896,3 @@ async def update_tools_user_valves_by_id(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND,
) )
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.NOT_FOUND,
)