feat(sidebar): hide unauthorized settings buttons in the sidebar for non-admins#596
feat(sidebar): hide unauthorized settings buttons in the sidebar for non-admins#596dembrane-sam-bot wants to merge 3 commits into
Conversation
|
Warning Review limit reached
More reviews will be available in 1 minute and 28 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughSettings access is now gated by admin role across home sidebar, settings navigation, and route logic. WorkspaceHomeView derives admin state; WorkspaceSettingsView conditionally renders admin-only nav items; WorkspaceSettingsRoute refactors default tab selection to use "settings:manage" policy. ChangesRole-based settings access control
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
|
Thank you for contributing to Dembrane ECHO! Before we consider your Pull Request, we ask that you sign our Contributor License Agreement (CLA). This is only required for your first Pull Request. Please review the CLA, and sign it by adding your GitHub username to the contributors.yml file. Thanks! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@echo/frontend/src/features/sidebar/views/workspace/WorkspaceHomeView.tsx`:
- Around line 35-39: The sidebar computes settingsPath but the Settings nav link
is still hardcoded to "/settings/general"; update the Settings nav target to use
the computed settingsPath (replace the hardcoded string used where the nav item
is rendered, e.g., the link or NavItem that currently points to
"/settings/general") so admins go to general and non-admins to billing or
members based on isAdmin/isBilling logic in WorkspaceHomeView and the
settingsPath constant.
In `@echo/frontend/src/routes/workspaces/WorkspaceSettingsRoute.tsx`:
- Around line 467-473: The current default-tab computation and redirect run
before `settings` is loaded causing wrong tab lock-in; update
`WorkspaceSettingsRoute` to defer computing `canEditSettings`/`defaultTab` and
performing the redirect until `settings` is non-null (or a loading flag is
false). Specifically, guard or delay the logic that reads
`settings?.my_policies` and `settings?.my_role` (the `canEditSettings` and
`defaultTab` calculations) and the subsequent redirect code block (the code
around lines handling tab selection/redirect) so it only executes when
`settings` is available, leaving the route idle or showing a loader until then.
Ensure `defaultTab: TabValue` is derived from `settings` inside that guarded
branch to avoid landing billing/admin users on `members` prematurely.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 54218718-1636-4600-a922-e623356f7b8d
📒 Files selected for processing (3)
echo/frontend/src/features/sidebar/views/workspace/WorkspaceHomeView.tsxecho/frontend/src/features/sidebar/views/workspace/WorkspaceSettingsView.tsxecho/frontend/src/routes/workspaces/WorkspaceSettingsRoute.tsx
| const canEditSettings = | ||
| settings?.my_policies?.includes("settings:manage") ?? false; | ||
| const defaultTab: TabValue = canEditSettings | ||
| ? "general" | ||
| : settings?.my_role === "billing" | ||
| ? "billing" | ||
| : "members"; |
There was a problem hiding this comment.
Defer default-tab redirect until settings are loaded.
Line 469 computes a fallback before settings exists, and Line 485 then locks in a valid but wrong segment. Billing/admin users can land on members from /settings and never get corrected.
Suggested fix
- const defaultTab: TabValue = canEditSettings
- ? "general"
- : settings?.my_role === "billing"
- ? "billing"
- : "members";
+ const defaultTab: TabValue | null = settings
+ ? canEditSettings
+ ? "general"
+ : settings.my_role === "billing"
+ ? "billing"
+ : "members"
+ : null;
const activeTab: TabValue = segmentIsValid
? (segment as TabValue)
- : defaultTab;
+ : (defaultTab ?? "members");
@@
useEffect(() => {
if (!workspaceId) return;
- if (segment !== activeTab) {
- navigate(`/w/${workspaceId}/settings/${activeTab}${urlSearch}`, {
+ if (!segmentIsValid) {
+ if (!defaultTab) return;
+ navigate(`/w/${workspaceId}/settings/${defaultTab}${urlSearch}`, {
replace: true,
});
}
- }, [workspaceId, segment, activeTab, navigate, urlSearch]);
+ }, [workspaceId, segmentIsValid, defaultTab, navigate, urlSearch]);Also applies to: 483-490
🤖 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 `@echo/frontend/src/routes/workspaces/WorkspaceSettingsRoute.tsx` around lines
467 - 473, The current default-tab computation and redirect run before
`settings` is loaded causing wrong tab lock-in; update `WorkspaceSettingsRoute`
to defer computing `canEditSettings`/`defaultTab` and performing the redirect
until `settings` is non-null (or a loading flag is false). Specifically, guard
or delay the logic that reads `settings?.my_policies` and `settings?.my_role`
(the `canEditSettings` and `defaultTab` calculations) and the subsequent
redirect code block (the code around lines handling tab selection/redirect) so
it only executes when `settings` is available, leaving the route idle or showing
a loader until then. Ensure `defaultTab: TabValue` is derived from `settings`
inside that guarded branch to avoid landing billing/admin users on `members`
prematurely.
What this changes
canEditSettingsvariable declaration inWorkspaceSettingsRoute.tsxand simplified default tab resolution.Confidence: High. Safe, client-side, UI-only change using the established
isAdminRoleand role-policies logic.Summary by CodeRabbit
New Features
Improvements