Skip to content

Commit 4f6516c

Browse files
committed
fix semantics of updating inactive terms
1 parent 8e7b240 commit 4f6516c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/officers/crud.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ async def create_new_officer_term(
216216
# if new_officer_term.position not in OfficerPosition.position_list():
217217
# raise HTTPException(status_code=500)
218218

219+
# when creating a new position, assign a default end date if one exists
219220
position_length = OfficerPosition.length_in_semesters(new_officer_term.position)
220221
if position_length is not None:
221222
new_officer_term.end_date = semesters.step_semesters(

src/officers/urls.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,23 +324,20 @@ async def update_term(
324324
raise HTTPException(status_code=401, detail="must have website admin permissions to update another user")
325325

326326
if (
327-
not utils.is_active_term(old_officer_term)
327+
not utils.is_past_term(old_officer_term)
328328
and not await WebsiteAdmin.has_permission(db_session, session_computing_id)
329329
):
330-
raise HTTPException(status_code=401, detail="only website admin can update a non-active term")
330+
raise HTTPException(status_code=401, detail="only website admins can update past terms")
331331

332332
# NOTE: Only admins can write new versions of position, start_date, and end_date.
333333
if (
334-
(
335-
officer_term_upload.position != old_officer_term.position
336-
or officer_term_upload.start_date != old_officer_term.start_date
337-
or officer_term_upload.end_date != old_officer_term.end_date
338-
)
339-
and not await WebsiteAdmin.has_permission(db_session, session_computing_id)
340-
):
334+
officer_term_upload.position != old_officer_term.position
335+
or officer_term_upload.start_date != old_officer_term.start_date
336+
or officer_term_upload.end_date != old_officer_term.end_date
337+
) and not await WebsiteAdmin.has_permission(db_session, session_computing_id):
341338
raise HTTPException(status_code=401, detail="Non-admins cannot modify position, start_date, or end_date.")
342339

343-
# TODO: log all important changes just to a .log file
340+
# TODO: log all important changes to a .log file
344341
success = await officers.crud.update_officer_term(
345342
db_session,
346343
officer_term_upload.to_officer_term(term_id, old_officer_term.computing_id)

src/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ def is_active_term(term: OfficerTerm) -> bool:
4343
)
4444
)
4545

46+
def is_past_term(term: OfficerTerm) -> bool:
47+
"""Any term which has concluded"""
48+
return (
49+
# an officer with no end date is current
50+
term.end_date is not None
51+
# if today is past the end date, it's a past term
52+
and datetime.today() > term.end_date
53+
)
54+
4655
def is_valid_phone_number(phone_number: str) -> bool:
4756
return (
4857
len(phone_number) == 10

0 commit comments

Comments
 (0)