Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c8ead80
chore(pyproject): update install steps and change to using uv
jbriones1 Dec 17, 2025
e6f1072
fix: python version pinned to 3.11
jbriones1 Dec 17, 2025
0d4ce6c
chore(gitignore): update gitignore with uv items
jbriones1 Dec 17, 2025
b7c305f
chore(pyright): update pyright config to use version 3.11
jbriones1 Dec 17, 2025
c94aa06
chore(format): ignore alembic migrations
jbriones1 Dec 17, 2025
a721e4f
chore(format): ran the formatter over the entire project
jbriones1 Dec 17, 2025
df0f490
fix(ci): fix script to not rely on requirements.txt
jbriones1 Dec 17, 2025
01cb9f4
fix(ci): split test and dev dependencies again, update action script
jbriones1 Dec 17, 2025
8fe4e74
fix(ci): removed requirements.txt requirement
jbriones1 Dec 17, 2025
5ab91f4
fix(uv): update uv.lock to current state
jbriones1 Dec 17, 2025
f571eb3
refactor(permissions): rewrote permissions to integrate admin types
jbriones1 Dec 18, 2025
74bc701
fix: type errors in officers crud
jbriones1 Dec 18, 2025
4873317
refactor(permissions): restructured most endpoints to use Depends
jbriones1 Dec 18, 2025
6c880e1
fix(tests): whole test suite can now be run
jbriones1 Dec 18, 2025
268fd97
fix: missing awaits on permission check calls
jbriones1 Dec 19, 2025
69469e1
fix(officers): tests now all work
jbriones1 Dec 19, 2025
6e39610
fix: move `conftest.py` to only work on integrations tests
jbriones1 Dec 19, 2025
3eeaebc
wip: add GET all registrations
jbriones1 Sep 27, 2025
150f08c
wip(nominee): add create endpoint
jbriones1 Sep 27, 2025
32a3ee0
wip: add GET all nominees
jbriones1 Sep 27, 2025
8492ff0
wip: add DELETE nominee_info
jbriones1 Sep 27, 2025
3fa406a
fix(Elections): duplicate operation id in nominees URLs
jbriones1 Sep 28, 2025
95ad68e
fix: patch to put
jbriones1 Sep 28, 2025
a751e67
fix: election tests now work
jbriones1 Dec 19, 2025
56f3585
fix(tests): add missing param types
jbriones1 Dec 20, 2025
f8824f7
refactor: split election tests into multiple functions
jbriones1 Dec 20, 2025
96ca71c
fix(tests): split admin elections tests
jbriones1 Dec 20, 2025
a34a3c4
fix(permissions): fixed some permission tests to be more efficient
jbriones1 Dec 20, 2025
e95efd9
refactor: update Nominee model names
jbriones1 Dec 20, 2025
0f2a339
fix(elections): fix all elections tests
jbriones1 Dec 21, 2025
af31465
fix(registrations): change return type to list
jbriones1 Dec 21, 2025
a1dc6b3
fix(registration): fix list being sent as a JSON response
jbriones1 Dec 21, 2025
812185e
fix(registratio): removed enum check
jbriones1 Dec 21, 2025
efa5042
fix(registration): changed search to a single registration
jbriones1 Dec 21, 2025
512bc66
refactor(officers): response for current officers changed to list
jbriones1 Dec 27, 2025
1d7a4c9
fix(officers): tests that expect a dict response for current officers
jbriones1 Dec 27, 2025
908e6ad
fix(Officers): merged the public and private models
jbriones1 Dec 27, 2025
316c1b6
chore(OfficerInfoDB): remove unused methods
jbriones1 Dec 27, 2025
2e4ce2c
fix(test): user client is now module scoped
jbriones1 Dec 27, 2025
6b4fc15
fix(officers): model fields use OfficerPositionEnum
jbriones1 Dec 27, 2025
bd9e3ad
refactor: made a computed field
jbriones1 Dec 27, 2025
6f7d55a
fix(officers): term_id added to Officer response, id is now an int
jbriones1 Dec 27, 2025
6293336
refactor: rename OfficerUpdate to OfficerInfoUpdate
jbriones1 Dec 27, 2025
91941f9
refactor: change csss_email to a computed field
jbriones1 Dec 27, 2025
846446c
chore(officers): delete old types
jbriones1 Dec 27, 2025
49a3c9b
fix: remove csss_email
jbriones1 Dec 27, 2025
68a5eba
fix: check that end_date is null for current officers
jbriones1 Dec 27, 2025
2b44419
fix: tests failed after the check for current admin changed
jbriones1 Dec 27, 2025
68758d1
refactor(elections): Election to ElectionDB
jbriones1 Dec 28, 2025
a9ffd2f
fix: election models now use timezone naive datetimes
jbriones1 Dec 28, 2025
5331eb9
fix: made all timestamps timezone aware, UTC stored now
jbriones1 Dec 30, 2025
12bd99f
fix(blogs): blogs are now timezone aware
jbriones1 Dec 30, 2025
141a9ae
chore(tables): rename the rest of the DB tables
jbriones1 Dec 30, 2025
8f585f1
chore: ruff fix unsorted imports
jbriones1 Dec 30, 2025
1f1c8f0
refactor(nominee): update nominee models and PATCH request
jbriones1 Dec 31, 2025
5f3cdb6
refactor(candidates): renamed registrations to candidates
jbriones1 Dec 31, 2025
17c0c67
fix(alembic): registration renamed to candidates
jbriones1 Dec 31, 2025
43a0cf6
fix(nominee): update POST to use create model
jbriones1 Dec 31, 2025
bf9fe64
fix(candidates): missed some renames
jbriones1 Dec 31, 2025
1a6ac99
fix(candidates): updating a candidate with the same position failed
jbriones1 Dec 31, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/alembic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
python3.11 -m pip install --upgrade pip
python3.11 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
pip install .

# This will fail if there are divergent heads and alembic gets confused;
# e.g., un-sanitarily merging main into a dev branch.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
python -m pip install --upgrade pip
python -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
pip install ".[test]"

- name: Run unit tests
run: PYTHONPATH=src ./venv/bin/python -m pytest ./tests/unit -v
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ google_key.json
# Python - Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
build/
dist/
wheels
*.egg-info/
*$py.class

.venv
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ See [the csss-backend wiki](https://github.com/CSSS/csss-site-backend/wiki/1.-Lo

If you're planning to read through the source code, please check out this project's [naming conventions](https://github.com/CSSS/csss-site-backend/wiki/Style-Guide#naming-conventions).

### Quickstart

1. Install [Python 3.11](https://www.python.org/downloads/), [git](https://git-scm.com/install/), and (optionally) [Docker](https://www.docker.com/get-started/)
Note: This may fail if you're using Python 3.12+
2. Clone this repository
3. Create and activate a virtual environment for this project. This has been tested with `pip` and `uv`
4. Install developer dependencies
```bash
# Install main dependencies
pip install . # or: uv pip install .

# Install with dev dependencies
pip install ".[dev]" # or: uv pip install ".[dev]"

# Install with test dependencies
pip install ".[test]" # or: uv pip install ".[test]"

# Install with all dependencies
pip install ".[dev, test]" # or: uv pip install ".[dev, test]"
```

5. Follow the database setup instructions on the [wiki](https://github.com/CSSS/csss-site-backend/wiki/1.-Local-Setup#database-setup). The recommended way is to do it through Docker, but both should work.
6. You will need to set the following environment variables
```bash
export DB_PORT=5444 # The port your database is listening at
export LOCAL=true # Should be true if you're running this locally
```


## Important Directories

- `config/` configuration files for the server machine
Expand All @@ -26,6 +55,7 @@ If you're planning to read through the source code, please check out this projec
- `officers/` for officer contact information + photos
- `test/` for html pages which interact with the backend's local api

## Linter
## Developer Tools

We use `ruff 0.6.9` as our linter, which you can run with `ruff check --fix`. If you use a different version, it may be inconsistent with our CI checks.
We use `pyright/basedpyright` for typechecking. Language services have been left enabled and will be changed if it becomes an issue.
44 changes: 41 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
[project]
name = "csss-site-backend"
version = "0.1"
requires-python = ">= 3.11" # older versions untested, but we use new features often
requires-python = "~=3.11.0" # older versions untested, but we use new features often

dependencies = [
# major
"fastapi==0.115.6",
"gunicorn==21.2.0",
"uvicorn[standard]==0.27.1",
"sqlalchemy[asyncio]==2.0.27",
"asyncpg==0.29.0",
"alembic==1.13.1",
"google-api-python-client==2.143.0",

# minor
"pyOpenSSL==24.0.0", # for generating cryptographically secure random numbers
"xmltodict==0.13.0",
"requests==2.31.0",
]

[project.optional-dependencies]
dev = [
"ruff==0.6.9", # linting and formatter
]

test = [
"pytest", # test framework
"pytest-asyncio",
"httpx",
]

[project.urls]
Homepage = "https://api.sfucsss.org/"

# Pytest: Test framework
[tool.pytest.ini_options]
pythonpath = ["src"]
log_cli = true
log_cli_level = "INFO"
testpaths = [
"tests",
]
]
norecursedirs = "tests/wip"
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

# Ruff: Formatter and linter
[tool.ruff]
line-length = 120
indent-width = 4
target-version = "py311"
exclude = [
"src/alembic/*"
]

[tool.ruff.format]
quote-style = "double"
Expand All @@ -31,6 +63,12 @@ line-ending = "lf"
select = ["E", "F", "B", "I", "N", "UP", "A", "PTH", "W", "RUF", "C4", "PIE", "Q", "FLY"] # "ANN"
ignore = ["E501", "F401", "N806"]

# [Based]Pyright: Type checker/LSP
[tool.pyright]
executionEnvironments = [{ root = "src" }]
executionEnvironments = [
{ root = "src", pythonVersion = "3.11" },
{ root = "tests", extraPaths=["src"], pythonVersion = "3.11" }
]
typeCheckingMode = "standard"
reportAny = "none" # Allow the use of `Any` type
reportExplicitAny = "none" # Allow the declaration of `Any` type
22 changes: 0 additions & 22 deletions requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import dependencies
2 changes: 1 addition & 1 deletion src/admin/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
GMAIL_ADDRESS = "csss-site@gmail.com"
GMAIL_USERNAME = ""


# TODO: look into sending emails from an sfu maillist (this might be painful)
def send_email(
recipient_address: str,
Expand All @@ -22,4 +23,3 @@ def send_email(

mail.sendmail(GMAIL_ADDRESS, recipient_address, content)
mail.quit()

5 changes: 4 additions & 1 deletion src/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import elections.tables
import nominees.tables
import officers.tables
import registrations.tables
import candidates.tables
from alembic import context

# this is the Alembic Config object, which provides
Expand Down Expand Up @@ -62,6 +62,9 @@ async def run_async_migrations() -> None:
and associate a connection with the context.
"""
configuration = config.get_section(config.config_ini_section)
if not configuration:
return

configuration["sqlalchemy.url"] = database.SQLALCHEMY_DATABASE_URL
connectable = async_engine_from_config(
configuration,
Expand Down
53 changes: 0 additions & 53 deletions src/alembic/versions/0c717bd88d06_elections_timestamp_datetime.py

This file was deleted.

6 changes: 3 additions & 3 deletions src/alembic/versions/166f3772fce7_auth_officer_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def upgrade() -> None:
op.create_table(
"site_user",
sa.Column("computing_id", sa.String(32), primary_key=True),
sa.Column("first_logged_in", sa.DateTime, nullable=False, default=datetime(2024, 6, 16)),
sa.Column("last_logged_in", sa.DateTime, nullable=False, default=datetime(2024, 6, 16)),
sa.Column("first_logged_in", sa.DateTime(timezone=True), nullable=True),
sa.Column("last_logged_in", sa.DateTime(timezone=True), nullable=True),
sa.Column("profile_picture_url", sa.Text(), nullable=True),
)
op.create_table(
"user_session",
# NOTE: order is important; site_user must be created first!
sa.Column("computing_id", sa.String(32), sa.ForeignKey("site_user.computing_id"), primary_key=True),
sa.Column("issue_time", sa.DateTime, nullable=False),
sa.Column("issue_time", sa.DateTime(timezone=True), nullable=False),
sa.Column("session_id", sa.String(512), nullable=False, unique=True),
)

Expand Down
6 changes: 3 additions & 3 deletions src/alembic/versions/243190df5588_create_election_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def upgrade() -> None:
sa.Column("slug", sa.String(length=64), nullable=False),
sa.Column("name", sa.String(length=64), nullable=False),
sa.Column("type", sa.String(length=64), default="general_election"),
sa.Column("datetime_start_nominations", sa.DateTime(), nullable=False),
sa.Column("datetime_start_voting", sa.DateTime(), nullable=False),
sa.Column("datetime_end_voting", sa.DateTime(), nullable=False),
sa.Column("datetime_start_nominations", sa.DateTime(timezone=True), nullable=False),
sa.Column("datetime_start_voting", sa.DateTime(timezone=True), nullable=False),
sa.Column("datetime_end_voting", sa.DateTime(timezone=True), nullable=False),
sa.Column("available_positions", sa.Text(), nullable=False),
sa.Column("survey_link", sa.String(length=300), nullable=True),
sa.PrimaryKeyConstraint("slug")
Expand Down
4 changes: 2 additions & 2 deletions src/alembic/versions/2a6ea95342dc_blog_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def upgrade() -> None:
op.create_table("blog_posts",
sa.Column("title", sa.String(length=128), primary_key=True, nullable=False),
sa.Column("computing_id", sa.String(length=32), sa.ForeignKey("officer_info.computing_id"), nullable=False),
sa.Column("date_created", sa.DateTime(), nullable=False),
sa.Column("last_edited", sa.DateTime(), nullable=False),
sa.Column("date_created", sa.DateTime(timezone=True), nullable=False),
sa.Column("last_edited", sa.DateTime(timezone=True), nullable=False),
sa.Column("html_content", sa.Text(), nullable=False),
sa.Column("post_tags", sa.String(length=128), nullable=True),
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""update_officer_term_constraint_71

Revision ID: a5c42bcdda5c
Revises: 876041e5b41c
Revises: 243190df5588
Create Date: 2025-09-28 18:03:54.856781

"""
Expand All @@ -13,7 +13,7 @@

# revision identifiers, used by Alembic.
revision: str = "a5c42bcdda5c"
down_revision: str | None = "876041e5b41c"
down_revision: str | None = "243190df5588"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None

Expand Down
1 change: 1 addition & 0 deletions src/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from auth import crud
Loading