Dynamic Challenge Management#79
Merged
Merged
Conversation
|
@Ayaanshaikh12243 is attempting to deploy a commit to the csxark's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dynamic Challenge Management #73
Overview
This PR implements the complete challenge approval workflow that was previously incomplete. When admins approve a challenge submission, the system now:
Issue Fixed
Issue #73: Challenge Approval Function Incomplete - Files Never Created
Problem:
approve-challengeEdge Function only updated submission status to "approved"SAMPLE_QUESTIONSarray didn't include themSolution:
challengesdatabase table for dynamic challenge managementChanges Made
Database Migrations
Migration:
20260205_create_challenges_table.sqlNew table for managing challenges:
RLS Policies:
Anyone can view active challenges- SELECT whereis_active = trueAdmins can insert challenges- INSERT with admin role checkAdmins can update challenges- UPDATE with admin role checkAdmins can delete challenges- DELETE with admin role checkIndexes:
categoryfor filteringdifficultyfor filteringis_activefor active challenge queriessubmission_idfor linkage to submissionsPre-populated Data:
Existing hardcoded challenges (q1-q5) are inserted during migration so the system works immediately.
Edge Function Updates
Updated:
supabase/functions/approve-challenge/index.tsComplete rewrite with full file creation workflow:
Authentication & Authorization:
Workflow Steps:
Validate Submission
Generate Challenge ID
q{timestamp}(e.g.,q1709564321)Create Supabase Storage Bucket
Upload Challenge Assets
/challenge-assets/{challengeId}/{filename}Generate challenge.json Metadata
{ "category": "Cryptography", "difficulty": "Intermediate", "created_at": "2026-03-03T12:34:56Z", "submission_id": "uuid-here" }Upload to
/challenge-assets/{challengeId}/challenge.jsonInsert into Challenges Table
Update Submission Status
Asset Format Expected:
Storage Structure Created:
Error Handling:
Response Format:
{ "success": true, "message": "Challenge 'The Cryptographer's Dilemma' has been approved and is now live!", "challenge_id": "q1709564321", "challenge_data": { "id": "q1709564321", "title": "The Cryptographer's Dilemma", "category": "Cryptography", "difficulty": "Intermediate" } }Frontend Changes
File:
src/components/ChallengePage.tsxNew State Variable:
New useEffect Hook - Fetch Challenges on Mount:
Replaced All SAMPLE_QUESTIONS References (13 occurrences):
SAMPLE_QUESTIONS.filter(...)→availableChallenges.filter(...)SAMPLE_QUESTIONS.find(...)→availableChallenges.find(...)SAMPLE_QUESTIONS.length→availableChallenges.lengthSAMPLE_QUESTIONS.map(...)→availableChallenges.map(...)Benefits of Dynamic Loading:
is_activeflagDocumentation
New:
Docs/CHALLENGE_APPROVAL_SYSTEM.mdComprehensive system documentation including:
Technical Details
Supabase Storage Bucket Setup
Bucket Name:
challenge-assetsConfiguration:
File Path Convention
/challenge-assets/{challengeId}/{filename}{SUPABASE_URL}/storage/v1/object/public/challenge-assets/{challengeId}/{filename}/challenge-assets/{challengeId}/{filename}Challenge ID Format
q{timestamp}q1709564321Database Query Pattern (Dynamic Loading)
Fallback Behavior
When Supabase is unavailable or query fails:
SAMPLE_QUESTIONSSecurity Considerations
Authentication & Authorization
approve-challengerequires authenticated userData Validation
Storage Security
Performance Implications
Testing Recommendations
Test 1: Approve Text-Only Challenge
Test 2: Approve Challenge With Assets
Test 3: Dynamic Challenge Loading
Test 4: Admin Controls
Test 5: Fallback Behavior
Test 6: Concurrent Approvals
1. Submit 3 challenges 2. Approve simultaneously 3. Verify all create unique IDs 4. Verify no conflicts 5. Verify all appear in frontendTest 7: Large File Uploads
Migration Path
For Existing Deployments
Step 1: Deploy Database Migration
Step 2: Verify Migration
Step 3: Deploy Edge Function
Step 4: Deploy Frontend Changes
npm run build # Deploy to your hosting platformStep 5: Verification Tests
For New Deployments
Databases/supabase/migrations/Zero Downtime Deployment
Breaking Changes
None - fully backward compatible
Non-Breaking Additions
challengestable (doesn't affect existing data)approve-challengefunction (same input/output contract)Rollback Plan
If needed:
challengestable in database (non-destructive)SAMPLE_QUESTIONSChecklist
Files Changed
Related Issues
Key Improvements
Functionality
File Creation ✅
Metadata Management ✅
Dynamic Loading ✅
is_activeUser Experience
System Quality
Performance Metrics
is_activeandcategoryFuture Enhancement Opportunities
Review Checklist
Notes for Reviewers
Key Points
Questions for Reviewers
q{timestamp}) work for your use case?This PR completes the challenge approval workflow, enabling dynamic challenge management without requiring code deployment or manual file operations.
Related PR: #70, #71, #72