1- import logging
2-
31from fastapi import APIRouter , Body , HTTPException , Request
42from fastapi .responses import JSONResponse , PlainTextResponse
53
64import auth .crud
75import database
86import officers .crud
97import utils
8+ from elections .urls import get_election_permissions
9+ from officers .models import PrivateOfficerResponse , PublicOfficerResponse
1010from officers .tables import OfficerInfo , OfficerTerm
1111from officers .types import InitialOfficerInfo , OfficerInfoUpload , OfficerTermUpload
1212from permission .types import OfficerPrivateInfo , WebsiteAdmin
1313from utils .urls import logged_in_or_raise
1414
15- _logger = logging .getLogger (__name__ )
16-
1715router = APIRouter (
1816 prefix = "/officers" ,
1917 tags = ["officers" ],
2523async def _has_officer_private_info_access (
2624 request : Request ,
2725 db_session : database .DBSession
28- ) -> tuple [None | str , None | str , bool ]:
26+ ) -> tuple [bool , str | None , ]:
2927 """determine if the user has access to private officer info"""
3028 session_id = request .cookies .get ("session_id" , None )
3129 if session_id is None :
32- return None , None , False
30+ return False , None
3331
3432 computing_id = await auth .crud .get_computing_id (db_session , session_id )
3533 if computing_id is None :
36- return session_id , None , False
34+ return False , None
3735
3836 has_private_access = await OfficerPrivateInfo .has_permission (db_session , computing_id )
39- return session_id , computing_id , has_private_access
37+ return has_private_access , computing_id
4038
4139# ---------------------------------------- #
4240# endpoints
4341
4442@router .get (
4543 "/current" ,
46- description = "Get information about all the officers. More information is given if you're authenticated & have access to private executive data." ,
44+ description = "Get information about the current officers. With no authorization, only get basic info." ,
45+ response_model = list [PrivateOfficerResponse ] | list [PublicOfficerResponse ],
46+ operation_id = "get_current_officers"
4747)
4848async def current_officers (
4949 # the request headers
5050 request : Request ,
5151 db_session : database .DBSession ,
5252):
53- _ , _ , has_private_access = await _has_officer_private_info_access (request , db_session )
53+ has_private_access , _ = await _has_officer_private_info_access (request , db_session )
5454 current_officers = await officers .crud .current_officers (db_session , has_private_access )
5555 return JSONResponse ({
5656 position : [
@@ -71,7 +71,7 @@ async def all_officers(
7171 # and may only be accessed by that officer and executives. All other officer terms are public.
7272 include_future_terms : bool = False ,
7373):
74- _ , computing_id , has_private_access = await _has_officer_private_info_access (request , db_session )
74+ has_private_access , computing_id = await _has_officer_private_info_access (request , db_session )
7575 if include_future_terms :
7676 is_website_admin = (computing_id is not None ) and (await WebsiteAdmin .has_permission (db_session , computing_id ))
7777 if not is_website_admin :
0 commit comments