Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request introduces a prerequisite challenge feature that allows challenges to be locked until a previous challenge is solved. The feature is enforced at the team level and includes comprehensive validation, testing, and documentation updates.
Changes:
- Added
previous_challenge_idfield to the Challenge model with database support - Implemented
ensureUnlockedvalidation in CTFService and StackService to check prerequisite completion - Added
TeamSolvedChallengeIDsrepository method andisChallengeLockedhandler logic - Updated REST API to include locked challenge responses with limited information
- Added comprehensive test coverage for the locked challenge workflow
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/models/challenge.go | Added PreviousChallengeID field to Challenge model |
| internal/service/ctf_service.go | Added ensureUnlocked validation and updated Create/Update/SubmitFlag/RequestChallengeFileDownload methods |
| internal/service/stack_service.go | Added ensureUnlocked validation to GetOrCreateStack method |
| internal/service/errors.go | Added ErrChallengeLocked error constant |
| internal/repo/submission_repo.go | Added TeamSolvedChallengeIDs method for checking solved challenges |
| internal/http/handlers/handler.go | Added optionalUserID helper and locked challenge response logic to ListChallenges |
| internal/http/handlers/types.go | Added optionalInt64 type and locked challenge response structures |
| internal/http/handlers/errors.go | Added error mapping for ErrChallengeLocked to HTTP 403 |
| internal/service/ctf_service_test.go | Added comprehensive tests for prerequisite validation and locked challenge workflows |
| internal/service/stack_service_test.go | Added test for locked stack creation |
| internal/http/integration/challenges_test.go | Added integration test for locked challenge flow |
| internal/http/integration/stacks_test.go | Added integration test for locked stack creation |
| internal/http/handlers/handler_test.go | Added handler-level tests for locked challenges |
| scripts/generate_dummy_sql/sql_writer.py | Updated SQL generation to include previous_challenge_id field |
| scripts/generate_dummy_sql/generator.py | Updated challenge tuple to include previous_challenge_id |
| scripts/generate_dummy_sql/defaults/data.yaml | Added example challenges with prerequisites |
| docs/docs/challenges.md | Updated API documentation for locked challenges |
| docs/docs/admin.md | Updated admin API documentation for prerequisite field |
| docs/docs/stacks.md | Added 403 error documentation for locked challenges |
| docs/docs/report.schema.json | Added previous_challenge_id to report schema |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.

A new feature has been introduced that requires solving a prerequisite challenge before accessing a subsequent one. Until the prerequisite (previous) challenge is solved, the next challenge remains in a Locked state. This restriction is enforced at the team level, just like flag submissions.
Locked challenges are subject to the following restrictions:
The following fields have been added to the REST API challenge response. The
previous_challengefamily is optional:is_locked: booleanprevious_challenge_id: optional intprevious_challenge_title: optional stringprevious_challenge_category: optional stringAdditionally, a new HTTP status code
403 challenge lockedhas been introduced in some API responses, with the error identifierErrChallengeLocked.This change also includes support for updating
previous_challenge_idvia the challenge update API. The business validation logic for checking whether the prerequisite challenge has been solved is as follows:For more details, please refer to the source code.