Refactor read_flow function to handle auto login

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-06 14:46:36 -03:00
commit d354ae9975

View file

@ -89,16 +89,13 @@ def read_flow(
settings_service: "SettingsService" = Depends(get_settings_service), settings_service: "SettingsService" = Depends(get_settings_service),
): ):
"""Read a flow.""" """Read a flow."""
# auth_settings = settings_service.auth_settings auth_settings = settings_service.auth_settings
# if auth_settings.AUTO_LOGIN: stmt = select(Flow).where(Flow.id == flow_id)
# user_id = None if auth_settings.AUTO_LOGIN:
# else: # If auto login is enable user_id can be current_user.id or None
# user_id = current_user.id # so write an OR
if user_flow := ( stmt = stmt.where((Flow.user_id == current_user.id) | (Flow.user_id == None))
session.exec( if user_flow := session.exec(stmt).first():
select(Flow).where(Flow.id == flow_id, Flow.user_id == current_user.id)
).first()
):
return user_flow return user_flow
else: else:
raise HTTPException(status_code=404, detail="Flow not found") raise HTTPException(status_code=404, detail="Flow not found")