Skip to content

Commit 2751dec

Browse files
committed
remove comments, make names more consistent
1 parent 6794ec1 commit 2751dec

File tree

4 files changed

+26
-54
lines changed

4 files changed

+26
-54
lines changed

src/cron/daily.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import google_api
88
import utils
99
from database import _db_session
10-
from officers.crud import all_officer_data, get_user_by_username
10+
from officers.crud import all_officers, get_user_by_username
1111

1212
_logger = logging.getLogger(__name__)
1313

@@ -18,7 +18,7 @@ async def update_google_permissions(db_session):
1818

1919
# TODO: for performance, only include officers with recent end-date (1 yr)
2020
# but measure performance first
21-
for term in await all_officer_data(db_session):
21+
for term in await all_officers(db_session):
2222
if utils.is_active(term):
2323
# TODO: if google drive permission is not active, update them
2424
pass
@@ -31,7 +31,7 @@ async def update_google_permissions(db_session):
3131
async def update_github_permissions(db_session):
3232
github_permissions, team_id_map = github.all_permissions()
3333

34-
for term in await all_officer_data(db_session):
34+
for term in await all_officers(db_session):
3535
new_teams = (
3636
# move all active officers to their respective teams
3737
github.officer_teams(term.position)

src/officers/crud.py

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ async def get_officer_terms(
9090

9191
return (await db_session.scalars(query)).all()
9292

93-
async def current_executive_team(db_session: database.DBSession, include_private: bool) -> dict[str, list[OfficerData]]:
93+
async def current_officers(
94+
db_session: database.DBSession,
95+
include_private: bool
96+
) -> dict[str, list[OfficerData]]:
9497
"""
9598
Get info about officers that are active. Go through all active & complete officer terms.
9699
@@ -104,17 +107,8 @@ async def current_executive_team(db_session: database.DBSession, include_private
104107
query = utils.is_active_officer(query)
105108

106109
officer_terms = (await db_session.scalars(query)).all()
107-
##num_officers = {}
108110
officer_data = {}
109111
for term in officer_terms:
110-
"""
111-
if term.position not in OfficerPosition.position_list():
112-
_logger.warning(
113-
f"Unknown OfficerTerm.position={term.position} in database. Ignoring in request."
114-
)
115-
continue
116-
"""
117-
118112
officer_info_query = (
119113
sqlalchemy
120114
.select(OfficerInfo)
@@ -124,43 +118,16 @@ async def current_executive_team(db_session: database.DBSession, include_private
124118
if officer_info is None:
125119
# TODO: make sure there are daily checks that this data actually exists
126120
continue
127-
128-
if term.position not in officer_data:
129-
##num_officers[term.position] = 0
121+
elif term.position not in officer_data:
130122
officer_data[term.position] = []
131123

132-
"""
133-
num_officers[term.position] += 1
134-
# TODO: move this to a daily cronjob
135-
if num_officers[term.position] > OfficerPosition.num_active(term.position):
136-
# If there are more active positions than expected, log it to a file
137-
_logger.warning(
138-
f"There are more active {term.position} positions in the OfficerTerm than expected "
139-
f"({num_officers[term.position]} > {OfficerPosition.num_active(term.position)})"
140-
)
141-
"""
142-
officer_data[term.position] += [OfficerData.from_data(term, officer_info, include_private, is_active=True)]
124+
officer_data[term.position] += [
125+
OfficerData.from_data(term, officer_info, include_private, is_active=True)
126+
]
143127

144-
"""
145-
# validate & warn if there are any data issues
146-
# TODO: decide whether we should enforce empty instances or force the frontend to deal with it
147-
for position in OfficerPosition.expected_positions():
148-
if position not in officer_data:
149-
_logger.warning(
150-
f"Expected position={position} in response current_executive_team."
151-
)
152-
elif (
153-
OfficerPosition.num_active(position) is not None
154-
and len(officer_data[position]) != OfficerPosition.num_active(position)
155-
):
156-
_logger.warning(
157-
f"Unexpected number of {position} entries "
158-
f"({len(officer_data[position])} entries) in current_executive_team response."
159-
)
160-
"""
161128
return officer_data
162129

163-
async def all_officer_data(
130+
async def all_officers(
164131
db_session: database.DBSession,
165132
include_private_data: bool,
166133
view_not_started_officer_terms: bool,

src/officers/urls.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
tags=["officers"],
2626
)
2727

28+
# ---------------------------------------- #
29+
# checks
30+
2831
async def has_officer_private_info_access(
2932
request: Request,
3033
db_session: database.DBSession,
@@ -41,6 +44,9 @@ async def has_officer_private_info_access(
4144
has_private_access = await OfficerPrivateInfo.has_permission(db_session, computing_id)
4245
return session_id, computing_id, has_private_access
4346

47+
# ---------------------------------------- #
48+
# endpoints
49+
4450
@router.get(
4551
"/current",
4652
description="Get information about all the officers. More information is given if you're authenticated & have access to private executive data.",
@@ -51,12 +57,11 @@ async def current_officers(
5157
db_session: database.DBSession,
5258
):
5359
_, _, has_private_access = await has_officer_private_info_access(request, db_session)
54-
55-
current_executives = await officers.crud.current_executive_team(db_session, has_private_access)
60+
current_officers = await officers.crud.current_officers(db_session, has_private_access)
5661
json_current_executives = {
5762
position: [
5863
officer_data.serializable_dict() for officer_data in officer_data_list
59-
] for position, officer_data_list in current_executives.items()
64+
] for position, officer_data_list in current_officers.items()
6065
}
6166

6267
return JSONResponse(json_current_executives)
@@ -78,10 +83,10 @@ async def all_officers(
7883
if not is_website_admin:
7984
raise HTTPException(status_code=401, detail="only website admins can view all executive terms that have not started yet")
8085

81-
all_officer_data = await officers.crud.all_officer_data(db_session, has_private_access, not view_not_started_officer_terms)
86+
all_officers = await officers.crud.all_officers(db_session, has_private_access, not view_not_started_officer_terms)
8287
return JSONResponse([
8388
officer_data.serializable_dict()
84-
for officer_data in all_officer_data
89+
for officer_data in all_officers
8590
])
8691

8792
@router.get(

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_data, current_executive_team, most_recent_officer_term
8+
from officers.crud import all_officers, current_officers, 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)
@@ -39,15 +39,15 @@ async def test__read_execs(database_setup):
3939
assert abc11_officer_term.favourite_course_0 == "CMPT 361"
4040
assert abc11_officer_term.biography == "Hi! I'm person A and I want school to be over ; _ ;"
4141

42-
current_exec_team = await current_executive_team(db_session, include_private=False)
42+
current_exec_team = await current_officers(db_session, include_private=False)
4343
assert current_exec_team is not None
4444
assert len(current_exec_team.keys()) == 1
4545
assert next(iter(current_exec_team.keys())) == OfficerPosition.PRESIDENT
4646
assert next(iter(current_exec_team.values()))[0].favourite_course_0 == "CMPT 999"
4747
assert next(iter(current_exec_team.values()))[0].csss_email == OfficerPosition.President.to_email()
4848
assert next(iter(current_exec_team.values()))[0].private_data is None
4949

50-
current_exec_team = await current_executive_team(db_session, include_private=True)
50+
current_exec_team = await current_officers(db_session, include_private=True)
5151
assert current_exec_team is not None
5252
assert len(current_exec_team) == 1
5353
assert next(iter(current_exec_team.keys())) == OfficerPosition.PRESIDENT
@@ -56,7 +56,7 @@ async def test__read_execs(database_setup):
5656
assert next(iter(current_exec_team.values()))[0].private_data is not None
5757
assert next(iter(current_exec_team.values()))[0].private_data.computing_id == "abc33"
5858

59-
all_terms = await all_officer_data(db_session, include_private=True)
59+
all_terms = await all_officers(db_session, include_private=True)
6060
assert len(all_terms) == 3
6161

6262

0 commit comments

Comments
 (0)