Skip to content

Commit 8c2048f

Browse files
authored
Make officers module more DRY (#94)
* add DELETE /term endpoint * fix and test delete term endpoint * switch to using date instead of datetime for officer term + cleaning * clean up todos * allow changing computing_id by admins * remove tests backend endpoints (use fe instead please) * fix tests and add basic endpoint tests * many small bug fixes * Update alembic.yml for python3.11 * add integration tests
1 parent 27907f7 commit 8c2048f

File tree

15 files changed

+594
-569
lines changed

15 files changed

+594
-569
lines changed

.github/workflows/alembic.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ jobs:
3232
3333
- name: Install dependencies
3434
run: |
35-
sudo apt-get install python3.11 python3.11-venv
35+
# for python3.11 (dear internet gods: we'll update to 3.13 or something in a year, i promise)
36+
sudo add-apt-repository ppa:deadsnakes/ppa
37+
sudo apt install python3.11 python3.11-venv
3638
python3.11 -m pip install --upgrade pip
3739
python3.11 -m venv venv
3840
source ./venv/bin/activate

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# major
2-
fastapi==0.109.1
2+
fastapi==0.115.6
33
gunicorn==21.2.0
44
uvicorn[standard]==0.27.1
55
sqlalchemy[asyncio]==2.0.27
@@ -19,3 +19,4 @@ ruff==0.6.9
1919
# test
2020
pytest
2121
pytest-asyncio
22+
httpx

src/alembic/versions/166f3772fce7_auth_officer_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def upgrade() -> None:
4242
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
4343
sa.Column("computing_id", sa.String(length=32), sa.ForeignKey("site_user.computing_id"), nullable=False),
4444
sa.Column("position", sa.String(length=128), nullable=False),
45-
sa.Column("start_date", sa.DateTime(), nullable=False),
46-
sa.Column("end_date", sa.DateTime(), nullable=True),
45+
sa.Column("start_date", sa.Date(), nullable=False),
46+
sa.Column("end_date", sa.Date(), nullable=True),
4747
sa.Column("nickname", sa.String(length=128), nullable=True),
4848
sa.Column("favourite_course_0", sa.String(length=32), nullable=True),
4949
sa.Column("favourite_course_1", sa.String(length=32), nullable=True),

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/load_test_db.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,9 @@ async def load_test_officers_data(db_session: AsyncSession):
212212
))
213213
await db_session.commit()
214214

215+
SYSADMIN_COMPUTING_ID = "gsa92"
215216
async def load_sysadmin(db_session: AsyncSession):
216217
# put your computing id here for testing purposes
217-
SYSADMIN_COMPUTING_ID = "gsa92"
218-
219218
print(f"loading new sysadmin '{SYSADMIN_COMPUTING_ID}'")
220219
await create_user_session(db_session, f"temp_id_{SYSADMIN_COMPUTING_ID}", SYSADMIN_COMPUTING_ID)
221220
await create_new_officer_info(db_session, OfficerInfo(
@@ -232,28 +231,11 @@ async def load_sysadmin(db_session: AsyncSession):
232231
await create_new_officer_term(db_session, OfficerTerm(
233232
computing_id=SYSADMIN_COMPUTING_ID,
234233

235-
position=OfficerPosition.SYSTEM_ADMINISTRATOR,
236-
start_date=date.today() - timedelta(days=365),
237-
end_date=None,
238-
239-
nickname="Gabe",
240-
favourite_course_0="CMPT 379",
241-
favourite_course_1="CMPT 295",
242-
243-
favourite_pl_0="Rust",
244-
favourite_pl_1="C",
245-
246-
biography="The systems are good o7",
247-
photo_url=None,
248-
))
249-
await create_new_officer_term(db_session, OfficerTerm(
250-
computing_id=SYSADMIN_COMPUTING_ID,
251-
252234
position=OfficerPosition.FIRST_YEAR_REPRESENTATIVE,
253235
start_date=date.today() - timedelta(days=(365*3)),
254236
end_date=date.today() - timedelta(days=(365*2)),
255237

256-
nickname="Gabe",
238+
nickname="G1",
257239
favourite_course_0="MACM 101",
258240
favourite_course_1="CMPT 125",
259241

@@ -270,7 +252,7 @@ async def load_sysadmin(db_session: AsyncSession):
270252
start_date=date.today() - timedelta(days=365),
271253
end_date=None,
272254

273-
nickname="Gabe",
255+
nickname="G2",
274256
favourite_course_0="CMPT 379",
275257
favourite_course_1="CMPT 295",
276258

@@ -280,6 +262,24 @@ async def load_sysadmin(db_session: AsyncSession):
280262
biography="The systems are good o7",
281263
photo_url=None,
282264
))
265+
# a future term
266+
await create_new_officer_term(db_session, OfficerTerm(
267+
computing_id=SYSADMIN_COMPUTING_ID,
268+
269+
position=OfficerPosition.DIRECTOR_OF_ARCHIVES,
270+
start_date=date.today() + timedelta(days=365*1),
271+
end_date=date.today() + timedelta(days=365*2),
272+
273+
nickname="G3",
274+
favourite_course_0="MACM 102",
275+
favourite_course_1="CMPT 127",
276+
277+
favourite_pl_0="C%",
278+
favourite_pl_1="C$$",
279+
280+
biography="o hey fellow kids \n\n\n I will can newline .... !!",
281+
photo_url=None,
282+
))
283283
await db_session.commit()
284284

285285
async def async_main(sessionmanager):

src/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import database
77
import officers.urls
88
import permission.urls
9-
import tests.urls
109

1110
logging.basicConfig(level=logging.DEBUG)
1211
database.setup_database()
@@ -17,8 +16,6 @@
1716
app.include_router(officers.urls.router)
1817
app.include_router(permission.urls.router)
1918

20-
app.include_router(tests.urls.router)
21-
2219
@app.get("/")
2320
async def read_root():
2421
return {"message": "Hello! You might be lost, this is actually the sfucsss.org's backend api."}

src/officers/constants.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def position_list() -> list[str]:
2828

2929
@staticmethod
3030
def length_in_semesters(position: str) -> int | None:
31-
# TODO: ask the committee to maintain a json file with all the important details from the constitution
32-
# (I can create the version version of the file)
31+
# TODO (#101): ask the committee to maintain a json file with all the important details from the constitution
3332
"""How many semester position is active for, according to the CSSS Constitution"""
3433
return _LENGTH_MAP[position]
3534

@@ -71,6 +70,7 @@ def is_signer(position: str) -> bool:
7170

7271
@staticmethod
7372
def expected_positions() -> list[str]:
73+
# TODO (#93): use this function in the daily cronjobs
7474
return [
7575
OfficerPosition.PRESIDENT,
7676
OfficerPosition.VICE_PRESIDENT,
@@ -81,11 +81,11 @@ def expected_positions() -> list[str]:
8181
OfficerPosition.DIRECTOR_OF_EDUCATIONAL_EVENTS,
8282
OfficerPosition.ASSISTANT_DIRECTOR_OF_EVENTS,
8383
OfficerPosition.DIRECTOR_OF_COMMUNICATIONS,
84-
#OfficerPosition.DIRECTOR_OF_OUTREACH, # TODO: when https://github.com/CSSS/documents/pull/9/files merged
84+
#OfficerPosition.DIRECTOR_OF_OUTREACH, # TODO (#101): when https://github.com/CSSS/documents/pull/9/files merged
8585
OfficerPosition.DIRECTOR_OF_MULTIMEDIA,
8686
OfficerPosition.DIRECTOR_OF_ARCHIVES,
8787
OfficerPosition.EXECUTIVE_AT_LARGE,
88-
# TODO: expect these only during fall & spring semesters. Also, TODO: this todo is correct...
88+
# TODO (#101): expect these only during fall & spring semesters.
8989
#OfficerPosition.FIRST_YEAR_REPRESENTATIVE,
9090

9191
#ElectionsOfficer,
@@ -121,8 +121,6 @@ def expected_positions() -> list[str]:
121121
OfficerPosition.SOCIAL_MEDIA_MANAGER: "N/A",
122122
}
123123

124-
# TODO: when an officer's start date is modified, update the end date as well if it's defined in this list
125-
# a number of semesters (a semester begins on the 1st of each four month period, starting january)
126124
# None, means that the length of the position does not have a set length in semesters
127125
_LENGTH_MAP = {
128126
OfficerPosition.PRESIDENT: 3,

0 commit comments

Comments
 (0)