Skip to content

Test and fix team invites#168

Merged
Marfuen merged 5 commits into
mainfrom
mariano/invites
Mar 21, 2025
Merged

Test and fix team invites#168
Marfuen merged 5 commits into
mainfrom
mariano/invites

Conversation

@Marfuen
Copy link
Copy Markdown
Contributor

@Marfuen Marfuen commented Mar 21, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced the invitation process to validate emails for greater security.
    • Introduced a dedicated error page with localized messages to help users navigate invitation issues.
  • Improvements

    • Refined layouts and menus so that admin-specific options are only shown to authorized users.
    • Updated the sign-out feature to support both button and menu interactions.
    • Adjusted various UI components for improved clarity and user experience.

Marfuen and others added 3 commits March 21, 2025 14:35
- Updated the `accept-invitation` action to validate invite codes more robustly and handle errors gracefully.
- Enhanced the `remove-member` action to ensure proper permission checks and revalidation after member removal.
- Introduced a new `IntegrationsLayout` component for admin access control in integrations.
- Added error handling for invitation issues in the `auth/invitation` route.
- Updated translations in `en.ts` for invitation error messages.
- Removed unused `onboarded` and `role` fields from the `User` model to streamline the database schema.
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 21, 2025

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

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 6:48pm
comp-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 6:48pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 21, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request implements several enhancements and refinements across the codebase. The invitation acceptance process has been updated to require an invited email and now uses a renamed function. Member removal logic has been expanded to update associated user details and sessions. Multiple dashboard layouts and authentication flows now incorporate additional admin validations and redirection, while various UI components receive admin flags for conditional rendering. Additionally, localized error messaging for invitations has been added and minor code reformatting updates have been applied across tasks, queries, and schema definitions.

Changes

File(s) Change Summary
apps/app/src/actions/organization/accept-invitation.ts, apps/app/src/app/(public)/auth/invite/[code]/route.ts, apps/app/src/api/auth/invitation/route.ts Updated invitation acceptance process: renamed acceptInvitation to completeInvitation, replaced findMemberByInviteCode with validateInviteCode (now with an extra invitedEmail parameter), and simplified error handling with enhanced email verification.
apps/app/src/actions/organization/remove-member.ts Enhanced member removal logic by restructuring the function to update the user's organization ID to null, delete related session records, and update revalidation paths.
apps/app/src/app/(public)/auth/page.tsx Refactored redirection and commentary to clarify the logic for authenticated users with or without an invite code.
apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/integrations/layout.tsx, apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/settings/layout.tsx Added session validation and admin access checks with redirects to enforce that only authorized (admin) users access certain dashboard areas.
apps/app/src/auth/config.ts, apps/app/src/auth/org.ts Updated authentication: modified the session callback to be asynchronous (including role and isAdmin properties) and removed automatic admin role assignment during organization creation.
apps/app/src/components/header.tsx, apps/app/src/components/main-menu.tsx, apps/app/src/components/mobile-menu.tsx, apps/app/src/components/sidebar.tsx, apps/app/src/components/sign-out.tsx, apps/portal/src/app/components/header.tsx UI component updates: introduced admin flag checks (e.g., hasAccess, userIsAdmin) to control menu rendering and sign-out functionalities, along with formatting adjustments.
apps/app/src/components/settings/team/members-list.tsx, apps/app/src/components/settings/team/team-members.tsx Modified team members components to conditionally render status badges (skipping for owners) and removed caching wrappers from data-fetching functions.
apps/app/src/locales/en.ts, apps/app/src/locales/es.ts, apps/app/src/locales/fr.ts, apps/app/src/locales/no.ts, apps/app/src/locales/pt.ts Added new localized error objects within the invitation section, providing specific messages and navigation labels for invitation errors.
apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/lib/utils.ts Added a "use server"; directive to ensure that the utility functions run in a server environment.
apps/app/src/jobs/tasks/organization/create-organization.ts Reformatted the organization creation task and its helper functions for consistency without functional changes.
apps/app/src/data/getOrganizations.ts Modified the organization query to include an OR condition to fetch organizations based on either accepted membership or owner role.
apps/app/src/store/user/store.ts Removed the onboarded property from the User type definition.
packages/db/prisma/migrations/20250321155359_remove_unwanted_columns_in_user_since_theyre_in_orgmember/migration.sql, packages/db/prisma/schema/schema.prisma Dropped unused columns (onboarded and role) from the User table and standardized whitespace/formatting in the Prisma schema.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Client/Browser
    participant R as Auth Route
    participant CI as completeInvitation
    participant DB as Database

    U->>C: Click invitation link with inviteCode
    C->>R: Request invitation acceptance
    R->>CI: Call completeInvitation(inviteCode, invitedEmail)
    CI->>DB: Validate invitation & update membership details
    alt Valid invitation
        DB-->>CI: Confirmation of update
        CI-->>R: Return accepted response
        R-->>C: Redirect to success page
    else Invalid invitation or error
        CI-->>R: Return error information
        R-->>C: Redirect to error page with message
    end
