Skip to content

Comments

fix: add users to managed event types when auto-accepting sub-team memberships#24392

Closed
joeauyeung wants to merge 3 commits intomainfrom
devin/1760028997-fix-auto-accept-managed-event-types
Closed

fix: add users to managed event types when auto-accepting sub-team memberships#24392
joeauyeung wants to merge 3 commits intomainfrom
devin/1760028997-fix-auto-accept-managed-event-types

Conversation

@joeauyeung
Copy link
Contributor

@joeauyeung joeauyeung commented Oct 9, 2025

What does this PR do?

Fixes a bug where users auto-accepted to sub teams via domain matching were not being automatically added to managed event types with assignAllTeamMembers: true.

Root Cause: The invitation flow was missing calls to updateNewTeamMemberEventTypes in two scenarios:

  1. When existing users are auto-accepted to the parent organization (which batch-accepts pending sub-team memberships)
  2. When new users are invited directly to sub-teams with matching auto-accept domains

Solution: Added the missing updateNewTeamMemberEventTypes calls in both code paths to ensure users get properly assigned to managed event types.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - This is a bug fix that doesn't change the documented API or user-facing behavior.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Integration Tests: Added comprehensive integration tests that verify both scenarios work correctly. The tests:

  1. Create organizations with auto-accept domains
  2. Set up managed event types with assignAllTeamMembers: true
  3. Simulate the invitation flows
  4. Verify that child event types are created for the users

Manual Testing (if needed):

  1. Set up an organization with orgAutoAcceptEmail domain matching
  2. Create a sub-team with a managed event type (assignAllTeamMembers: true)
  3. Test both scenarios:
    • Invite existing user to organization → verify they get added to sub-team managed event types
    • Invite new user directly to sub-team → verify they get added to managed event types

Key Changes

Bug Fix #1: Existing users auto-accepted to org

// Before: Only batch-accepted sub-team memberships, didn't call updateNewTeamMemberEventTypes
// After: Query pending memberships first, then call updateNewTeamMemberEventTypes for each
const pendingSubTeamMemberships = await prisma.membership.findMany({...});
await prisma.membership.updateMany({...}); 
await Promise.all(
  pendingSubTeamMemberships.map(({ teamId }) => updateNewTeamMemberEventTypes(user.id, teamId))
);

Bug Fix #2: New users invited to sub-team

// Before: Created users but never called updateNewTeamMemberEventTypes
// After: Filter auto-accepted users and add them to managed event types
const createdUsers = await createNewUsersConnectToOrgIfExists({...});
const autoAcceptedUsers = createdUsers.filter(
  (user) => orgConnectInfoByUsernameOrEmail[user.email].autoAccept
);
await Promise.all(autoAcceptedUsers.map((user) => updateNewTeamMemberEventTypes(user.id, teamId)));

Review Focus Areas

  • Database Query Logic: Verify the query for pending sub-team memberships captures the correct memberships
  • Auto-Accept Detection: Confirm the filtering logic orgConnectInfoByUsernameOrEmail[user.email].autoAccept works correctly
  • Performance: Consider impact of additional database queries in organizations with many sub-teams
  • Integration Tests: Review test scenarios match the actual bug conditions

Link to Devin run: https://app.devin.ai/sessions/c0d0a43edbe6412dbec727ffd00e1e6f
Requested by: @joeauyeung

…mberships

When a user is auto-accepted to a parent organization, their pending sub-team
memberships are batch-accepted, but updateNewTeamMemberEventTypes was never
called for those sub teams. This caused users to not be added to managed event
types with assignAllTeamMembers: true.

This fix queries for pending sub-team memberships before accepting them, then
calls updateNewTeamMemberEventTypes for each newly-accepted sub team to ensure
users are properly added to managed event types.

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Oct 9, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1760028997-fix-auto-accept-managed-event-types

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>
@vercel
Copy link

vercel bot commented Oct 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Oct 9, 2025 8:28pm
cal-eu Ignored Ignored Oct 9, 2025 8:28pm

…ment

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>
@github-actions
Copy link
Contributor

This PR is being marked as stale due to inactivity.

@joeauyeung
Copy link
Contributor Author

Closing in favour of #24731 (review)

@joeauyeung joeauyeung closed this Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO size/L Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The getIntegrations function runs repeatedly due to state polling

2 participants