fix: APIV2 team membership - Member not getting added to event-type automatically (#24780)
* fix: APIV2 team membership addition * feat: Add trimming for email domain and orgAutoAcceptEmail in auto-accept logic - Trim whitespace from both user email domain and orgAutoAcceptEmail - Ensures consistent matching even with accidental whitespace - Addresses feedback from PR review Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * simplify * feat: Use shared OrganizationMembershipService in TRPC for consistent auto-accept logic - Create OrganizationMembershipService.container.ts for DI in TRPC - Update getOrgConnectionInfo to apply trimming + case-insensitive comparison - Precompute auto-accept decisions in createNewUsersConnectToOrgIfExists using the service - Use service in handleNewUsersInvites for consistent auto-accept determination - Ensures both API v2 and TRPC paths use identical trimming and normalization logic Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Revert "feat: Use shared OrganizationMembershipService in TRPC for consistent auto-accept logic" This reverts commit 0b2bd28b6e32e8c1d3dea139ca8ff9cbf402ac00. * refactor: Unify OrganizationRepository and remove duplicate PrismaOrganizationRepository (#24869) * refactor: Convert OrganizationRepository from static to instance methods - Add constructor accepting deps object with prismaClient - Convert all static methods to instance methods - Add getOrganizationAutoAcceptSettings method - Create singleton instance export in repository barrel file - Update API v2 OrganizationsRepository to extend from OrganizationRepository - Update all call sites to use singleton instance - Add platform-libraries organizations.ts export - Fix mock imports to use repository barrel - Fix unsafe optional chaining in next-auth-options.ts - Fix any types in test files with proper type inference Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update all imports to use OrganizationRepository barrel export - Update imports from direct OrganizationRepository file to barrel export - This ensures mocks work correctly in tests - Fixes 202 failing tests related to organizationRepository mock Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update test mocks to use partial mock pattern - Convert organizationMock to partial mock that preserves real class - Add proper prisma mocks to failing test files - Remove old OrganizationRepository mocks from test files - This fixes test failures related to mock interception Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Export mocked singleton and update tests to use it directly - Export mockedSingleton as organizationRepositoryMock from organizationMock - Update delegationCredential.test.ts to import and use the exported mock - This fixes 'vi.mocked(...).mockResolvedValue is not a function' errors Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Use platform-libraries import for API v2 OrganizationRepository API v2 should import shared features through @calcom/platform-libraries instead of directly from @calcom/features to maintain proper architectural boundaries and packaging/licensing separation. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Implement DI pattern for OrganizationRepository - Create OrganizationRepository.module.ts and .container.ts for DI - Replace singleton pattern with getOrganizationRepository() across 20 files - Update platform-libraries to export getOrganizationRepository - Delete duplicate PrismaOrganizationRepository.ts - Remove singleton export file (repositories/index.ts) - Update test mocks to use DI container pattern - All type checks and unit tests passing Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Implement read/write client separation in OrganizationRepository - Updated OrganizationRepository constructor to accept optional prismaWriteClient parameter - Routed all write operations (create, update) through prismaWrite client - Routed all read operations (find, get) through prismaRead client - Updated API v2 OrganizationsRepository to pass both dbRead.prisma and dbWrite.prisma to super() - Optimized getOrganizationRepository() calls by storing in local variables to avoid repeated function calls - This fixes the critical issue where API v2 was passing read-only client to base class with write methods Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Fix mock setup and optimize getOrganizationRepository() calls - Fixed verify-email.test.ts mock to return mocked repository instance instead of scenario helper object - Added mockReset to organizationMock.ts beforeEach to properly reset mock implementations between tests - Added local variables in page.tsx to store getOrganizationRepository() result for consistency This fixes the issue where getOrganizationRepository() was returning organizationScenarios.organizationRepository (scenario helper) instead of the actual mocked repository instance, causing findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail to be undefined. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * refactor: Simplify OrganizationRepository to use single prismaClient - Updated base OrganizationRepository constructor to accept only { prismaClient } instead of { prismaClient, prismaWriteClient? } - Replaced this.prismaRead and this.prismaWrite with single this.prismaClient property - Updated API v2 OrganizationsRepository to pass only dbWrite.prisma as prismaClient - Removed unused PrismaReadService import from API v2 - All read and write operations now use the same client instance This simplifies the architecture as requested - API v2 uses write client for all operations, and apps/web uses the client from DI container. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix: Match OrganizationsRepository.findById signature with base class The findById method in OrganizationsRepository was using a different signature than the base OrganizationRepository class, causing type errors in CI. Changed from: findById(organizationId: number) Changed to: findById({ id }: { id: number }) This matches the base class signature and resolves the CI unit test failures. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Update all findById call sites to use object parameter Fixed 6 call sites in API v2 that were calling findById with a number instead of the required { id: number } object parameter: - is-org.guard.ts - is-admin-api-enabled.guard.ts - is-webhook-in-org.guard.ts - organizations.service.ts - managed-organizations.service.ts (2 call sites) This resolves the API v2 build failure caused by the signature change in OrganizationsRepository.findById to match the base class. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * fix: Remove redundant findById override from OrganizationsRepository The findById method was duplicating the base class OrganizationRepository implementation. Both methods had identical logic (filtering by isOrganization: true), so the override was unnecessary. Since OrganizationsRepository extends OrganizationRepository and passes dbWrite.prisma to the base constructor, the base class method already provides the exact same functionality. This resolves the API v2 build failure by eliminating the duplicate method that was causing conflicts. Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Remove unncessary changes * Store in variable * Revert "Remove unncessary changes" This reverts commit af9351786a21616c9508c441191c17f2374fb2cc. * Revert dbRead/dbWrite changes * Add organizations library to tsconfig.json --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
This commit is contained in:
50 files changed
+583
-159
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import { OrganizationsRepository } from "@/modules/organizations/index/organizations.repository";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
import { OrganizationMembershipService as BaseOrganizationMembershipService } from "@calcom/platform-libraries/organizations";
|
||||
|
||||
@Injectable()
|
||||
export class OrganizationMembershipService extends BaseOrganizationMembershipService {
|
||||
constructor(organizationsRepository: OrganizationsRepository) {
|
||||
super({ organizationRepository: organizationsRepository });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export class IsAdminAPIEnabledGuard implements CanActivate {
|
||||
}
|
||||
}
|
||||
|
||||
const org = await this.organizationsRepository.findById(Number(organizationId));
|
||||
const org = await this.organizationsRepository.findById({ id: Number(organizationId) });
|
||||
|
||||
if (org?.isOrganization && !org?.isPlatform) {
|
||||
const adminAPIAccessIsEnabledInOrg = await this.organizationsRepository.fetchOrgAdminApiStatus(
|
||||
|
||||
@@ -55,7 +55,7 @@ export class IsOrgGuard implements CanActivate {
|
||||
}
|
||||
}
|
||||
|
||||
const org = await this.organizationsRepository.findById(Number(organizationId));
|
||||
const org = await this.organizationsRepository.findById({ id: Number(organizationId) });
|
||||
|
||||
if (org?.isOrganization) {
|
||||
canAccess = true;
|
||||
|
||||
@@ -43,7 +43,7 @@ export class IsWebhookInOrg implements CanActivate {
|
||||
}
|
||||
}
|
||||
|
||||
const org = await this.organizationsRepository.findById(Number(organizationId));
|
||||
const org = await this.organizationsRepository.findById({ id: Number(organizationId) });
|
||||
|
||||
if (org?.isOrganization) {
|
||||
const isWebhookInOrg = await this.organizationsWebhooksRepository.findWebhook(
|
||||
|
||||
@@ -4,23 +4,17 @@ import { PrismaWriteService } from "@/modules/prisma/prisma-write.service";
|
||||
import { StripeService } from "@/modules/stripe/stripe.service";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
import { OrganizationRepository } from "@calcom/platform-libraries/organizations";
|
||||
import { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
@Injectable()
|
||||
export class OrganizationsRepository {
|
||||
export class OrganizationsRepository extends OrganizationRepository {
|
||||
constructor(
|
||||
private readonly dbRead: PrismaReadService,
|
||||
private readonly dbWrite: PrismaWriteService,
|
||||
private readonly stripeService: StripeService
|
||||
) {}
|
||||
|
||||
async findById(organizationId: number) {
|
||||
return this.dbRead.prisma.team.findUnique({
|
||||
where: {
|
||||
id: organizationId,
|
||||
isOrganization: true,
|
||||
},
|
||||
});
|
||||
) {
|
||||
super({ prismaClient: dbWrite.prisma });
|
||||
}
|
||||
|
||||
async findByIds(organizationIds: number[]) {
|
||||
|
||||
@@ -6,7 +6,7 @@ export class OrganizationsService {
|
||||
constructor(private readonly organizationsRepository: OrganizationsRepository) {}
|
||||
|
||||
async isPlatform(organizationId: number) {
|
||||
const organization = await this.organizationsRepository.findById(organizationId);
|
||||
const organization = await this.organizationsRepository.findById({ id: organizationId });
|
||||
return organization?.isPlatform;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { ZoomVideoService } from "@/modules/conferencing/services/zoom-video.ser
|
||||
import { CredentialsRepository } from "@/modules/credentials/credentials.repository";
|
||||
import { EmailModule } from "@/modules/email/email.module";
|
||||
import { EmailService } from "@/modules/email/email.service";
|
||||
import { OrganizationMembershipService } from "@/lib/services/organization-membership.service";
|
||||
import { MembershipsModule } from "@/modules/memberships/memberships.module";
|
||||
import { OAuthClientRepository } from "@/modules/oauth-clients/oauth-client.repository";
|
||||
import { UserOOORepository } from "@/modules/ooo/repositories/ooo.repository";
|
||||
@@ -108,6 +109,7 @@ import { Module } from "@nestjs/common";
|
||||
],
|
||||
providers: [
|
||||
OrganizationsRepository,
|
||||
OrganizationMembershipService,
|
||||
OrganizationsTeamsRepository,
|
||||
OrganizationsService,
|
||||
OrganizationsTeamsService,
|
||||
@@ -200,4 +202,4 @@ import { Module } from "@nestjs/common";
|
||||
OrganizationsEventTypesPrivateLinksController,
|
||||
],
|
||||
})
|
||||
export class OrganizationsModule {}
|
||||
export class OrganizationsModule { }
|
||||
+2
-2
@@ -103,12 +103,12 @@ export class ManagedOrganizationsService {
|
||||
}
|
||||
|
||||
private async isManagerOrganizationPlatform(managerOrganizationId: number) {
|
||||
const organization = await this.organizationsRepository.findById(managerOrganizationId);
|
||||
const organization = await this.organizationsRepository.findById({ id: managerOrganizationId });
|
||||
return !!organization?.isPlatform;
|
||||
}
|
||||
|
||||
async getManagedOrganization(managedOrganizationId: number) {
|
||||
const organization = await this.organizationsRepository.findById(managedOrganizationId);
|
||||
const organization = await this.organizationsRepository.findById({ id: managedOrganizationId });
|
||||
if (!organization) {
|
||||
throw new NotFoundException(`Managed organization with id=${managedOrganizationId} does not exist.`);
|
||||
}
|
||||
|
||||
+203
@@ -418,6 +418,209 @@ describe("Organizations Teams Memberships Endpoints", () => {
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
// Auto-accept tests
|
||||
describe("auto-accept based on email domain", () => {
|
||||
let orgWithAutoAccept: Team;
|
||||
let subteamWithAutoAccept: Team;
|
||||
let userWithMatchingEmail: User;
|
||||
let userWithUppercaseEmail: User;
|
||||
let userWithMatchingEmailForOverride: User;
|
||||
let userWithNonMatchingEmail: User;
|
||||
|
||||
beforeAll(async () => {
|
||||
// Create org with auto-accept settings
|
||||
orgWithAutoAccept = await organizationsRepositoryFixture.create({
|
||||
name: `auto-accept-org-${randomString()}`,
|
||||
isOrganization: true,
|
||||
});
|
||||
|
||||
// Update organizationSettings with orgAutoAcceptEmail
|
||||
await organizationsRepositoryFixture.updateSettings(orgWithAutoAccept.id, {
|
||||
orgAutoAcceptEmail: "acme.com",
|
||||
isOrganizationVerified: true,
|
||||
isOrganizationConfigured: true,
|
||||
});
|
||||
|
||||
// Create subteam
|
||||
subteamWithAutoAccept = await teamsRepositoryFixture.create({
|
||||
name: `auto-accept-subteam-${randomString()}`,
|
||||
isOrganization: false,
|
||||
parent: { connect: { id: orgWithAutoAccept.id } },
|
||||
});
|
||||
|
||||
// Create event type with assignAllTeamMembers
|
||||
await eventTypesRepositoryFixture.createTeamEventType({
|
||||
schedulingType: "COLLECTIVE",
|
||||
team: { connect: { id: subteamWithAutoAccept.id } },
|
||||
title: "Auto Accept Event Type",
|
||||
slug: "auto-accept-event-type",
|
||||
length: 30,
|
||||
assignAllTeamMembers: true,
|
||||
bookingFields: [],
|
||||
locations: [],
|
||||
});
|
||||
|
||||
// Create users
|
||||
userWithMatchingEmail = await userRepositoryFixture.create({
|
||||
email: `alice@acme.com`,
|
||||
username: `alice-${randomString()}`,
|
||||
});
|
||||
|
||||
userWithUppercaseEmail = await userRepositoryFixture.create({
|
||||
email: `bob@ACME.COM`,
|
||||
username: `bob-${randomString()}`,
|
||||
});
|
||||
|
||||
userWithMatchingEmailForOverride = await userRepositoryFixture.create({
|
||||
email: `david@acme.com`,
|
||||
username: `david-${randomString()}`,
|
||||
});
|
||||
|
||||
userWithNonMatchingEmail = await userRepositoryFixture.create({
|
||||
email: `charlie@external.com`,
|
||||
username: `charlie-${randomString()}`,
|
||||
});
|
||||
|
||||
// Add users to org
|
||||
await membershipsRepositoryFixture.create({
|
||||
role: "MEMBER",
|
||||
accepted: true,
|
||||
user: { connect: { id: userWithMatchingEmail.id } },
|
||||
team: { connect: { id: orgWithAutoAccept.id } },
|
||||
});
|
||||
|
||||
await membershipsRepositoryFixture.create({
|
||||
role: "MEMBER",
|
||||
accepted: true,
|
||||
user: { connect: { id: userWithUppercaseEmail.id } },
|
||||
team: { connect: { id: orgWithAutoAccept.id } },
|
||||
});
|
||||
|
||||
await membershipsRepositoryFixture.create({
|
||||
role: "MEMBER",
|
||||
accepted: true,
|
||||
user: { connect: { id: userWithMatchingEmailForOverride.id } },
|
||||
team: { connect: { id: orgWithAutoAccept.id } },
|
||||
});
|
||||
|
||||
await membershipsRepositoryFixture.create({
|
||||
role: "MEMBER",
|
||||
accepted: true,
|
||||
user: { connect: { id: userWithNonMatchingEmail.id } },
|
||||
team: { connect: { id: orgWithAutoAccept.id } },
|
||||
});
|
||||
|
||||
// Create profiles for users
|
||||
await profileRepositoryFixture.create({
|
||||
uid: `usr-${userWithMatchingEmail.id}`,
|
||||
username: userWithMatchingEmail.username || `user-${userWithMatchingEmail.id}`,
|
||||
organization: { connect: { id: orgWithAutoAccept.id } },
|
||||
user: { connect: { id: userWithMatchingEmail.id } },
|
||||
});
|
||||
|
||||
await profileRepositoryFixture.create({
|
||||
uid: `usr-${userWithUppercaseEmail.id}`,
|
||||
username: userWithUppercaseEmail.username || `user-${userWithUppercaseEmail.id}`,
|
||||
organization: { connect: { id: orgWithAutoAccept.id } },
|
||||
user: { connect: { id: userWithUppercaseEmail.id } },
|
||||
});
|
||||
|
||||
await profileRepositoryFixture.create({
|
||||
uid: `usr-${userWithMatchingEmailForOverride.id}`,
|
||||
username: userWithMatchingEmailForOverride.username || `user-${userWithMatchingEmailForOverride.id}`,
|
||||
organization: { connect: { id: orgWithAutoAccept.id } },
|
||||
user: { connect: { id: userWithMatchingEmailForOverride.id } },
|
||||
});
|
||||
|
||||
await profileRepositoryFixture.create({
|
||||
uid: `usr-${userWithNonMatchingEmail.id}`,
|
||||
username: userWithNonMatchingEmail.username || `user-${userWithNonMatchingEmail.id}`,
|
||||
organization: { connect: { id: orgWithAutoAccept.id } },
|
||||
user: { connect: { id: userWithNonMatchingEmail.id } },
|
||||
});
|
||||
|
||||
// Make user an admin of the org for API access
|
||||
await membershipsRepositoryFixture.create({
|
||||
role: "ADMIN",
|
||||
accepted: true,
|
||||
user: { connect: { id: user.id } },
|
||||
team: { connect: { id: orgWithAutoAccept.id } },
|
||||
});
|
||||
});
|
||||
|
||||
it("should auto-accept when email matches orgAutoAcceptEmail", async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post(`/v2/organizations/${orgWithAutoAccept.id}/teams/${subteamWithAutoAccept.id}/memberships`)
|
||||
.send({
|
||||
userId: userWithMatchingEmail.id,
|
||||
role: "MEMBER",
|
||||
} satisfies CreateOrgTeamMembershipDto)
|
||||
.expect(201);
|
||||
|
||||
const responseBody: ApiSuccessResponse<TeamMembershipOutput> = response.body;
|
||||
expect(responseBody.data.accepted).toBe(true);
|
||||
|
||||
// Verify EventTypes assignment
|
||||
const eventTypes = await eventTypesRepositoryFixture.getAllTeamEventTypes(
|
||||
subteamWithAutoAccept.id
|
||||
);
|
||||
const eventTypeWithAssignAll = eventTypes.find((et) => et.assignAllTeamMembers);
|
||||
expect(eventTypeWithAssignAll).toBeTruthy();
|
||||
const userIsHost = eventTypeWithAssignAll?.hosts.some((h) => h.userId === userWithMatchingEmail.id);
|
||||
expect(userIsHost).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle case-insensitive email domain matching", async () => {
|
||||
// User with email="bob@ACME.COM" should match orgAutoAcceptEmail="acme.com"
|
||||
const response = await request(app.getHttpServer())
|
||||
.post(`/v2/organizations/${orgWithAutoAccept.id}/teams/${subteamWithAutoAccept.id}/memberships`)
|
||||
.send({
|
||||
userId: userWithUppercaseEmail.id,
|
||||
role: "MEMBER",
|
||||
} satisfies CreateOrgTeamMembershipDto)
|
||||
.expect(201);
|
||||
|
||||
const responseBody: ApiSuccessResponse<TeamMembershipOutput> = response.body;
|
||||
expect(responseBody.data.accepted).toBe(true);
|
||||
});
|
||||
|
||||
it("should ALWAYS auto-accept when email matches, even if accepted:false", async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post(`/v2/organizations/${orgWithAutoAccept.id}/teams/${subteamWithAutoAccept.id}/memberships`)
|
||||
.send({
|
||||
userId: userWithMatchingEmailForOverride.id,
|
||||
role: "MEMBER",
|
||||
accepted: false,
|
||||
} satisfies CreateOrgTeamMembershipDto)
|
||||
.expect(201);
|
||||
|
||||
const responseBody: ApiSuccessResponse<TeamMembershipOutput> = response.body;
|
||||
// Should override to true because email matches
|
||||
expect(responseBody.data.accepted).toBe(true);
|
||||
});
|
||||
|
||||
it("should NOT auto-accept when email does not match orgAutoAcceptEmail", async () => {
|
||||
const response = await request(app.getHttpServer())
|
||||
.post(`/v2/organizations/${orgWithAutoAccept.id}/teams/${subteamWithAutoAccept.id}/memberships`)
|
||||
.send({
|
||||
userId: userWithNonMatchingEmail.id,
|
||||
role: "MEMBER",
|
||||
} satisfies CreateOrgTeamMembershipDto)
|
||||
.expect(201);
|
||||
|
||||
const responseBody: ApiSuccessResponse<TeamMembershipOutput> = response.body;
|
||||
expect(responseBody.data.accepted).toBe(false);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await userRepositoryFixture.deleteByEmail(userWithMatchingEmail.email);
|
||||
await userRepositoryFixture.deleteByEmail(userWithUppercaseEmail.email);
|
||||
await userRepositoryFixture.deleteByEmail(userWithMatchingEmailForOverride.email);
|
||||
await userRepositoryFixture.deleteByEmail(userWithNonMatchingEmail.email);
|
||||
await organizationsRepositoryFixture.delete(orgWithAutoAccept.id);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await userRepositoryFixture.deleteByEmail(user.email);
|
||||
await userRepositoryFixture.deleteByEmail(userToInviteViaApi.email);
|
||||
|
||||
+22
-3
@@ -12,6 +12,7 @@ import { IsAdminAPIEnabledGuard } from "@/modules/auth/guards/organizations/is-a
|
||||
import { IsOrgGuard } from "@/modules/auth/guards/organizations/is-org.guard";
|
||||
import { RolesGuard } from "@/modules/auth/guards/roles/roles.guard";
|
||||
import { IsTeamInOrg } from "@/modules/auth/guards/teams/is-team-in-org.guard";
|
||||
import { OrganizationMembershipService } from "@/lib/services/organization-membership.service";
|
||||
import { OrganizationsRepository } from "@/modules/organizations/index/organizations.repository";
|
||||
import { CreateOrgTeamMembershipDto } from "@/modules/organizations/teams/memberships/inputs/create-organization-team-membership.input";
|
||||
import { UpdateOrgTeamMembershipDto } from "@/modules/organizations/teams/memberships/inputs/update-organization-team-membership.input";
|
||||
@@ -58,8 +59,9 @@ export class OrganizationsTeamsMembershipsController {
|
||||
|
||||
constructor(
|
||||
private organizationsTeamsMembershipsService: OrganizationsTeamsMembershipsService,
|
||||
private readonly organizationsRepository: OrganizationsRepository
|
||||
) {}
|
||||
private readonly organizationsRepository: OrganizationsRepository,
|
||||
private readonly orgMembershipService: OrganizationMembershipService
|
||||
) { }
|
||||
|
||||
@Get("/")
|
||||
@ApiOperation({ summary: "Get all memberships" })
|
||||
@@ -168,6 +170,9 @@ export class OrganizationsTeamsMembershipsController {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// TODO: Refactor to use inviteMembersWithNoInviterPermissionCheck when it is moved to a Service
|
||||
// See: packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.ts
|
||||
@Roles("TEAM_ADMIN")
|
||||
@PlatformPlan("ESSENTIALS")
|
||||
@Post("/")
|
||||
@@ -184,7 +189,21 @@ export class OrganizationsTeamsMembershipsController {
|
||||
throw new UnprocessableEntityException("User is not part of the Organization");
|
||||
}
|
||||
|
||||
const membership = await this.organizationsTeamsMembershipsService.createOrgTeamMembership(teamId, data);
|
||||
const shouldAutoAccept = await this.orgMembershipService.shouldAutoAccept({
|
||||
organizationId: orgId,
|
||||
userEmail: user.email,
|
||||
});
|
||||
|
||||
// ALWAYS override when email matches - prevents pending memberships
|
||||
// Remember organizations expect added team member to automatically start receiving bookings for the team event
|
||||
const acceptedStatus = shouldAutoAccept ? true : (data.accepted ?? false);
|
||||
|
||||
const membershipData = { ...data, accepted: acceptedStatus };
|
||||
const membership = await this.organizationsTeamsMembershipsService.createOrgTeamMembership(
|
||||
teamId,
|
||||
membershipData
|
||||
);
|
||||
|
||||
if (membership.accepted) {
|
||||
try {
|
||||
await updateNewTeamMemberEventTypes(user.id, teamId);
|
||||
|
||||
@@ -37,6 +37,20 @@ export class OrganizationRepositoryFixture {
|
||||
});
|
||||
}
|
||||
|
||||
async updateSettings(
|
||||
teamId: Team["id"],
|
||||
settings: {
|
||||
orgAutoAcceptEmail?: string;
|
||||
isOrganizationVerified?: boolean;
|
||||
isOrganizationConfigured?: boolean;
|
||||
}
|
||||
) {
|
||||
return this.prismaWriteClient.organizationSettings.update({
|
||||
where: { organizationId: teamId },
|
||||
data: settings,
|
||||
});
|
||||
}
|
||||
|
||||
async delete(teamId: Team["id"]) {
|
||||
return await this.prismaWriteClient.$transaction(async (prisma) => {
|
||||
await prisma.organizationSettings.delete({
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
"@calcom/platform-libraries/conferencing": ["../../../packages/platform/libraries/conferencing.ts"],
|
||||
"@calcom/platform-libraries/repositories": ["../../../packages/platform/libraries/repositories.ts"],
|
||||
"@calcom/platform-libraries/bookings": ["../../../packages/platform/libraries/bookings.ts"],
|
||||
"@calcom/platform-libraries/private-links": ["../../../packages/platform/libraries/private-links.ts"]
|
||||
"@calcom/platform-libraries/private-links": ["../../../packages/platform/libraries/private-links.ts"],
|
||||
"@calcom/platform-libraries/organizations": ["../../../packages/platform/libraries/organizations.ts"]
|
||||
},
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
Reference in new issue
Block a user