Skip to content

Add site settings with per-key validation and a public API (W2-04) #49 - #64

Merged
calebyhan merged 3 commits into
mainfrom
BrianRyu-site-settings
Oct 25, 2026
Merged

calebyhan merged 3 commits into
mainfrom
BrianRyu-site-settings

Conversation

@BrianRyu04

Copy link
Copy Markdown
Contributor

Single values like the tagline, contact email, Instagram handle, responder form link, SMS number, and launch date need to be editable by coordinators without a deploy (TDD 4.5.3). Each key has its own Pydantic type so a typo in the editor can't break the site. This PR adds the table, the key registry, and the public read endpoint. The admin editor comes later.

Changes:

  • Added the SiteSetting model (key primary key, JSONB value, nullable updated_by, updated_at) and its migration, so settings can be stored and edited.
  • Added services/site_settings.py with a SETTINGS registry. Each entry has a Pydantic type (checked with TypeAdapter), a default, a public flag, and a description for the future editor. Adding a key later (like retention_days) is one new entry.
  • Added get_setting, which returns the stored value if it's valid and otherwise the default. Unknown keys raise KeyError.
  • Added set_setting, which validates and upserts, and raises a validation error for bad values. It flushes instead of committing, matching the other services, so callers own the transaction.
  • Added GET /api/settings returning SiteSettingsDTO (TDD 4.7.1) with public keys only. line_launch_at is not public because the status endpoint will serve it.
  • Registered a dev seed with sample values (tagline and responder form URL). The seed module is imported inside seed_dev() so the registration actually runs.
  • Added pydantic[email] for email validation.
  • Added tests in test_site_settings.py for defaults, stored values winning over defaults, rejecting a bad email and a non-URL, and non-public keys never appearing in GET /api/settings.

Notes for reviewers:

  • The migration chains off fe7f9cc864a9 and alembic heads shows a single head. I regenerated it once after removing an empty revision from a failed first attempt.
  • The form URL in the seed is a placeholder. Swap in the real link if we have one.

Closes #49

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Backend Test Results

154 tests  +6   154 ✅ +6   1s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit f584f56. ± Comparison against base commit bf72391.

♻️ This comment has been updated with latest results.

@calebyhan

Copy link
Copy Markdown
Collaborator

there are merge conflicts, and also for the PR title you just need to copy the issue title @BrianRyu04

@BrianRyu04 BrianRyu04 changed the title #49 Add site settings table, registry, and GET /api/settings Add site settings with per-key validation and a public API (W2-04) #49 Oct 22, 2026

@calebyhan calebyhan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@calebyhan
calebyhan merged commit adb88b9 into main Oct 25, 2026
4 checks passed
@calebyhan
calebyhan deleted the BrianRyu-site-settings branch October 25, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add site settings with per-key validation and a public API (W2-04)

2 participants