Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/elections/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum

from pydantic import BaseModel
from pydantic import BaseModel, Field


class ElectionTypeEnum(str, Enum):
Expand All @@ -16,7 +16,7 @@ class ElectionModel(BaseModel):
datetime_start_voting: str
datetime_end_voting: str
available_positions: str
survey_link: str | None
survey_link: str | None = Field(None)

class NomineeInfoModel(BaseModel):
computing_id: str
Expand Down
17 changes: 12 additions & 5 deletions src/elections/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ async def _validate_user(
response_model=list[ElectionModel]
)
async def list_elections(
_: Request,
request: Request,
db_session: database.DBSession,
):
is_admin, _, _ = await _validate_user(request, db_session)
election_list = await elections.crud.get_all_elections(db_session)
if election_list is None or len(election_list) == 0:
raise HTTPException(
Expand All @@ -59,10 +60,16 @@ async def list_elections(
)

current_time = datetime.now()
election_metadata_list = [
election.public_metadata(current_time)
for election in election_list
]
if is_admin:
election_metadata_list = [
election.private_details(current_time)
for election in election_list
]
else:
election_metadata_list = [
election.public_details(current_time)
for election in election_list
]

return JSONResponse(election_metadata_list)

Expand Down
3 changes: 1 addition & 2 deletions src/permission/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from fastapi import HTTPException

import database
import elections.crud
import officers.constants
import officers.crud
import utils
Expand Down Expand Up @@ -52,7 +51,7 @@ async def has_permission(db_session: database.DBSession, computing_id: str) -> b
return False

class WebsiteAdmin:
WEBSITE_ADMIN_POSITIONS: ClassVar[list[OfficerPosition]] = [
WEBSITE_ADMIN_POSITIONS: ClassVar[list[str]] = [
OfficerPosition.PRESIDENT,
OfficerPosition.VICE_PRESIDENT,
OfficerPosition.DIRECTOR_OF_ARCHIVES,
Expand Down