11from typing import Annotated , Literal
22
33from fastapi import APIRouter , Body , Depends
4+ from loguru import logger
45from pydantic import BaseModel
56from sqlalchemy .engine import Row
67from sqlalchemy .ext .asyncio import AsyncConnection
@@ -73,6 +74,11 @@ async def attach_to_study(
7374 # PHP lets *anyone* edit *any* study. We're not going to do that.
7475 if study .creator != user .user_id and not await user .is_admin ():
7576 msg = f"Study { study_id } can only be edited by its creator."
77+ logger .warning (
78+ "User attempted to attach entities to study they do not own." ,
79+ study_id = study_id ,
80+ entity_ids = entity_ids ,
81+ )
7682 raise StudyNotEditableError (msg )
7783 if study .status != StudyStatus .IN_PREPARATION :
7884 msg = f"Study { study_id } can only be edited while in preparation."
@@ -93,6 +99,11 @@ async def attach_to_study(
9399 except ValueError as e :
94100 msg = str (e )
95101 raise StudyConflictError (msg ) from e
102+ logger .info (
103+ "User {user_id} attached entities to study {study_id}." ,
104+ study_id = study_id ,
105+ entity_ids = entity_ids ,
106+ )
96107 return AttachDetachResponse (study_id = study_id , main_entity_type = study .type_ )
97108
98109
@@ -124,6 +135,10 @@ async def create_study(
124135 user = user ,
125136 expdb = expdb ,
126137 )
138+ logger .info (
139+ "User {user_id} created study {study_id}." ,
140+ study_id = study_id ,
141+ )
127142 # Make sure that invalid fields raise an error (e.g., "task_ids")
128143 return {"study_id" : study_id }
129144
0 commit comments