Skip to content

Commit 4fc04da

Browse files
committed
clean naming again
1 parent c7255fd commit 4fc04da

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/officers/crud.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
_logger = logging.getLogger(__name__)
1717

1818

19-
async def most_recent_exec_term(db_session: database.DBSession, computing_id: str) -> OfficerTerm | None:
19+
async def most_recent_officer_term(db_session: database.DBSession, computing_id: str) -> OfficerTerm | None:
2020
"""
21-
Returns the most recent OfficerTerm an exec has had
21+
Returns the most recent OfficerTerm an exec has held
2222
"""
2323
query = (
2424
sqlalchemy
@@ -31,16 +31,15 @@ async def most_recent_exec_term(db_session: database.DBSession, computing_id: st
3131

3232
async def current_officer_positions(db_session: database.DBSession, computing_id: str) -> list[str]:
3333
"""
34-
Returns [] if the user is not currently an officer.
34+
Returns the list of officer positions a user currently has. Returns [] if the user is not currently an officer.
3535
36-
Gets positions ordered most recent start date first.
37-
38-
An officer can have multiple positions, such as Webmaster, Frosh chair, and DoEE.
36+
An officer can have multiple positions at once, such as Webmaster, Frosh chair, and DoEE.
3937
"""
4038
query = (
4139
sqlalchemy
4240
.select(OfficerTerm)
4341
.where(OfficerTerm.computing_id == computing_id)
42+
# In order of most recent start date first
4443
.order_by(OfficerTerm.start_date.desc())
4544
)
4645
query = utils.is_active_officer(query)

src/permission/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ async def has_permission(db_session: database.DBSession, computing_id: str) -> b
1818
A semester is defined in semester_start
1919
"""
2020

21-
most_recent_exec_term = await officers.crud.most_recent_exec_term(db_session, computing_id)
22-
if most_recent_exec_term is None:
21+
term = await officers.crud.most_recent_officer_term(db_session, computing_id)
22+
if term is None:
2323
return False
24-
elif most_recent_exec_term.end_date is None:
24+
elif term.end_date is None:
2525
# considered an active exec if no end_date
2626
return True
2727

@@ -30,7 +30,7 @@ async def has_permission(db_session: database.DBSession, computing_id: str) -> b
3030
NUM_SEMESTERS = 5
3131
cutoff_date = step_semesters(semester_start, -NUM_SEMESTERS)
3232

33-
return most_recent_exec_term.end_date > cutoff_date
33+
return term.end_date > cutoff_date
3434

3535
class WebsiteAdmin:
3636
WEBSITE_ADMIN_POSITIONS: ClassVar[list[OfficerPosition]] = [

tests/integration/test_officers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import load_test_db
66
from database import SQLALCHEMY_TEST_DATABASE_URL, DatabaseSessionManager
77
from officers.constants import OfficerPosition
8-
from officers.crud import all_officer_terms, current_executive_team, most_recent_exec_term
8+
from officers.crud import all_officer_terms, current_executive_team, most_recent_officer_term
99

1010
# TODO: setup a database on the CI machine & run this as a unit test then (since
1111
# this isn't really an integration test)
@@ -27,9 +27,9 @@ async def test__read_execs(database_setup):
2727
sessionmanager = await database_setup
2828
async with sessionmanager.session() as db_session:
2929
# test that reads from the database succeeded as expected
30-
assert (await most_recent_exec_term(db_session, "blarg")) is None
31-
assert await most_recent_exec_term(db_session, "abc22") is None
32-
abc11_officer_term = await most_recent_exec_term(db_session, "abc11")
30+
assert (await most_recent_officer_term(db_session, "blarg")) is None
31+
assert await most_recent_officer_term(db_session, "abc22") is None
32+
abc11_officer_term = await most_recent_officer_term(db_session, "abc11")
3333

3434
assert abc11_officer_term.computing_id == "abc11"
3535
assert abc11_officer_term.position == OfficerPosition.EXECUTIVE_AT_LARGE

0 commit comments

Comments
 (0)