Skip to content

Conversation

@raghavyuva
Copy link
Owner

@raghavyuva raghavyuva commented Jun 30, 2025

Summary by CodeRabbit

  • New Features

    • Introduced role-based access control (RBAC) for various settings sections, including account management, avatar upload, feature flags, security, and two-factor authentication actions.
    • Feature Flags tab and controls are now conditionally visible and interactive based on user permissions.
    • Notification settings tabs and layout adjust dynamically based on feature flag permissions.
  • Refactor

    • Updated access control logic for feature flag API endpoints, separating read and write operations for improved permission handling.
    • Modified permission guard components to require explicit fallback behavior, removing default access denied messaging.
  • Chores

    • Updated API version metadata formatting for consistency.

@keploy
Copy link

keploy bot commented Jun 30, 2025

To generate Unit Tests for this PR, please click here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

This update introduces comprehensive role-based access control (RBAC) checks throughout the application's settings UI and API. It restructures feature flag API routes to separate read and write access, applies RBAC guards to various UI components, and adjusts tab visibility and layouts based on user permissions. Minor formatting and fallback handling changes are also included.

Changes

File(s) Change Summary
api/api/versions.json Updated "release_date" and reformatted the "changes" field for metadata clarity.
api/internal/routes.go Split feature flag routes into separate read/write groups; updated RBAC middleware application and method signature.
view/app/settings/general/components/AccountSection.tsx
view/app/settings/general/components/AvatarSection.tsx
view/app/settings/general/components/SecuritySection.tsx
view/app/settings/general/components/TwoFactorSetup.tsx
Wrapped interactive UI elements and action buttons in RBACGuard components to enforce user permission checks.
view/app/settings/general/components/FeatureFlagsSettings.tsx Wrapped the component and individual toggles with RBACGuard for read and update permissions, respectively.
view/app/settings/general/page.tsx
view/app/settings/notifications/page.tsx
Conditionally rendered tabs and adjusted layouts based on feature flag read permissions using useRBAC.
view/components/rbac/PermissionGuard.tsx Removed AccessDenied fallback; fallback prop is now passed directly without defaulting to AccessDenied.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI_Component
    participant RBACGuard
    participant Server

    User->>UI_Component: Attempt interactive action (e.g., update avatar, toggle flag)
    UI_Component->>RBACGuard: Check permission (resource, action)
    alt Permission granted
        RBACGuard-->>UI_Component: Allow action/render
        UI_Component->>Server: Send request (if applicable)
        Server-->>UI_Component: Respond with result
    else Permission denied
        RBACGuard-->>UI_Component: Block action/hide element
    end
Loading
sequenceDiagram
    participant Client
    participant API_ReadGroup
    participant API_WriteGroup
    participant RBAC_Middleware

    Client->>API_ReadGroup: GET /feature-flags
    API_ReadGroup-->>Client: Return feature flags (no RBAC)

    Client->>API_WriteGroup: PUT /feature-flags
    API_WriteGroup->>RBAC_Middleware: Check write permission
    alt Permission granted
        RBAC_Middleware-->>API_WriteGroup: Allow
        API_WriteGroup-->>Client: Update feature flag
    else Permission denied
        RBAC_Middleware-->>API_WriteGroup: Deny
        API_WriteGroup-->>Client: Access denied
    end
Loading

Poem

In the warren of code, permissions now hop,
With RBAC in place, only right paws can swap.
Feature flags guarded, tabs now appear,
Only for bunnies with access so clear.
Buttons and toggles, all checked with care—
Secure little burrows, everywhere!
🐇🔒

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@raghavyuva
Copy link
Owner Author

raghavyuva commented Jun 30, 2025

@coderabbitai pause

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

Tip

For best results, initiate chat on the files or code changes.

@raghavyuva I've stopped the review process as requested. The current review operation has been halted.

For future reference, you can also use @coderabbitai pause to pause reviews on a PR, and @coderabbitai resume to resume them when you're ready.

🐰 stops mid-hop and sits quietly

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
view/app/settings/general/components/SecuritySection.tsx (1)

54-63: LGTM! Appropriate RBAC protection for password reset.

The RBAC guard correctly protects the password reset functionality with resource="user" action="update".

Consider adding a fallback prop to provide user feedback when the action is not permitted, rather than having the button disappear entirely.

-            <RBACGuard resource="user" action="update">
+            <RBACGuard 
+              resource="user" 
+              action="update"
+              fallback={<p className="text-sm text-muted-foreground">{t('settings.security.password.reset.noPermission')}</p>}
+            >
view/app/settings/general/components/AvatarSection.tsx (1)

24-30: LGTM! Consistent RBAC protection for avatar updates.

The RBAC guard appropriately protects avatar upload functionality with resource="user" action="update", maintaining consistency with other user settings components.

Similar to SecuritySection.tsx, consider adding a fallback to inform users when they lack permission to update their avatar.

-          <RBACGuard resource="user" action="update">
+          <RBACGuard 
+            resource="user" 
+            action="update"
+            fallback={<p className="text-sm text-muted-foreground text-center">{t('settings.account.avatar.noPermission')}</p>}
+          >
view/app/settings/general/components/FeatureFlagsSettings.tsx (1)

58-104: Consider the user experience impact of nested RBAC guards.

The nested RBAC structure (outer read guard, inner update guards) is logically correct but may create a confusing user experience. Users with read-only permissions will see the feature toggles but won't be able to interact with them, potentially leading to frustration.

Consider either:

  1. Adding visual indicators (e.g., tooltips) explaining why switches are disabled
  2. Restructuring to hide the switches entirely for users without update permissions

The current implementation is functionally correct but could benefit from UX improvements.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24d196c and be1c1f8.

📒 Files selected for processing (10)
  • api/api/versions.json (1 hunks)
  • api/internal/routes.go (2 hunks)
  • view/app/settings/general/components/AccountSection.tsx (6 hunks)
  • view/app/settings/general/components/AvatarSection.tsx (2 hunks)
  • view/app/settings/general/components/FeatureFlagsSettings.tsx (2 hunks)
  • view/app/settings/general/components/SecuritySection.tsx (2 hunks)
  • view/app/settings/general/components/TwoFactorSetup.tsx (4 hunks)
  • view/app/settings/general/page.tsx (3 hunks)
  • view/app/settings/notifications/page.tsx (3 hunks)
  • view/components/rbac/PermissionGuard.tsx (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
view/app/settings/general/components/AvatarSection.tsx (1)
view/components/rbac/RBACGuard.tsx (1)
  • RBACGuard (16-59)
view/app/settings/notifications/page.tsx (1)
view/lib/rbac.ts (1)
  • useRBAC (26-58)
🔇 Additional comments (6)
api/api/versions.json (1)

6-10: LGTM! Routine version metadata update.

The release date update and formatting improvement for the changes array are appropriate for this PR.

api/internal/routes.go (2)

225-235: LGTM! Excellent separation of read/write access for feature flags.

The architectural decision to allow unrestricted read access while protecting write operations with RBAC is sound and follows the principle of least privilege.


392-396: FeatureFlagRoutes signature usage verified
All calls to FeatureFlagRoutes have been updated to the new (readGroup, writeGroup, controller) signature.
• api/internal/routes.go:

router.FeatureFlagRoutes(featureFlagReadGroup, featureFlagWriteGroup, featureFlagController)
view/app/settings/general/components/TwoFactorSetup.tsx (1)

19-19: RBAC implementation looks good and consistent.

The RBAC guards are properly implemented around all 2FA action buttons using consistent resource="user" and action="update" permissions. This appropriately restricts 2FA management operations to users with update permissions on user resources.

Also applies to: 74-78, 87-91, 114-122

view/app/settings/general/page.tsx (1)

12-13: Proper conditional rendering based on RBAC permissions.

The implementation correctly uses canAccessResource('feature-flags', 'read') to conditionally render the Feature Flags tab and dynamically adjust the grid layout. This provides a clean user experience where users only see tabs they have permission to access.

Also applies to: 17-17, 43-44, 53-59, 98-98

view/app/settings/general/components/AccountSection.tsx (1)

25-25: Consistent RBAC implementation across user preference controls.

The RBAC guards are consistently applied to all user preference controls using the appropriate resource="user" and action="update" permissions. This creates a uniform access control pattern across username updates, email verification, theme settings, font preferences, language selection, and auto-update configuration.

Also applies to: 122-129, 161-174, 202-204, 208-243, 257-263, 277-283

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

✅ Actions performed

Reviews paused.

@raghavyuva raghavyuva self-assigned this Jun 30, 2025
@raghavyuva raghavyuva moved this to In progress in Nixopus Jun 30, 2025
@raghavyuva raghavyuva added this to the Beta Release milestone Jun 30, 2025
@raghavyuva raghavyuva merged commit 50c73b6 into master Jun 30, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Nixopus Jun 30, 2025
@raghavyuva raghavyuva deleted the feat/team-management branch June 30, 2025 15:58
zhravan pushed a commit to zhravan/nixopus that referenced this pull request Sep 2, 2025
Feat: Team Management With Permissions and Roles
@coderabbitai coderabbitai bot mentioned this pull request Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants