Skip to content

Commit 58b2094

Browse files
authored
Update: Fetching elections as an admin gets you private details (#117)
1 parent c9f6c1e commit 58b2094

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/elections/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ElectionModel(BaseModel):
1616
datetime_start_voting: str
1717
datetime_end_voting: str
1818
available_positions: str
19-
survey_link: str | None
19+
survey_link: str | None = None
2020

2121
class NomineeInfoModel(BaseModel):
2222
computing_id: str

src/elections/urls.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ async def _validate_user(
4848
response_model=list[ElectionModel]
4949
)
5050
async def list_elections(
51-
_: Request,
51+
request: Request,
5252
db_session: database.DBSession,
5353
):
54+
is_admin, _, _ = await _validate_user(request, db_session)
5455
election_list = await elections.crud.get_all_elections(db_session)
5556
if election_list is None or len(election_list) == 0:
5657
raise HTTPException(
@@ -59,10 +60,16 @@ async def list_elections(
5960
)
6061

6162
current_time = datetime.now()
62-
election_metadata_list = [
63-
election.public_metadata(current_time)
64-
for election in election_list
65-
]
63+
if is_admin:
64+
election_metadata_list = [
65+
election.private_details(current_time)
66+
for election in election_list
67+
]
68+
else:
69+
election_metadata_list = [
70+
election.public_details(current_time)
71+
for election in election_list
72+
]
6673

6774
return JSONResponse(election_metadata_list)
6875

src/permission/types.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from fastapi import HTTPException
55

66
import database
7-
import elections.crud
87
import officers.constants
98
import officers.crud
109
import utils
@@ -52,7 +51,7 @@ async def has_permission(db_session: database.DBSession, computing_id: str) -> b
5251
return False
5352

5453
class WebsiteAdmin:
55-
WEBSITE_ADMIN_POSITIONS: ClassVar[list[OfficerPosition]] = [
54+
WEBSITE_ADMIN_POSITIONS: ClassVar[list[str]] = [
5655
OfficerPosition.PRESIDENT,
5756
OfficerPosition.VICE_PRESIDENT,
5857
OfficerPosition.DIRECTOR_OF_ARCHIVES,

0 commit comments

Comments
 (0)