-
Notifications
You must be signed in to change notification settings - Fork 11.1k
feat: Ensure teams with conflicting slugs owned by the user are migrated(handled in backend, frontend already had this restriction) #25291
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
Conversation
…boarding - Added findOwnedTeamsByUserId method to TeamRepository - Created buildTeamsAndInvites method in BaseOnboardingService that automatically: - Detects teams with same slug as organization - Marks conflicting teams for migration (isBeingMigrated: true) - Filters empty team names and invite emails - Updated BillingEnabledOrgOnboardingService to use new method - Updated SelfHostedOnboardingService to use new method - Added comprehensive tests for slug conflict scenarios This ensures backend validation even if frontend is bypassed, preventing slug conflicts during organization creation. All inheriting classes automatically get this validation without code changes.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Refactored listOwnedTeamsHandler to use TeamRepository.findOwnedTeamsByUserId instead of direct Prisma queries. This: - Reduces code duplication - Ensures consistency across the codebase - Follows repository pattern - Makes the handler more maintainable
50980dd to
7494654
Compare
| ]; | ||
| } | ||
|
|
||
| protected async buildTeamsAndInvites( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed filterTeamsAndInvites -> buildTeamsAndInvites
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 6 files
- Renamed testFilterTeamsAndInvites to testBuildTeamsAndInvites - Made test wrapper method async to match the async buildTeamsAndInvites - Added orgSlug parameter to all test calls - Updated all 9 test cases to use await with the new method signature - Fixed lint warnings by using proper types instead of 'any' - Imported OnboardingIntentResult and User types - Used Pick<User> for mockUser type - Removed all 'as any' type casts Fixes test failures where filterTeamsAndInvites was renamed to buildTeamsAndInvites in the base service. Co-Authored-By: [email protected] <[email protected]>
Added vi.mock for TeamRepository to avoid database calls in unit tests. The buildTeamsAndInvites method now calls ensureConflictingSlugTeamIsMigrated which uses TeamRepository.findOwnedTeamsByUserId(). Mocking this prevents Prisma errors in CI while keeping the tests focused on filtering logic. The mock returns an empty array so no teams are found for migration, allowing the tests to verify the filtering behavior without database access. Co-Authored-By: [email protected] <[email protected]>
E2E results are ready! |
packages/features/ee/organizations/lib/service/onboarding/BaseOnboardingService.ts
Outdated
Show resolved
Hide resolved
Refactored the conditional logic in ensureConflictingSlugTeamIsMigrated for better readability while preserving exact behavior. Changed from manual array manipulation to using .map() for updating team migration status. This is a cosmetic change with no functional differences. Co-Authored-By: [email protected] <[email protected]>
|
Refactored for readability while preserving exact behavior. The code now uses |
Udit-takkar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now
What does this PR do?
This PR adds backend validation to prevent slug conflicts when creating organizations. It ensures that if a user owns a team with the same slug as the organization they're creating, that team is automatically marked for migration.
Key Changes:
findOwnedTeamsByUserIdmethod toTeamRepositoryto query teams where user is OWNER or ADMINbuildTeamsAndInvitesmethod inBaseOnboardingServicethat:isBeingMigrated: true)listOwnedTeamsHandlerto use the new repository method instead of direct Prisma queriesThis ensures backend validation even if frontend validation is bypassed, preventing slug conflicts during organization creation. All classes inheriting from
BaseOnboardingServiceautomatically get this validation.Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Test Scenario 1: Automatic Migration Detection
isBeingMigrated: trueTest Scenario 2: Existing Team in List
isBeingMigrated: falseisBeingMigrated: trueTest Scenario 3: Non-Conflicting Slugs
Test Scenario 4: Member Role
Environment Variables:
Human Review Checklist
Please pay special attention to:
Query Logic Equivalence: Verify that
TeamRepository.findOwnedTeamsByUserIdreturns the same results as the original Prisma query inlistOwnedTeamsHandler(filters organizations, checks OWNER/ADMIN roles, requires accepted membership)Automatic Migration Behavior: Confirm that automatically adding teams to the migration list is the desired behavior and won't cause unexpected side effects in production
Method Signature Change: The
filterTeamsAndInvitesmethod was changed to asyncbuildTeamsAndInvites. Verify all callers have been updated (bothBillingEnabledOrgOnboardingServiceandSelfHostedOnboardingService)Test Coverage: Review test scenarios, especially edge cases around:
Repository Pattern: Verify that instantiating
TeamRepositorydirectly inBaseOnboardingServicefollows the codebase's dependency injection patternsLink to Devin run: https://app.devin.ai/sessions/b90a924a3ffb4a0cb03cb0c79f5f98e0
Requested by: [email protected] (@hariombalhara)