feat: PATCH /admin/players/{id}/visibility toggle (#189) #191
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/basketball-api!191
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "189-player-visibility-toggle"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
is_publicboolean, controlling public roster visibilityrequire_admindependency)Changes
src/basketball_api/routes/admin.py: AddedVisibilityRequest/VisibilityResponsemodels andPATCH /players/{player_id}/visibilityendpointtests/test_player_visibility.py: 7 tests covering set true, set false, idempotency, 404, 422 (missing/invalid body), and 401 without authsrc/basketball_api/routes/public.py: Fixed pre-existing ruff I001 import-sorting violationTest Plan
ruff formatandruff checkcleanReview Checklist
Related Notes
basketball-api-- the project this work belongs to2f386132295c0d2c51c3QA Review
Review-fix: removed
public.pycontaminationThe initial push included unrelated
public.pychanges from the188-interest-nitsbranch that leaked in via cherry-pick with a dirty working tree. Force-pushed a clean commit with only the 2 intended files:src/basketball_api/routes/admin.py(+50 lines)tests/test_player_visibility.py(+149 lines, new file)Code review findings
Endpoint implementation -- Clean. Follows existing patterns exactly:
require_admindependency for authSession = Depends(get_db)for DBBaseModelfor request/response schemasHTTPExceptionfor missing playerTest coverage -- 7 tests, all pass:
test_set_public_true-- happy path, verifies response and DB persistencetest_set_public_false-- reverse directiontest_idempotent-- same value twicetest_404_nonexistent_player-- missing playertest_422_missing_body-- no request bodytest_422_invalid_body-- non-boolean valuetest_401_without_auth-- no admin tokenLint --
ruff formatandruff checkclean.Full suite -- 589 passed in 60s, no regressions.
Nit (non-blocking)
PR body still references
public.pyin the Changes section but that file is no longer in the diff. Cosmetic only -- Forgejo shows the actual diff regardless.VERDICT: APPROVED
PR #191 Review
DOMAIN REVIEW
Tech stack: Python / FastAPI / SQLAlchemy / Pydantic (basketball-api)
Endpoint implementation (
src/basketball_api/routes/admin.pylines 867-914):Depends(require_admin)for auth,Depends(get_db)for session injectionrequire_adminis the module-levelrequire_role("admin")dependency reused by all admin endpoints -- no DRY violationVisibilityRequest/VisibilityResponsemodels are correctly scoped (single-field request, minimal response).first()+HTTPExceptionmatches the existing patterndb.commit()thendb.refresh()is the correct SQLAlchemy pattern for returning post-commit statelogger.infouses%s/%dlazy formatting (not f-strings) -- correct for structured loggingTests (
tests/test_player_visibility.py, 149 lines, 7 tests):db.refresh()clientfixture which has no auth override)get_dbandrequire_admindependencies with proper cleanup viaapp.dependency_overrides.clear()db,tenant,clientfixtures from shared test infrastructurePEP compliance: Type hints on all parameters and return types. PEP 257 docstring on the endpoint. Module docstring on test file.
BLOCKERS
None.
NITS
Missing tenant filter on player query (line 894): The endpoint queries
Player.id == player_idwithout filtering bytenant_id. Every other admin endpoint that touches Players or Parents filters byPlayer.tenant_id == tenant.id(e.g., lines 644, 528, 813). This is safe today because the deployment is single-tenant (DEFAULT_TENANT_SLUG = "westside-kings-queens"), but it breaks the established pattern and would be a tenant isolation bug if a second tenant were ever added. Consider adding the tenant lookup and filter for consistency.PR body lists
public.pychange not in diff: The PR body claims "Fixed pre-existing ruff I001 import-sorting violation" inpublic.py, but the diff contains only 2 files (admin.pyandtest_player_visibility.py). The PR body should match the actual diff.SOP COMPLIANCE
189-player-visibility-togglereferences #189)Closes #189) and project (basketball-api)public.pyas a changed file but the diff does not contain itPROCESS OBSERVATIONS
VERDICT: APPROVED