Skip to content

Conversation

@hariombalhara
Copy link
Member

@hariombalhara hariombalhara commented Nov 20, 2025

What does this PR do?

Fixes a critical bug in the organization onboarding flow where new teams (id === -1) with slugs matching the organization slug were being incorrectly marked for migration instead of being created as new teams.

The Problem:
When a user adds a new team during organization onboarding with a slug that matches the organization slug, the backend was auto-enabling migration for that team. Since new teams have id === -1, this caused them to be treated as existing teams to migrate, resulting in the team not being created at all.

The Solution:

  1. Scope auto-migration logic to only apply to existing teams (id !== -1) with matching org slug
  2. Add safety check in createOrMoveTeamsToOrganization to prevent moving teams with id === -1
  3. Preserve teams without names if they are being migrated (id !== -1), as the name is not required for migration

Changes:

  • Modified filterTeamsAndInvites to accept optional orgSlug parameter
  • Updated auto-migration logic: slugConflictsWithOrg && team.id !== -1
  • Added guard in createOrMoveTeamsToOrganization: team.isBeingMigrated && team.id !== -1
  • Updated all callers to pass organization slug
  • Added comprehensive test coverage for edge cases

Mandatory Tasks

  • I have self-reviewed the code
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - Internal logic change, no API changes
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Test Scenario 1: New team with matching org slug

  1. Create organization with slug "acme"
  2. Add a new team (id === -1) with slug "acme" during onboarding
  3. Expected: Team should be created as a new team, NOT migrated
  4. Verify: Team exists in database with correct slug

Test Scenario 2: Existing team with matching org slug

  1. User has existing team with slug "acme"
  2. Create organization with slug "acme"
  3. Add the existing team (id !== -1, slug "acme") during onboarding
  4. Expected: Team should be auto-marked for migration
  5. Verify: Team is moved to organization, not duplicated

Test Scenario 3: Teams without names being migrated

  1. Add existing team (id !== -1) with empty name and isBeingMigrated = true
  2. Expected: Team should be kept (not filtered out)
  3. Verify: Team is successfully migrated despite empty name

Environment:

  • No special environment variables required
  • Standard Cal.com database setup

Human Review Checklist

Critical Items to Verify:

  • Auto-migration logic: Confirm that slugConflictsWithOrg && team.id !== -1 correctly identifies only existing teams for auto-migration
  • New team handling: Verify new teams (id === -1) with matching org slug are never auto-migrated
  • Safety check: Review the guard in createOrMoveTeamsToOrganization prevents invalid team moves
  • Empty name handling: Confirm teams without names are only filtered if id === -1 (new teams)
  • Test coverage: Validate that test cases cover all critical edge cases, especially the combination of:
    • New team + matching slug (should NOT migrate)
    • Existing team + matching slug (should migrate)
    • Existing team + empty name + being migrated (should keep)

Session Info:

Checklist

  • I have read the contributing guide
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have checked if my changes generate no new warnings

…ation for teams with org slug

- Keep teams without names if they are being migrated (ID !== -1)
- Auto-enable migration for teams where team.slug === organization.slug
- Add backend safety measure matching frontend behavior
- Add comprehensive tests for both fixes

Co-Authored-By: [email protected] <[email protected]>
@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 Nov 20, 2025
- Only auto-enable migration for existing teams (id !== -1) with matching org slug
- New teams (id === -1) with matching org slug remain as new teams to be created
- Add safety check in createOrMoveTeamsToOrganization to prevent moving new teams
- Add test for new team with matching org slug to ensure it's not auto-migrated
- Update existing test to reflect correct behavior for teams with empty names

Co-Authored-By: [email protected] <[email protected]>
@vercel
Copy link

vercel bot commented Nov 20, 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 Nov 20, 2025 7:13am
cal-eu Ignored Ignored Nov 20, 2025 7:13am

@devin-ai-integration devin-ai-integration bot changed the title fix: preserve teams being migrated without names and auto-enable migration for teams with org slug fix: prevent auto-migration of new teams with matching org slug Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants