Skip to content

Conversation

@Mohamed-RPF
Copy link
Contributor

Make URN mandatory for UK schools and NCES ID mandatory for US schools

Add conditional presence validation for UK URN (reference) and US NCES ID (district_nces_id) fields, with format validation and scoped uniqueness to allow reuse after school rejection. This improves validation error handling so users receive specific, actionable error messages instead of generic form errors.

Status

Closes: https://github.com/orgs/RaspberryPiFoundation/projects/51/views/11?pane=issue&itemId=120513360&issue=RaspberryPiFoundation%7Cdigital-editor-issues%7C780

Related to: (standalone url)

Points for consideration:

Security

  • Partial unique indexes prevent duplicate entries among active (non-rejected) schools
  • Format validation enforces strict digit patterns (5-6 digits for URN, 12 digits for NCES ID)
  • Case-insensitive uniqueness check prevents bypass attempts

What's changed?

Database:

  • Converted reference index to partial unique index (WHERE rejected_at IS NULL)
  • Converted district_nces_id index to partial unique index (WHERE rejected_at IS NULL)
  • This allows rejected schools to release their identifiers for reuse by legitimate schools

Model (School):

  • Added conditional presence validation: reference required for UK (country_code == 'GB')
  • Added conditional presence validation: district_nces_id required for US (country_code == 'US')
  • Added format validation: URN must be 5-6 digits, NCES ID must be 12 digits
  • Added scoped uniqueness: only active (non-rejected) schools are checked for duplicates
  • Added united_kingdom? and united_states? helper methods

API Error Responses:

Field Validation Error Message
reference presence "can't be blank"
reference uniqueness "has already been taken"
reference format "must be 5-6 digits (e.g., 100000)"
district_nces_id presence "can't be blank"
district_nces_id uniqueness "has already been taken"
district_nces_id format "must be 12 digits (e.g., 010000000001)"

Tests:

  • 16 comprehensive validation tests covering:
    • Conditional presence (UK/US specific)
    • Format validation (valid/invalid patterns)
    • Scoped uniqueness (allows reuse after rejection)
  • Updated factory to include valid reference for default GB schools

@Mohamed-RPF Mohamed-RPF self-assigned this Dec 8, 2025
@Mohamed-RPF Mohamed-RPF added enhancement New feature or request API labels Dec 8, 2025
@cla-bot cla-bot bot added the cla-signed label Dec 8, 2025
@Mohamed-RPF Mohamed-RPF force-pushed the 780-improve-urn-nces-id-and-and-school-roll-number-validation-error-message-and-form-state-api branch from 8994994 to 27313f4 Compare December 8, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API cla-signed enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants