feat(web): conditionally show upgrade toast only to org owners#1024
feat(web): conditionally show upgrade toast only to org owners#1024ksg98 wants to merge 1 commit intosourcebot-dev:mainfrom
Conversation
Only org owners should see the upgrade notification toast. Non-owners and anonymous users no longer trigger the version check or see the popup. Fixes sourcebot-dev#815 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughThe changes implement owner-only gating for the UpgradeToast component by adding an Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 Tip CodeRabbit can suggest fixes for GitHub Check annotations.Configure the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/web/src/app/[domain]/components/upgradeToast.test.tsx (1)
75-77: Mock doesn't respectenabledoption, but test still validates correctly.The
useQuerymock always returns{ data: 'v1.0.0' }regardless of theenabledoption. In reality, whenenabled: false, react-query returnsundefinedfordata. The test still passes because the component'suseEffecthas an early return for!isOwner, so this doesn't cause a false positive.Consider making the mock more realistic for future-proofing:
♻️ Proposed improvement for mock fidelity
vi.mock('@tanstack/react-query', () => ({ - useQuery: () => ({ data: 'v1.0.0' }), + useQuery: ({ enabled = true }: { enabled?: boolean }) => ({ + data: enabled ? 'v1.0.0' : undefined, + }), }));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/web/src/app/`[domain]/components/upgradeToast.test.tsx around lines 75 - 77, The useQuery mock in the test is unrealistic because it always returns { data: 'v1.0.0' } even when the react-query `enabled` option is false; update the vi.mock for '@tanstack/react-query' so the mocked useQuery inspects the passed options (e.g., `options.enabled`) and returns { data: 'v1.0.0' } only when enabled is true/undefined, otherwise returns { data: undefined } to mirror real react-query behavior; target the mocked useQuery implementation in the test (the vi.mock block) and ensure it accepts the same args signature so tests that rely on `enabled` behave correctly (the component's useEffect and isOwner branches will then be validated realistically).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/web/src/app/`[domain]/components/upgradeToast.test.tsx:
- Around line 75-77: The useQuery mock in the test is unrealistic because it
always returns { data: 'v1.0.0' } even when the react-query `enabled` option is
false; update the vi.mock for '@tanstack/react-query' so the mocked useQuery
inspects the passed options (e.g., `options.enabled`) and returns { data:
'v1.0.0' } only when enabled is true/undefined, otherwise returns { data:
undefined } to mirror real react-query behavior; target the mocked useQuery
implementation in the test (the vi.mock block) and ensure it accepts the same
args signature so tests that rely on `enabled` behave correctly (the component's
useEffect and isOwner branches will then be validated realistically).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1a16f3b9-9f85-4408-866a-dde0fcd487d6
📒 Files selected for processing (3)
packages/web/src/app/[domain]/components/upgradeToast.test.tsxpackages/web/src/app/[domain]/components/upgradeToast.tsxpackages/web/src/app/[domain]/layout.tsx
Summary
isOwnerprop toUpgradeToastcomponent with early return guard in theuseEffectenabled: isOwnerto theuseQuerycall to skip the version API request entirely for non-ownersmembershipquery inlayout.tsxso the role is available at render timeisOwnergating behaviorTest plan
upgradeToast.test.tsxtests verify:isOwner=falseisOwner=trueFixes #815
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests