Repository navigation
feat(profiles): setter CVs, shareable solve cards, embeddable problem widgets [wave F items 70-72] - #353
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| def get(self, request, problem_id): | ||
| problem = get_object_or_404(Problem, pk=problem_id) | ||
| from contests.models import ContestProblem | ||
|
|
||
| live_contest = ContestProblem.objects.filter( | ||
| problem=problem, | ||
| contest__end_at__gt=timezone.now(), | ||
| ).exists() | ||
| if live_contest: | ||
| return Response( | ||
| {"detail": "This problem is not embeddable right now."}, |
There was a problem hiding this comment.
Bug: EmbedProblemView retrieves problems without validating status == APPROVED, leaking draft and private problem details to anonymous users.
Severity: HIGH
Suggested Fix
Enforce problem visibility checks matching ProblemViewSet.get_queryset or use the _visible_problem helper before returning the embed payload, returning a 404 for unapproved problems.
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/users/profile_widgets.py#L120-L130
Potential issue: `EmbedProblemView.get` uses `get_object_or_404(Problem, pk=problem_id)`
without checking the problem's `status`. Because the view allows any unauthenticated
caller, anonymous clients can query sequential IDs to inspect unpublished, draft, and
private problems—retrieving titles, limits, sample test cases, and solve counts that are
otherwise protected across the application.
Also affects:
backend/users/profile_widgets.py:74-79
Did we get this right? 👍 / 👎 to inform future reviews.
| ) | ||
| title = html.escape(card["problem_title"][:60]) | ||
| handle = html.escape(card["username"][:30]) | ||
| svg = f"""<svg xmlns="http://www.w3.org/2000/svg" width="600" height="200" viewBox="0 0 600 200"> | ||
| <rect width="600" height="200" rx="16" fill="#0f172a"/> | ||
| <rect x="8" y="8" width="584" height="184" rx="12" fill="#1e293b"/> | ||
| <text x="32" y="58" fill="#38bdf8" font-family="sans-serif" font-size="22" font-weight="bold">SOLVED</text> | ||
| <text x="32" y="96" fill="#f8fafc" font-family="sans-serif" font-size="24" font-weight="bold">{handle}</text> | ||
| <text x="32" y="128" fill="#cbd5e1" font-family="sans-serif" font-size="18">{title}</text> | ||
| <text x="32" y="162" fill="#94a3b8" font-family="sans-serif" font-size="14">solver #{card["ordinal"]} · {solved_date} · webcoder</text> | ||
| </svg>""" |
There was a problem hiding this comment.
Bug: SolveCardSvgView renders a "SOLVED" badge and solve card for users who have not solved the given problem.
Severity: MEDIUM
Suggested Fix
In SolveCardSvgView and SolveCardView, check if an accepted submission exists for (user, problem) or if card["solved_at"] is None, and return an HTTP 404 response.
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/users/profile_widgets.py#L87-L107
Potential issue: `SolveCardSvgView.get` renders a card image with a hardcoded "SOLVED"
label for any requested user and problem combination without verifying whether the user
actually achieved an accepted submission. If a user has not solved the problem,
`solved_at` resolves to `None`, but the endpoint still returns HTTP 200 with an SVG
claiming the problem is solved.
Did we get this right? 👍 / 👎 to inform future reviews.
| """1-based solve ordinal of a problem (the Nth solver overall).""" | ||
| from submissions.models import Submission | ||
|
|
||
| return ( | ||
| Submission.objects.filter( | ||
| problem_id=problem_id, verdict=Submission.VerdictStatus.ACCEPTED | ||
| ) | ||
| .values_list("user_id") | ||
| .distinct() | ||
| .count() | ||
| ) |
There was a problem hiding this comment.
Bug: solve_ordinal calculates the total distinct solver count instead of the user's specific solve rank.
Severity: MEDIUM
Suggested Fix
Update solve_ordinal to accept the user or their earliest accepted submission timestamp, counting only distinct users who solved the problem at or before that timestamp.
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/users/setter.py#L50-L61
Potential issue: `solve_ordinal` computes the total count of distinct users with an
accepted submission on the problem rather than the solving user's specific rank or order
of solve. As a result, every solver displays the exact same ordinal on their card, and
the displayed number changes dynamically over time as subsequent users solve the
problem.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3db518a87f
ℹ️ 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".
| def get(self, request, problem_id): | ||
| problem = get_object_or_404(Problem, pk=problem_id) |
There was a problem hiding this comment.
Restrict public widgets to publicly visible problems
For a draft or pending-approval problem that is not attached to an upcoming/running contest, this anonymous endpoint returns its title and sample inputs/outputs to anyone who supplies its ID. The existing visibility boundary in ProblemViewSet.get_queryset() (backend/problems/views.py:201–227) restricts anonymous readers to APPROVED problems, but this lookup bypasses it. The two new solve-card views likewise query unrestricted problems and expose their metadata. Apply the public-problem visibility filter across these new public endpoints so unpublished author content cannot be retrieved by enumerating IDs.
Useful? React with 👍 / 👎.
| "problem_id": problem.id, | ||
| "problem_title": title, | ||
| "difficulty": problem.difficulty, | ||
| "ordinal": solve_ordinal(problem.id), |
There was a problem hiding this comment.
Calculate the ordinal at the user's first accepted submission
Once two users have solved a problem, both cards display solver #2, including the first solver's previously shared card. solve_ordinal() counts all current distinct solvers without considering this user or their first accepted submission, so the displayed ordinal is a changing solve count rather than the claimed deterministic solver position. Calculate the user's position using their first accepted submission and distinct solvers up to that point, so later solves do not change earlier users' ordinals.
Useful? React with 👍 / 👎.
| by_difficulty = {"EASY": 0, "MEDIUM": 0, "HARD": 0} | ||
| for problem in approved: | ||
| if problem.difficulty in by_difficulty: | ||
| by_difficulty[problem.difficulty] += 1 |
There was a problem hiding this comment.
Include VERY_EASY problems in the difficulty breakdown
For setters who author beginner problems, the CV silently excludes all VERY_EASY problems from its difficulty breakdown even though they contribute to problems_approved. Problem.DifficultyLevel explicitly defines this supported difficulty, and the problem authoring form offers it, so a setter whose approved portfolio consists entirely of beginner problems gets a positive total alongside zero in every displayed difficulty bucket. Initialize the breakdown from the model's supported difficulty choices, including VERY_EASY, so those contributions are represented.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a063dcb23
ℹ️ 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".
| <main style={{ maxWidth: 520, margin: '0 auto', padding: '16px' }}> | ||
| <PageHeader title={t('embed_title', 'WebCoder problem')} /> | ||
| {problemId ? <ProblemEmbedWidget problemId={problemId} /> : null} |
There was a problem hiding this comment.
Exclude the site shell from the embeddable widget page
When /embed/problems/{id} is loaded in an iframe, it still inherits RootLayout and Providers, which unconditionally render <Navbar /> and <Footer /> around the page (src/app/providers.tsx:163–165). Consequently, the advertised standalone widget includes the full site navigation and footer, consuming space and adding scrolling inside a compact embed. Give this route a chrome-free shell or conditionally omit those components for embed routes.
Useful? React with 👍 / 👎.
| await navigator.clipboard?.writeText(svgUrl).catch(() => undefined); | ||
| setCopied(true); |
There was a problem hiding this comment.
Show copy success only after the clipboard write succeeds
If clipboard access is denied or navigator.clipboard is unavailable, clicking the share button still displays “Copied!” even though the solve-card URL was never copied. The rejection is swallowed, and the unavailable-API case also falls through to setCopied(true), leaving users to paste an unchanged clipboard with no indication that sharing failed. Set the success state only after a successful write, and expose an error or a selectable URL when copying is unavailable.
Useful? React with 👍 / 👎.
| by_difficulty = {"EASY": 0, "MEDIUM": 0, "HARD": 0} | ||
| for problem in approved: | ||
| if problem.difficulty in by_difficulty: | ||
| by_difficulty[problem.difficulty] += 1 |
There was a problem hiding this comment.
Bug: by_difficulty omits "VERY_EASY", causing approved problems of that difficulty to be excluded from the setter CV's difficulty breakdown.
Severity: MEDIUM
Suggested Fix
Include "VERY_EASY" in by_difficulty by dynamically initializing keys from Problem.DifficultyLevel.values (or Problem.DifficultyLevel.choices), or use collections.Counter to track counts.
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/users/setter.py#L21-L24
Potential issue: In `backend/users/setter.py`, `by_difficulty` is initialized with keys
only for `"EASY"`, `"MEDIUM"`, and `"HARD"`, omitting `"VERY_EASY"`. When aggregating
problems for the setter CV breakdown, problems with difficulty `VERY_EASY` fail the
membership check and are omitted from `by_difficulty`. Consequently, the breakdown sums
to less than `problems_approved`, and the frontend displays missing or inconsistent
difficulty metrics for setters with approved `VERY_EASY` problems.
… widgets [wave F items 70-72]
- item 70: derived setter portfolio (approved problems by difficulty,
editorial/article credits, contests) + SetterProfile blurb/links;
/users/{u}/setter-cv/ GET/PUT; /setters/{u} page with owner editing
- item 71: deterministic solve-card payload (solver ordinal + date) +
server-rendered SVG at /users/cards/solve/{u}/{problem}/svg/; share
block on AC submissions with copy-link
- item 72: /users/embed/problems/{id}/ payload (title, limits, samples,
solve count — live-contest problems blocked) + the /embed/problems/{id}
iframe page + ProblemEmbedWidget component
- BACKLOG statuses for 70-72
…all-clock independent
d03bccc to
1c01d2c
Compare
| def get(self, request, username, problem_id): | ||
| user = User.objects.filter(username=username).first() | ||
| problem = Problem.objects.filter(pk=problem_id).first() | ||
| if user is None or problem is None: | ||
| return Response({"detail": "Not found."}, status=status.HTTP_404_NOT_FOUND) | ||
| return Response(solve_card(user, problem)) |
There was a problem hiding this comment.
Bug: SolveCardView and SolveCardSvgView do not enforce problem status or contest visibility checks, leaking metadata for non-public or contest problems to unauthenticated callers.
Severity: MEDIUM
Suggested Fix
Filter problem queries to only allow APPROVED status (or owner-accessible problems for authenticated users) and ensure problems locked in active contests return a 404 response.
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/users/profile_widgets.py#L74-L79
Potential issue: `SolveCardView` and `SolveCardSvgView` permit anonymous access and
retrieve problems using `Problem.objects.filter(pk=problem_id).first()` without checking
visibility constraints such as `status=APPROVED` or active contest restrictions. This
allows anonymous users to iterate through sequential problem IDs to read metadata
including title, difficulty, and solver counts for draft, pending, private, or active
contest problems.
Also affects:
backend/users/profile_widgets.py:87~92
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c01d2cdeb
ℹ️ 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".
| solved_date = ( | ||
| card["solved_at"].strftime("%Y-%m-%d") if card["solved_at"] else "" | ||
| ) |
There was a problem hiding this comment.
Require an accepted submission before rendering a solved SVG
For an existing user who has never solved the requested problem, this public endpoint still returns an SVG labeled SOLVED under that user's handle. solve_card() returns solved_at=None in that case, but the renderer merely leaves the date blank and includes the problem's current solver count. Anyone can therefore obtain an official-looking solve card for an arbitrary user/problem pair without an accepted submission. Reject unsolved pairs before rendering, or render an explicitly unsolved state instead.
Useful? React with 👍 / 👎.
Wave F PR 6/9 — BACKLOG section D.
Items
SetterProfile(blurb + up to 5 links).GET/PUT /users/username/{u}/setter-cv/;/setters/{u}page with live completion editing for the owner./users/cards/solve/{u}/{problem_id}/svg/. AC submission detail pages show the card with a copy-link share control.GET /users/embed/problems/{id}/(title, difficulty, limits, sample I/O, solve count; live/upcoming-contest problems are refused) + the minimal-chrome/embed/problems/{id}iframe page and aProblemEmbedWidgetcomponent.Gates (all run in the worktree, CI-identical commands)
SECRET_KEY=x DB_PASSWORD=x python -m pytest -q --cov-fail-under=100→ 2103 passed, TOTAL 100% after branch-closure tests (new:users/test_profile_widgets.py, 16 tests; users/setter.py + users/profile_widgets.py at 100% lines & branches)npm run test775 passed ·npx tsc --noEmitclean ·npm run lint0/0 ·npm run buildgreen · fullnpx playwright test→ 183 passed, 5 skipped, 0 failed (new spece2e/wave-f-widgets.spec.ts, 4 tests)