Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Add Organization Name Constraint #3196

Merged
merged 3 commits into from
Mar 13, 2025

Conversation

scott-ray-wilson
Copy link
Contributor

@scott-ray-wilson scott-ray-wilson commented Mar 6, 2025 β€’

Description πŸ“£

This PR adds a alphanumeric and limit symbol constraint to organization names.

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests πŸ› οΈ

# Here's some code block to paste some code snippets

Summary by CodeRabbit

  • New Features
    • Enhanced organization name validation now enforces length and allowed character rules, providing clearer error messages during updates, creation, and sign-up.
    • Improved error feedback in the sign-up workflow ensures users receive better notifications when issues occur.
  • Refactor
    • Streamlined error handling by consolidating notification logic, resulting in more consistent error displays across interactions.
    • Adjusted modal behavior in the organization creation interface for a refined user experience.
    • Introduced a new schema for generic resource name validation, enhancing input validation across various components.

Copy link

coderabbitai bot commented Mar 6, 2025 β€’

Walkthrough

The changes introduce a new Zod schema named GenericResourceNameSchema in the backend, enforcing trimmed string inputs with a minimum of 1 and a maximum of 64 characters while allowing only specific characters. This schema replaces the previous inline validations for organization names in multiple routes (v1, v2, and v3) for both PATCH and POST operations, as well as in the signup flow. In the frontend, error handling has been refined by encapsulating Axios error logic in a new exported function onRequestError, which is now invoked in both the UserInfoStep component and the query client configuration. Additionally, the CreateOrgModal component is updated to include a modal={false} prop, potentially altering its display behavior.

Suggested reviewers

  • vmatsiiako

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

πŸ”§ ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

backend/src/server/routes/v2/organization-router.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".

(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/backend".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install @typescript-eslint/eslint-plugin@latest --save-dev

The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "backend/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

backend/src/server/routes/v1/organization-router.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".

(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/backend".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install @typescript-eslint/eslint-plugin@latest --save-dev

The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "backend/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

backend/src/server/lib/schemas.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "@typescript-eslint/eslint-plugin".

(The package "@typescript-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/backend".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install @typescript-eslint/eslint-plugin@latest --save-dev

The plugin "@typescript-eslint/eslint-plugin" was referenced from the config file in "backend/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 1 others

Tip

⚑πŸ§ͺ Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

πŸ“œ 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 abc2ffc and 76f3450.

πŸ“’ Files selected for processing (8)
  • backend/src/server/lib/schemas.ts (1 hunks)
  • backend/src/server/routes/v1/organization-router.ts (2 hunks)
  • backend/src/server/routes/v2/organization-router.ts (2 hunks)
  • backend/src/server/routes/v3/signup-router.ts (2 hunks)
  • frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx (2 hunks)
  • frontend/src/hooks/api/reactQuery.tsx (1 hunks)
  • frontend/src/lib/schemas/index.ts (1 hunks)
  • frontend/src/pages/organization/SettingsPage/components/OrgNameChangeSection/OrgNameChangeSection.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx
  • backend/src/server/routes/v3/signup-router.ts
  • backend/src/server/routes/v2/organization-router.ts
  • backend/src/server/routes/v1/organization-router.ts
  • backend/src/server/lib/schemas.ts
  • frontend/src/hooks/api/reactQuery.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Check TS and Lint
  • GitHub Check: Check Frontend Type and Lint check
  • GitHub Check: Run integration test
  • GitHub Check: Check API Changes
πŸ”‡ Additional comments (4)
frontend/src/pages/organization/SettingsPage/components/OrgNameChangeSection/OrgNameChangeSection.tsx (2)

17-17: LGTM! Good addition of the import.

Adding the import for the new GenericResourceNameSchema is appropriate for the schema change below.


20-20: LGTM! Consistent validation implementation.

Replacing the inline string validation with the reusable GenericResourceNameSchema ensures consistent organization name validation across the application. This is a good improvement that helps maintain uniform constraints.

frontend/src/lib/schemas/index.ts (2)

1-2: LGTM! Required import for zod.

Adding the import for zod is necessary for defining the new schema.


5-13: LGTM! Well-defined organization name constraints.

The GenericResourceNameSchema properly implements the organization name constraints with:

  • Appropriate trimming of input
  • Reasonable length limits (1-64 characters)
  • Clear error messages
  • A regex that restricts to alphanumeric characters, dashes, underscores, and spaces

This implementation aligns well with the PR objective of introducing constraints on organization names.

✨ Finishing Touches
  • πŸ“ Generate Docstrings

πŸͺ§ 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

@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 (2)
frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx (1)

12-15: Frontend schema doesn't match backend constraints.

The frontend form validation only checks if the name is non-empty but doesn't enforce the same constraints as the new backend OrganizationNameSchema, which requires alphanumeric characters with limited symbols and max length of 64 characters.

Consider updating the schema to match backend constraints:

const schema = z
  .object({
-    name: z.string().nonempty({ message: "Name is required" })
+    name: z.string()
+      .trim()
+      .nonempty({ message: "Name is required" })
+      .max(64, { message: "Name must be 64 or fewer characters" })
+      .regex(/^[a-zA-Z0-9\-_\s]+$/, "Name can only contain alphanumeric characters, dashes, underscores, and spaces")
  })
  .required();
frontend/src/components/auth/UserInfoStep.tsx (1)

250-257: Organization name field lacks client-side pattern validation.

While the input has maxLength={64} which matches the backend constraint, it doesn't validate the character pattern (alphanumeric, dashes, underscores, spaces) enforced by the backend.

Consider adding a pattern check or using a controlled input with validation before submission to provide immediate feedback to users.

πŸ“œ Review details

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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 706feaf and abc2ffc.

πŸ“’ Files selected for processing (7)
  • backend/src/server/lib/schemas.ts (1 hunks)
  • backend/src/server/routes/v1/organization-router.ts (2 hunks)
  • backend/src/server/routes/v2/organization-router.ts (2 hunks)
  • backend/src/server/routes/v3/signup-router.ts (2 hunks)
  • frontend/src/components/auth/UserInfoStep.tsx (2 hunks)
  • frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx (1 hunks)
  • frontend/src/hooks/api/reactQuery.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Check Frontend Type and Lint check
  • GitHub Check: Run integration test
  • GitHub Check: Check API Changes
  • GitHub Check: Check TS and Lint
πŸ”‡ Additional comments (12)
frontend/src/components/organization/CreateOrgModal/CreateOrgModal.tsx (1)

80-81:

❓ Verification inconclusive

Modal property update may affect behavior.

The modal={false} property has been added to the Modal component. This property likely affects the modal's behavior, possibly disabling backdrop click-to-close functionality or changing how it interacts with the page.


🏁 Script executed:

#!/bin/bash
# Check Modal component implementation to understand impact of modal={false}
fd --type file -e tsx -e jsx Modal.tsx | grep -v "node_modules" | xargs rg "modal(\s*)=(\s*)" -A 5 -B 5

Length of output: 1180


Action: Verify Modal Behavior Adjustments

The addition of the modal={false} prop in <Modal modal={false} isOpen={isOpen}> may change how the modal behaves (for instance, disabling backdrop click-to-close or altering interaction patterns). Please confirm that this behavior is intentional and update any related UI tests or documentation if necessary.

  • Verify that the modified behavior matches design expectations.
  • Double-check if any related modal functionality (like user interactions or other modal props) requires adjustment in light of this change.
backend/src/server/lib/schemas.ts (1)

25-30: Good implementation of organization name constraints.

The new OrganizationNameSchema properly enforces alphanumeric input with specific allowed symbols (dashes, underscores, spaces) and appropriate length constraints. This implementation aligns well with the PR objective.

frontend/src/components/auth/UserInfoStep.tsx (2)

14-14: Improved error handling with onRequestError.

Adding the error handling function provides better user feedback when API requests fail, which is a good practice.


210-210: Error handling implementation is correct.

The onRequestError function is properly called in the catch block to handle any request errors during account signup.

backend/src/server/routes/v2/organization-router.ts (2)

15-15: Good schema import.

Importing the centralized OrganizationNameSchema promotes consistency and reusability across routes.


334-334: Proper schema enforcement in organization creation route.

The organization creation endpoint now correctly uses the OrganizationNameSchema to validate input, enforcing the name constraints consistently with other parts of the application.

backend/src/server/routes/v3/signup-router.ts (2)

7-7: Added import for consistent organization name validation.

Good addition of the OrganizationNameSchema import to enforce standardized validation for organization names.


104-104: Improved validation for organization names.

Great refactoring to use the centralized OrganizationNameSchema instead of the inline validation. This ensures consistent enforcement of organization name constraints across the application.

backend/src/server/routes/v1/organization-router.ts (2)

16-16: Added imports for schema validation.

Good import of OrganizationNameSchema alongside the existing slugSchema. This ensures consistent organization name validation.


254-254: Standardized organization name validation.

Excellent replacement of the inline validation with the centralized OrganizationNameSchema. This ensures that organization names are consistently validated across different API routes and maintains the optional nature of this field for PATCH operations.

frontend/src/hooks/api/reactQuery.tsx (2)

25-187: Refactored error handling into a reusable function.

Great refactoring of the error handling logic into a separate onRequestError function. This improves code organization and makes the error handling more consistent across the application. The function handles validation errors, forbidden errors, and generic request errors with appropriate notifications.

A few observations:

  1. The function provides detailed error information in modals for ValidationError and ForbiddenError
  2. It maintains request ID for all error types, which is helpful for debugging
  3. The error messages are formatted consistently

189-192: Simplified mutation cache error handling.

Good refactoring to use the extracted onRequestError function in the mutation cache configuration. This makes the code more concise and ensures consistent error handling.

@scott-ray-wilson scott-ray-wilson merged commit d9d6238 into main Mar 13, 2025
7 of 8 checks passed
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