55import database
66import officers .crud
77import utils
8- from dependencies import LoggedInUser , perm_admin
8+ from dependencies import LoggedInUser , SessionUser , perm_admin
99from officers .constants import OfficerPositionEnum
1010from officers .models import (
1111 OfficerCreate ,
1616 OfficerTermUpdate ,
1717 OfficerUpdate ,
1818)
19- from officers .tables import OfficerInfoDB
2019from permission .types import OfficerPrivateInfo
2120from utils .permissions import is_user_website_admin , verify_update
2221from utils .shared_models import DetailModel , SuccessResponse
@@ -112,21 +111,18 @@ async def all_officers(
112111 operation_id = "get_officer_terms_by_id" ,
113112)
114113async def get_officer_terms (
115- request : Request , db_session : database .DBSession , computing_id : str , include_future_terms : bool = False
114+ user_id : SessionUser , db_session : database .DBSession , computing_id : str , include_future_terms : bool = False
116115):
117116 if include_future_terms :
118- await verify_update (request , db_session , computing_id )
119- # _, session_computing_id = await get_user(request, db_session)
120- # if computing_id != session_computing_id and not is_user_website_admin(session_computing_id, db_session):
121- # raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="not authorized")
117+ await verify_update (user_id , db_session , computing_id )
122118
123119 # all term info is public, so anyone can get any of it
124120 officer_terms = await officers .crud .get_officer_terms (db_session , computing_id , include_future_terms )
125121 return JSONResponse ([OfficerTerm .model_validate (term ).model_dump (mode = "json" ) for term in officer_terms ])
126122
127123
128124@router .get (
129- "/info/{computing_id:str }" ,
125+ "/info/{computing_id}" ,
130126 description = "Get officer info for the current user, if they've ever been an exec. Only admins can get info about another user." ,
131127 response_model = OfficerInfo ,
132128 responses = {403 : {"description" : "not authorized to view author user info" , "model" : DetailModel }},
@@ -163,9 +159,10 @@ async def create_officer_term(
163159 officer_list : list [OfficerCreate ],
164160):
165161 new_terms = await officers .crud .create_multiple_officers (db_session , officer_list )
162+ content = [term .serializable_dict () for term in new_terms ]
166163
167164 await db_session .commit ()
168- return JSONResponse ([ OfficerTerm . model_validate ( term ). model_dump ( mode = "json" ) for term in new_terms ] )
165+ return JSONResponse (content )
169166
170167
171168@router .patch (
@@ -183,12 +180,12 @@ async def create_officer_term(
183180 operation_id = "update_officer_info" ,
184181)
185182async def update_officer_info (
186- request : Request ,
183+ user_id : SessionUser ,
187184 db_session : database .DBSession ,
188185 computing_id : str ,
189186 officer_info_upload : OfficerUpdate ,
190187):
191- await verify_update (request , db_session , computing_id )
188+ await verify_update (user_id , db_session , computing_id )
192189
193190 old_officer_info = await officers .crud .get_officer_info_or_raise (db_session , computing_id )
194191 old_officer_info .update_from_params (officer_info_upload )
@@ -221,8 +218,9 @@ async def update_officer_term(db_session: database.DBSession, term_id: int, body
221218
222219 old_officer_term = await officers .crud .get_officer_term_by_id_or_raise (db_session , term_id )
223220
224- if utils .is_past_term (old_officer_term ):
225- raise HTTPException (status_code = 403 , detail = "you may not update past terms" )
221+ # TODO: Enable this check if we allow non-website admins to change their information
222+ # if utils.is_past_term(old_officer_term):
223+ # raise HTTPException(status_code=403, detail="you may not update past terms")
226224
227225 new_data = body .model_dump (exclude_unset = True )
228226
0 commit comments