Overview
Admin routes provide full CRUD operations for managing the application. All routes require authentication and admin privileges. Security: All admin routes protected by:Admin Dashboard
Display admin dashboard with statistics
total_challenges: All challenges countreleased_challenges: Challenges withrelease_at <= nowunreleased_challenges: Challenges withrelease_at > nowtotal_users: User counttotal_articles: Article count
Challenge Management
Create Challenge
Create a new challenge with answer boxes
Challenge title
Challenge content (supports CKEditor rich text)
Target key stage: KS3, KS4, or KS5
Scheduled release time (defaults to now if not specified)
Hours after release_at to automatically lock challenge
Challenge image/diagram (jpg, png, gif)
Array of answer boxes, each with:
box_label: Label for the answer box (e.g., “Part A”)correct_answer: The correct answer stringorder: Display order (integer)
- Creates challenge folder at
uploads/challenge_{YYYY-MM-DD}/ - Saves uploaded image to challenge folder
- Creates
Challengerecord withdate_posted=now() - Creates
ChallengeAnswerBoxrecords for each answer box - Commits transaction
admin.manage_challenges with success message
Edit Challenge
Edit existing challenge and answer boxes
ID of challenge to edit
- Existing boxes updated in place
- New boxes created if form has more entries than existing
- Unused boxes deleted (only if no submissions exist)
- Boxes with submissions are preserved for data integrity
admin.manage_challenges
Delete Challenge
Delete challenge, submissions, and files
ID of challenge to delete
- Deletes challenge image file if exists
- Removes challenge folder if empty
- Deletes all
AnswerSubmissionrecords - Deletes
Challengerecord (cascades to answer boxes) - Commits transaction
admin.manage_challenges
Toggle Challenge Lock
Manually lock/unlock a challenge
ID of challenge to toggle
- Toggles
is_manually_lockedfield - When locked: Answers revealed, no new submissions
- When unlocked: Students can submit again
admin.manage_challenges with status message
List Challenges
List all challenges (released and unreleased)
released_challenges: Challenges withrelease_at <= now, ordered bydate_posteddescunreleased_challenges: Challenges withrelease_at > now, ordered byrelease_atasc
User Management
List Users
Enhanced user management with search, filtering, pagination
Page number
Users per page (max 100)
Search by name, email, class, or user ID
Filter by key stage (ks3, ks4, ks5, or ‘all’)
Filter by year (7-13 or ‘all’)
Filter by type: ‘competition’, ‘regular’, or ‘all’
Filter by admin status: ‘admin’, ‘user’, or ‘all’
Create User
Create a new user account
User’s first name (no spaces)
User’s last name (no spaces)
Unique email address
Password (will be hashed)
School year (7-13)
Maths class (not used for competition participants)
Grant admin privileges
Mark as competition participant
School ID (required if is_competition_participant=true)
- Email must be unique
- No whitespace in names
- Competition participants must have school_id
- Key stage auto-calculated from year
admin.manage_users
Edit User
Edit existing user account
ID of user to edit
admin.manage_users
Delete User
Delete user and all associated data
ID of user to delete
- Cannot delete your own account
- Cascades deletion to:
LeaderboardEntryArticle(authored by user)AnswerSubmissionSummerLeaderboardSummerSubmission
admin.manage_users
Toggle Admin Status
Toggle admin privileges for user
ID of user to toggle
admin.manage_users with message
Reset Password
Reset user’s password to random string
ID of user
- Generates 10-character random password
- Hashes and saves to database
- Displays new password to admin (shown once)
admin.manage_users with password in flash message
User Search (AJAX)
Dynamic user search endpoint for AJAX
Search query (min 2 characters, or 1 if numeric)
Max results (capped at 50)
id,full_name,email,maths_classkey_stage,yearis_admin,is_competition_participantdate_joined
Bulk User Actions
Perform bulk actions on multiple users
Action to perform: ‘promote_admin’, ‘demote_admin’, ‘mark_competition’, ‘unmark_competition’, ‘delete’
Array of user IDs to modify
- Cannot demote yourself from admin
- Cannot delete yourself
- Actions only affect specified users
Article Management
Create Article
Create article or newsletter
Article title
Article content (CKEditor rich text)
Author name (named_creator field)
Type: ‘article’ or ‘newsletter’
PDF file (for newsletters only)
- Saves PDF to
uploads/newsletters/newsletter_{YYYY_MM}_{filename} - Creates
Articlerecord withuser_id=current_user.id - Sets
date_posted=now()
admin.manage_articles
Edit Article
Edit existing article or newsletter
ID of article to edit
- New file upload replaces existing file
- Old file deleted from filesystem
admin.manage_articles
Delete Article
Delete article and associated files
ID of article to delete
- Deletes PDF file if exists
- Deletes
Articlerecord - Commits transaction
admin.manage_articles
List Articles
List all articles and newsletters
date_posted descending
Leaderboard Management
List Leaderboard
View leaderboard with key stage statistics
- All leaderboard entries ordered by key stage then score
- Statistics: total entries, unique participants, highest/average scores
- Counts per key stage (KS3, KS4, KS5)
Create Leaderboard Entry
Create new leaderboard entry
User ID (dropdown selection)
Initial score
Key stage: KS3, KS4, or KS5
- User can only have one entry per key stage
- Duplicate user+key_stage combination rejected
admin.manage_leaderboard
Edit Leaderboard Entry
Edit existing leaderboard entry
ID of leaderboard entry
- Prevents duplicate user+key_stage combinations
- Updates
last_updatedtimestamp
admin.manage_leaderboard
Export Leaderboard
Export leaderboard to CSV
- User ID
- Name
- Year
- Class
- Key Stage
- Score
- Last Updated
leaderboard_export.csv file download
File Upload
CKEditor Upload
Handle image uploads for CKEditor
Image file (jpg, jpeg, png, gif only)
- Validates file extension
- Saves to
uploads/folder with secure filename - Returns direct URL for CKEditor
Math Engine Tester
Web interface for testing math expression equivalence
admin/math_engine_tester.html template