Loading

Possibly related PRs

  • Clean up (metadata) + fixes #51: Renaming of the invitation function to completeInvitation aligns closely with changes in this PR.
  • Lewis/pol #164: Similar modifications in invitation acceptance logic, specifically involving the function rename and enhanced email validation.
  • Mariano/deel import #110: Direct update to the invitation handling mechanism with a new implementation of completeInvitation mirrors changes in this PR.

Poem

I'm a little rabbit with ears so keen,
Hopping through code in a digital scene,
With invites validated and menus so bright,
I nibble on bugs 'til they take flight,
In a meadow of functions, I happily roam,
Celebrating changes that make our app feel like home!
🐇🌟


📜 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 5ef36fb and 04f2faf.

⛔ Files ignored due to path filters (1)
  • apps/app/languine.lock is excluded by !**/*.lock
📒 Files selected for processing (30)
  • apps/app/src/actions/organization/accept-invitation.ts (1 hunks)
  • apps/app/src/actions/organization/remove-member.ts (1 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/integrations/layout.tsx (1 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/lib/utils.ts (1 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/people/components/table/types.ts (0 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/[orgId]/settings/layout.tsx (2 hunks)
  • apps/app/src/app/[locale]/(public)/auth/invite/[code]/route.ts (1 hunks)
  • apps/app/src/app/[locale]/(public)/auth/invite/error/page.tsx (1 hunks)
  • apps/app/src/app/[locale]/(public)/auth/page.tsx (1 hunks)
  • apps/app/src/app/api/auth/invitation/route.ts (1 hunks)
  • apps/app/src/auth/config.ts (4 hunks)
  • apps/app/src/auth/org.ts (0 hunks)
  • apps/app/src/components/header.tsx (1 hunks)
  • apps/app/src/components/main-menu.tsx (4 hunks)
  • apps/app/src/components/mobile-menu.tsx (2 hunks)
  • apps/app/src/components/settings/team/members-list.tsx (1 hunks)
  • apps/app/src/components/settings/team/team-members.tsx (3 hunks)
  • apps/app/src/components/sidebar.tsx (1 hunks)
  • apps/app/src/components/sign-out.tsx (1 hunks)
  • apps/app/src/data/getOrganizations.ts (1 hunks)
  • apps/app/src/jobs/tasks/organization/create-organization.ts (1 hunks)
  • apps/app/src/locales/en.ts (1 hunks)
  • apps/app/src/locales/es.ts (1 hunks)
  • apps/app/src/locales/fr.ts (1 hunks)
  • apps/app/src/locales/no.ts (1 hunks)
  • apps/app/src/locales/pt.ts (1 hunks)
  • apps/app/src/store/user/store.ts (0 hunks)
  • apps/portal/src/app/components/header.tsx (1 hunks)
  • packages/db/prisma/migrations/20250321155359_remove_unwanted_columns_in_user_since_theyre_in_orgmember/migration.sql (1 hunks)
  • packages/db/prisma/schema/schema.prisma (4 hunks)
✨ 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.
    • 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.

Marfuen added 2 commits March 21, 2025 14:41
- Replaced `acceptInvitation` with `completeInvitation` in the invitation handling logic for better clarity.
- Improved error handling in the invitation process to ensure proper redirection on failure.
- Updated `MobileMenu` component to accept `isAdmin` prop for enhanced access control.
- Adjusted `Header` component to pass `isAdmin` state to `MobileMenu` for conditional rendering based on user permissions.
- Streamlined code formatting for better readability and maintainability.
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