Refactor read_flow function to handle auto login
This commit is contained in:
parent
1dec624c61
commit
d354ae9975
1 changed files with 7 additions and 10 deletions
|
|
@ -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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue