Skip to content

feat(content-ops): problem versioning changelog+restore, saved searches, scheduled drops, author analytics, testcase bounties [wave F items 125/129/131/132/133] - #357

Open
Prekzursil wants to merge 1 commit into
mainfrom
wf-f/content-ops
Open

Prekzursil wants to merge 1 commit into
mainfrom
wf-f/content-ops

Conversation

@Prekzursil

Copy link
Copy Markdown
Owner

Wave F items 125 / 129 / 131 / 132 / 133 (+ verify 130)

Problem versioning + changelog (125)

  • Append-only changelog ledger per problem: every edit snapshots the previous revision (problem_changelog, restore_revision).
  • ChangelogView (GET problems/<id>/changelog/) + RestoreRevisionView (POST problems/<id>/restore/<rev>/, author/verifier only) — restore appends a new revision, never rewrites history.

Saved searches (129)

  • SavedSearch model (name + params JSON, one row per user+name via update_or_create) with SavedSearchView GET/POST/DELETE ?id=.
  • Catalog strip (SavedSearchesStrip): save the current filter set under a name, one-click re-apply, delete.

Scheduled drops (131)

  • publish_at gate on the catalog: staff/verifiers see all, authenticated users get (published | own), anon published-only (problem_is_visible / visible_problem_queryset).
  • DropsView (upcoming drops feed) + drop calendar on the analytics page.

Author analytics (132)

  • author_analytics: authored/approved funnel, by-difficulty mix, submission count, AC rate, unique solvers, editorial coverage, open bounty count.
  • AuthorAnalyticsView (?username= needs verifier gate) + /author/analytics dashboard.

Testcase bounties (133)

  • ProblemBounty model (author posts coin bounty for a missing testcase; verifier FULFILL / requester CANCEL resolution).
  • BountyListView, BountyClaimView (POST testcase input), BountyResolveView.

Verify 130 (translation coverage)

  • translation_gaps from PR7 covers statement-translation drift; add-wave-f9-keys.py keeps all 30 locale catalogs + mobile copies in parity (byte-for-byte incl. CRLF tr).

Tests

  • Backend: changelog/restore round-trip, saved-search CRUD, drop-gate visibility matrix, analytics derivation, bounty lifecycle (claim/fulfil/cancel/permission), 100% line coverage on every new module; full suite 2124 passed, TOTAL 100%.
  • Frontend: ContentOps.test.tsx (analytics summary, empty states, saved-search save/apply/delete, anon hidden); i18n parity 30 locales.
  • E2E: e2e/wave-f-content-ops.spec.ts — analytics dashboard, saved-search strip, changelog probe; full mock suite 186 passed / 5 skipped (real-stack).

BACKLOG

docs/BACKLOG.md statuses updated for items 125/129/131/132/133.

…es, scheduled drops, author analytics, testcase bounties [wave F items 125/129/131/132/133]

- item 125: full versioning ledger — GET /problems/{id}/changelog/ over the
  append-only StatementRevision history; POST
  /problems/{id}/revisions/{rid}/restore/ rolls the statement back and
  records the restore as a new ledger row
- item 129: SavedSearch — named catalog filter presets (querystring
  params); GET/POST/DELETE /problems/searches/ + the catalog
  SavedSearchesStrip (save current filters, one-click re-apply, delete)
- item 131: Problem.publish_at — the public catalog hides future-dated
  APPROVED problems (staff/verifiers and the author still see them);
  GET /problems/drops/ calendar; drop panel on the analytics page
- item 132: content_ops.author_analytics — authored/approved counts,
  difficulty mix, submission funnel + AC rate, unique solvers, editorial
  coverage, open bounty count; GET /problems/author-analytics/ (own, or
  others' for verifiers) + /author/analytics dashboard
- item 133: ProblemBounty — community pledges (500/bounty cap, 2000
  locked cap), contributors claim, verifiers fulfill with credit note,
  requesters cancel; GET/POST /problems/{id}/bounties/ + claim/resolve
- BACKLOG statuses for 125/129/131/132/133
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T15:43:16.537051Z 88bd5c0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment on lines +86 to +96
if problem is None:
return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND)
if not _authoring_gate(request.user):
return Response(
{"detail": "Authors and verifiers only."},
status=status.HTTP_403_FORBIDDEN,
)
ok, message = restore_revision(problem, revision_id, request.user)
if not ok:
return Response({"detail": message}, status=status.HTTP_404_NOT_FOUND)
return Response({"detail": message})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: RestoreRevisionView and ChangelogView gate access only by user role rather than ownership, allowing creators to read draft changelogs and overwrite statements of other authors' problems.
Severity: HIGH

Suggested Fix

Update _authoring_gate or enforce permissions within RestoreRevisionView and ChangelogView to ensure PROBLEM_CREATOR and TEACHER users can only access their own problems. In restore_revision, check problem status and call _guard_contest_pin before saving updates.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: backend/problems/content_ops_views.py#L84-L96

Potential issue: In `_authoring_gate`, permission checks only inspect the user's role
without verifying problem ownership (`problem.author_id == request.user.id`).
Consequently, any authenticated user holding the `PROBLEM_CREATOR` or `TEACHER` role can
restore revisions for any problem and view other authors' draft changelogs via
`RestoreRevisionView` and `ChangelogView`. Additionally, `restore_revision` bypasses
status restrictions (allowing modifications to `APPROVED` problems) and ignores
contest-pin protections (`_guard_contest_pin`), allowing statement modifications
contrary to the permission model.

Also affects:

  • backend/problems/content_ops_views.py:67~76

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +269 to +279
)
if bounty.requester_id == request.user.id:
return Response(
{"detail": "You cannot claim your own bounty."},
status=status.HTTP_400_BAD_REQUEST,
)
bounty.claimed_by = request.user
bounty.save(update_fields=["claimed_by"])
return Response(
{"detail": "Claimed — submit the strengthened tests for review."}
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: BountyClaimView.post does not check if bounty.claimed_by is already set, allowing subsequent callers to overwrite the existing claimant.
Severity: MEDIUM

Suggested Fix

In BountyClaimView.post, check if bounty.claimed_by is not null (e.g., return HTTP 409 or 400). Use transaction.atomic() with select_for_update() to prevent race conditions during concurrent claim attempts.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: backend/problems/content_ops_views.py#L261-L279

Potential issue: `BountyClaimView.post` checks that a bounty's status is `OPEN` and the
caller is not the requester, but does not verify if `bounty.claimed_by` is already
populated. Subsequent callers claiming an open bounty will overwrite the existing
`claimed_by` field, causing the original claimant to lose credit when the bounty is
later fulfilled and resolved via `BountyResolveView`.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment thread backend/problems/views.py
Comment on lines +237 to +247
in (User.Roles.ADMIN, User.Roles.PROBLEM_VERIFIER)
):
pass # staff/verifiers see scheduled problems (the calendar view)
else:
drop_gate = models.Q(publish_at__isnull=True) | models.Q(
publish_at__lte=now
)
if user.is_authenticated:
qs = (qs.filter(drop_gate) | qs.filter(author=user)).distinct()
else:
qs = qs.filter(drop_gate)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Scheduled publish_at visibility checks are omitted across multiple endpoints and public API views, leaking unreleased problems before their scheduled release time.
Severity: HIGH

Suggested Fix

Consistently apply visibility filters (such as visible_problem_queryset or problem_is_visible) across public_api views, related, starters, RandomProblemView, and related editorial queries to exclude problems where publish_at is in the future.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: backend/problems/views.py#L228-L247

Potential issue: The scheduled publishing filter (`publish_at`) is only implemented in
`ProblemViewSet.get_queryset`, leaving other query paths vulnerable to data leaks.
Endpoints that construct their own `Problem` queries—such as `PublicProblemDetail`, the
public problem list, `related` problems, `starters`, `RandomProblemView._visible_pool`,
and community editorials—filter only by `status=APPROVED`. Unauthenticated and standard
users can access statements, metadata, or IDs of scheduled problems before their
`publish_at` timestamp.

Did we get this right? 👍 / 👎 to inform future reviews.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88bd5c0192

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

problem = Problem.objects.filter(pk=problem_id).first()
if problem is None:
return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND)
if not _authoring_gate(request.user):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce problem-level write permissions before restoring

Any authenticated creator or teacher can restore another author's problem because _authoring_gate only checks the caller's role, not ownership or problem status. This bypasses ProblemObjectPermissions in backend/users/permissions.py, which restricts ordinary authors to editing their own DRAFT/PRIVATE problems. A creator can obtain revision IDs from the changelog endpoint and overwrite an unrelated approved statement. Apply the existing object-level write restrictions before allowing a restore.

Useful? React with 👍 / 👎.

{"detail": "Authors and verifiers only."},
status=status.HTTP_403_FORBIDDEN,
)
ok, message = restore_revision(problem, revision_id, request.user)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the active-contest edit guard during restores

For a problem attached to an upcoming or running contest, an otherwise authorized verifier can change its statement through this endpoint while normal updates are blocked. ProblemViewSet.perform_update calls _guard_contest_pin specifically to freeze statements until the contest ends, but this path calls restore_revision directly, which saves without that guard. Apply the same contest-pin check before restoring so a rollback cannot invalidate a live contest.

Useful? React with 👍 / 👎.

Comment thread backend/problems/views.py
Comment on lines +241 to +247
drop_gate = models.Q(publish_at__isnull=True) | models.Q(
publish_at__lte=now
)
if user.is_authenticated:
qs = (qs.filter(drop_gate) | qs.filter(author=user)).distinct()
else:
qs = qs.filter(drop_gate)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply scheduled visibility to public download endpoints

For an APPROVED problem with a future publish_at, this gate hides the normal detail endpoint, but anonymous callers can still download its complete statement and samples through /api/v1/problems/<id>/offline-bundle/: OfflineBundleView.get in backend/problems/tooling.py filters only by APPROVED status. The samples endpoint has the same omission, and random_problem._visible_pool can reveal scheduled IDs and return links whose detail requests now yield 404. Reuse the scheduled visibility predicate across these public entry points so the release time cannot be bypassed.

Useful? React with 👍 / 👎.

Comment on lines +40 to +42
const isAuthor = ['PROBLEM_CREATOR', 'PROBLEM_VERIFIER', 'TEACHER', 'ADMIN'].includes(
auth.user?.role ?? '',
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept the role values actually returned by the API

Users whose backend roles are problem creator or verifier cannot access the new dashboard: User.Roles serializes them as CREATOR and VERIFIER, and AuthContext stores the /users/me/ response without translating those values. This check accepts only the legacy long spellings, so those users see the creators-only message and neither analytics nor drops are loaded. Include the canonical short values, as documented by the frontend User type.

Useful? React with 👍 / 👎.

Comment on lines +275 to +276
bounty.claimed_by = request.user
bounty.save(update_fields=["claimed_by"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject attempts to overwrite another contributor's claim

After a contributor claims a bounty, its status remains OPEN, so any other authenticated user except the requester can call this endpoint and replace claimed_by. Fulfillment then credits whichever user last overwrote the claim rather than the original contributor. Reject claims already held by another user and make the availability check and assignment atomic to prevent concurrent claim requests from causing the same overwrite.

Useful? React with 👍 / 👎.

Comment on lines +121 to +124
href: '/author/wizard',
label: t('nav_author_wizard', 'Authoring wizard'),
},
{ href: '/author/tools', label: t('nav_author_tools', 'Author tools') },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Point the new author navigation links at implemented routes

For users shown the contributor menu, both the new Authoring wizard and Author tools links lead to nonexistent pages. A repository-wide search for these paths and route files finds only these links; src/app/author/ contains only the analytics page and its test, and next.config.ts defines no redirects or rewrites to supply the missing destinations. There are also no generated route artifacts or catch-all handlers providing them. Remove these entries until the pages exist, or link to the implemented authoring surfaces instead.

Useful? React with 👍 / 👎.

Comment on lines +123 to +126
by_difficulty = {"EASY": 0, "MEDIUM": 0, "HARD": 0}
for problem in approved:
if problem.difficulty in by_difficulty:
by_difficulty[problem.difficulty] += 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include VERY_EASY problems in the difficulty breakdown

For authors with approved beginner problems, the dashboard silently omits those problems from its difficulty mix. Problem.DifficultyLevel includes the supported VERY_EASY value, which is also exercised by the existing content-seed tests, but this dictionary excludes it and the following membership check discards every matching problem. Consequently, an author with only VERY_EASY problems sees a positive approved total alongside all-zero difficulty counts. Initialize the breakdown from the model's difficulty choices so every supported band is counted.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant