feat: Restrict @predictors mentions to curators/admins with warning toast#4599
feat: Restrict @predictors mentions to curators/admins with warning toast#4599SylvainChevalier wants to merge 4 commits into
Conversation
- Backend: filter @predictors to only active (non-withdrawn) predictions by excluding forecasts with end_time in the past - Frontend: show warning toast when non-admin/curator uses @predictors in both comment creation and editing flows - Frontend: add mention autocomplete with permission filtering to the comment edit form (was previously only on new comment form) - Add translation key for the warning message - Add test for withdrawn forecast exclusion Fixes #4082 Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
📝 WalkthroughWalkthroughBackend filtering now excludes withdrawn forecasts from Changes
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🚀 Preview EnvironmentYour preview environment is ready!
Details
ℹ️ Preview Environment InfoIsolation:
Limitations:
Cleanup:
|
|
@claude please fix the unit test problems. |
|
Claude encountered an error —— View job Fixing Unit Test Problems
|
|
@claude please fix the unit test problems. |
|
Claude finished @SylvainChevalier's task in 5m 20s —— View job Fixing Unit Test Problems
SummaryTwo CI failures, both fixed in Backend — Frontend formatting — Not doneI could not run the prettier check or the pytest suite locally (sandbox restrictions on shell access), so the fixes rely on CI to validate. The frontend fix mirrors the exact pattern prettier produced in the sibling file, and the backend fix addresses the precise constraint shown in the traceback. |
- tests/unit/test_comments/test_utils.py: pass start_time alongside end_time for the withdrawn forecast so end_time > start_time and the end_time_after_start_time DB check constraint is satisfied. - front_end/src/components/comment_feed/comment.tsx: reformat the predictors-warning condition to match prettier's preferred shape (matches the equivalent block already in comment_editor.tsx). Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
|
@claude some more unit tests failing. |
|
Claude finished @SylvainChevalier's task in 2m 18s —— View job Fixing Unit Test Problems
SummaryThe only failure in run 25917354314 was a frontend lint error in A stray blank line sat between the The backend test job in that run was already green, so no further changes were needed. Not doneI could not run the linter locally (sandbox restrictions), so the fix relies on CI to validate. |
Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
|
@claude some more unit tests failing. |
|
Claude finished @SylvainChevalier's task in 1m 31s —— View job Fixing Unit Test Problems
SummaryThe only failure in run 26104324382 was a frontend lint error in The previous fix in The backend test job in that run was already green, so no further changes were needed. Not doneI could not run the linter locally (sandbox restrictions), so the fix relies on CI to validate. |
Co-authored-by: Sylvain <SylvainChevalier@users.noreply.github.com>
|
lgtm as far as the ui is concerned, but I couldn't test the emails. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
front_end/src/components/comment_feed/comment.tsx (1)
493-574:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd
postData?.user_permissiontohandleSaveCommentdependency array.The callback reads
postData?.user_permissionon line 525 for the permission-based warning gate, butpostDatais not included in the dependency array. This creates a stale closure where the callback uses the oldpostDatareference if the prop changes between renders.Suggested fix
}, [ user, isLoading, commentMarkdown, comment.id, + postData?.user_permission, PUBLIC_MINIMAL_UI, t, setCommentMarkdown, setComments,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@front_end/src/components/comment_feed/comment.tsx` around lines 493 - 574, The handleSaveComment callback reads postData?.user_permission but postData is not in its dependency array, causing a stale closure; update the dependency list for handleSaveComment (the useCallback that defines handleSaveComment) to include postData (or specifically postData?.user_permission) so the callback re-creates whenever postData changes, ensuring the permission check uses the current postData value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@front_end/src/utils/comments.ts`:
- Around line 83-88: The hasPredictorsMention function currently compares raw
capture groups (match[1] or match[2]) directly to "predictors", which misses
forms like @(predictors); update hasPredictorsMention to normalize the captured
username by trimming whitespace and any surrounding parentheses or surrounding
characters before lowercasing and comparing. Locate hasPredictorsMention (and
its use of userTagPattern and match[1]/match[2]) and apply a small normalization
step such as stripping leading/trailing parentheses and whitespace from the
chosen capture value, then compare normalizedUsername.toLowerCase() ===
"predictors".
---
Outside diff comments:
In `@front_end/src/components/comment_feed/comment.tsx`:
- Around line 493-574: The handleSaveComment callback reads
postData?.user_permission but postData is not in its dependency array, causing a
stale closure; update the dependency list for handleSaveComment (the useCallback
that defines handleSaveComment) to include postData (or specifically
postData?.user_permission) so the callback re-creates whenever postData changes,
ensuring the permission check uses the current postData value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: aceda96a-12c5-4538-b92b-9200034a3ba1
📒 Files selected for processing (6)
comments/utils.pyfront_end/messages/en.jsonfront_end/src/components/comment_feed/comment.tsxfront_end/src/components/comment_feed/comment_editor.tsxfront_end/src/utils/comments.tstests/unit/test_comments/test_utils.py

Summary
@predictorsautocomplete suggestion only shown to curators/admins (already existed)@predictorsFixes #4082
Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
@predictorsin comments. Only authorized users can send notifications to predictors.Improvements
@predictorsmentions now exclude users with withdrawn or expired forecasts, ensuring more accurate targeting of active forecasters.