Skip to content

Implement class join codes#789

Draft
fspeirs wants to merge 14 commits intomainfrom
fs-implement-class-join-codes
Draft

Implement class join codes#789
fspeirs wants to merge 14 commits intomainfrom
fs-implement-class-join-codes

Conversation

@fspeirs
Copy link
Copy Markdown
Contributor

@fspeirs fspeirs commented Apr 22, 2026

This PR implements join code functionality for school classes, allowing students to join classes using a unique 6-character code.

Changes

  • Add join_code column to school_classes table
  • Implement JoinCodeGenerator utility for generating unique join codes
  • Add join code functionality to SchoolClass model with automatic generation and regeneration
  • Create join endpoint (/api/classes/join) for class enrollment via join codes
  • Add regenerate join code endpoint (PATCH /api/school_classes/:id/regenerate_join_code)
  • Expose join_code in school class API responses
  • Fix authentication flow to preserve join codes through login redirect
  • Add comprehensive test coverage for all new functionality
  • Update CanCan abilities for join code permissions

@cla-bot cla-bot Bot added the cla-signed label Apr 22, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

Test coverage

SimpleCov coverage data was unavailable for this run.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/24841523591

Comment thread spec/models/school_class_spec.rb Fixed
@fspeirs fspeirs force-pushed the fs-implement-class-join-codes branch from 2b3e115 to bb23e12 Compare April 22, 2026 12:43
fspeirs added 8 commits April 23, 2026 10:47
- Move JoinController from root to Api namespace
- Change from redirect-based to JSON API endpoints:
  - GET /api/join/:join_code - public endpoint returns school_code
  - POST /api/join/:join_code - authenticated endpoint enrolls user
- Returns JSON with redirect_url and school_code
- Remove all redirect logic from controller
- Simpler, cleaner API design for frontend consumption
- Updated JoinCodeGenerator to produce format: Consonant-Vowel-2Digits-Consonant-Vowel-2Digits
- Example: GE86SU10 instead of BAFA2345
- Updated validation regex in SchoolClass model
- Updated specs to test new format
- All tests passing
- Remove consonants K, X, Z to reduce offensive word risk
- Add OFFENSIVE_PATTERNS blacklist (AS, BA, BO, BU, DA, DI, FU, HO, PO, SH, TA, TI, VA)
- Filter codes during generation to skip offensive CV patterns
- Add test to verify no offensive patterns in generated codes
- Max 100 attempts before raising error (very unlikely to hit)

This prevents codes like BA55FU99 or DI12HO34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant