Skip to content

fix: managers should not be allowed to create api keys#5409

Merged
victorvhs017 merged 4 commits intomainfrom
restrict-managers-from-creating-api-keys
Apr 17, 2025
Merged

fix: managers should not be allowed to create api keys#5409
victorvhs017 merged 4 commits intomainfrom
restrict-managers-from-creating-api-keys

Conversation

@Dhruwang
Copy link
Copy Markdown
Member

@Dhruwang Dhruwang commented Apr 17, 2025

What does this PR do?

Fixes #(issue)

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Summary by CodeRabbit

  • New Features
    • Updated API key management permissions to restrict create, update, and delete actions to organization owners only; managers no longer have access.
    • API keys settings navigation and UI now visible and accessible exclusively to organization owners.
  • Chores
    • Removed the "Powered by Formbricks" branding translation key from all supported languages.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview Apr 17, 2025 0:24am

@Dhruwang Dhruwang requested a review from victorvhs017 April 17, 2025 08:55
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 17, 2025

Thank you for following the naming conventions for pull request titles! 🙏

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 17, 2025

"""

Walkthrough

This change restricts API key management actions within the organization settings to users with the "owner" role by removing the "manager" role from authorization checks in the relevant backend actions. The frontend permission checks and UI components were updated accordingly: access is now limited exclusively to owners, with non-owners immediately blocked from page rendering. The navigation menu for organization settings was modified to hide the API keys section from non-owners. Additionally, the translation key for "powered by Formbricks" was removed from multiple localization files, including German, English, French, Brazilian Portuguese, Portuguese (Portugal), and Traditional Chinese. No changes were made to the signatures or declarations of exported or public entities, except for the removal of the translation key in the localization files.

Suggested reviewers

  • gupta-piyush19
    """

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8c2a18a and ea4d650.

📒 Files selected for processing (1)
  • apps/web/modules/organization/settings/api-keys/page.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/modules/organization/settings/api-keys/page.tsx
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Run E2E Tests / Run E2E Tests
  • GitHub Check: Run Unit Tests / Unit Tests
  • GitHub Check: Build Formbricks-web / Build Formbricks-web
  • GitHub Check: Run Linters / Linters
  • GitHub Check: Validate Docker Build
  • GitHub Check: SonarQube
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Tusk Tester

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (1)
apps/web/modules/organization/settings/api-keys/page.tsx (1)

45-45: Consider renaming prop for consistency with variable naming.

While the permission check works correctly, there's a minor inconsistency between the variable name isNotOwner and the prop name isReadOnly. Consider renaming for better code clarity.

-            isReadOnly={isNotOwner}
+            isNotOwner={isNotOwner}

This would require updating the prop name in the ApiKeyList component as well.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5b9bf3f and d337071.

📒 Files selected for processing (8)
  • apps/web/modules/organization/settings/api-keys/actions.ts (3 hunks)
  • apps/web/modules/organization/settings/api-keys/page.tsx (3 hunks)
  • packages/lib/messages/de-DE.json (0 hunks)
  • packages/lib/messages/en-US.json (0 hunks)
  • packages/lib/messages/fr-FR.json (0 hunks)
  • packages/lib/messages/pt-BR.json (0 hunks)
  • packages/lib/messages/pt-PT.json (0 hunks)
  • packages/lib/messages/zh-Hant-TW.json (0 hunks)
💤 Files with no reviewable changes (6)
  • packages/lib/messages/de-DE.json
  • packages/lib/messages/en-US.json
  • packages/lib/messages/fr-FR.json
  • packages/lib/messages/pt-BR.json
  • packages/lib/messages/zh-Hant-TW.json
  • packages/lib/messages/pt-PT.json
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Run E2E Tests / Run E2E Tests
  • GitHub Check: Build Formbricks-web / Build Formbricks-web
  • GitHub Check: Run Linters / Linters
  • GitHub Check: Run Unit Tests / Unit Tests
  • GitHub Check: SonarQube
  • GitHub Check: Validate Docker Build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Tusk Tester
🔇 Additional comments (5)
apps/web/modules/organization/settings/api-keys/actions.ts (3)

28-28: Permission restriction applied correctly.

The authorization roles for deleting API keys have been restricted to only "owner", removing "manager" from the allowed roles. This change aligns with the PR objective to limit API key management to owners only.


50-50: Permission restriction applied correctly.

The authorization roles for creating API keys have been restricted to only "owner", removing "manager" from the allowed roles. This change directly addresses the core objective of the PR to prevent managers from creating API keys.


72-72: Permission restriction applied correctly.

The authorization roles for updating API keys have been restricted to only "owner", removing "manager" from the allowed roles. This change consistently applies the owner-only restriction across all API key operations.

apps/web/modules/organization/settings/api-keys/page.tsx (2)

22-22: Variable name change is appropriate for the new permission model.

The variable has been renamed to isNotOwner which clearly indicates the permission check being performed. This boolean will be true for any non-owner roles (including managers).


34-37: Alert warning updated correctly for non-owners.

The condition for displaying the warning now uses isNotOwner, correctly showing the alert to managers and other non-owner roles. The alert formatting with size "small" makes the warning less intrusive while still being clear about the permission restriction.

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
apps/web/modules/organization/settings/api-keys/page.tsx (1)

47-47: Inconsistent prop naming

The prop name isReadOnly doesn't match the variable name isNotOwner, which could be confusing. Consider renaming the prop to match the variable name for better readability and maintainability.

- isReadOnly={isNotOwner}
+ isNotOwner={isNotOwner}

This would require updating the ApiKeyList component to use the isNotOwner prop instead of isReadOnly.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d337071 and 6dcc986.

📒 Files selected for processing (2)
  • apps/web/app/(app)/environments/[environmentId]/settings/(organization)/components/OrganizationSettingsNavbar.tsx (2 hunks)
  • apps/web/modules/organization/settings/api-keys/page.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Run E2E Tests / Run E2E Tests
  • GitHub Check: Build Formbricks-web / Build Formbricks-web
  • GitHub Check: Run Linters / Linters
  • GitHub Check: Run Unit Tests / Unit Tests
  • GitHub Check: SonarQube
  • GitHub Check: Validate Docker Build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Tusk Tester
🔇 Additional comments (3)
apps/web/app/(app)/environments/[environmentId]/settings/(organization)/components/OrganizationSettingsNavbar.tsx (2)

25-25: Extraction of owner role for access control

Good addition to extract isOwner alongside isMember from getAccessFlags. This properly separates the role-based access control concerns.


62-62: Effective restriction of API keys navigation to owners only

This change properly restricts the visibility of the API keys navigation item to owners only, which aligns with the PR objective to prevent managers from creating API keys.

apps/web/modules/organization/settings/api-keys/page.tsx (1)

22-24: Unauthorized access handling implemented correctly

Good implementation of the server-side check that prevents non-owners from accessing the API keys page. This effectively addresses the comment from the previous review about preventing access when the route is accessed directly.

@Dhruwang Dhruwang enabled auto-merge April 17, 2025 12:22
@sonarqubecloud
Copy link
Copy Markdown

@use-tusk
Copy link
Copy Markdown
Contributor

use-tusk bot commented Apr 17, 2025

✅ Generated 3 tests - 3 passed (ea4d650) View tests ↗

View output in GitHub ↗

Test Summary

  • APIKeysPage - 3 ✅
View check history

Commit Status Output Tests Passed Failed Error
d337071 ⏩ No tests generated Output
6dcc986 🚫 Cancelled due to new commit on branch Output
8c2a18a 🚫 Cancelled due to new commit on branch Output
ea4d650 ✅ Generated 3 tests - 3 passed Tests 3 3 0 0

@Dhruwang Dhruwang added this pull request to the merge queue Apr 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 17, 2025
@Dhruwang Dhruwang added this pull request to the merge queue Apr 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 17, 2025
@victorvhs017 victorvhs017 added this pull request to the merge queue Apr 17, 2025
Merged via the queue into main with commit 2e979c7 Apr 17, 2025
21 checks passed
@victorvhs017 victorvhs017 deleted the restrict-managers-from-creating-api-keys branch April 17, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants