Skip to content

Scheduling infrastructure for absolutely everyone.

fix: scope managed user to client id (#14347)

Morgane3562cdfb5ac
diff --git a/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts b/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts
index 0241ea7ada7..dd30c01b3ab 100644
--- a/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts
+++ b/apps/api/v2/src/modules/oauth-clients/services/oauth-clients-users.service.ts
@@ -2,7 +2,7 @@ import { EventTypesService } from "@/ee/event-types/services/event-types.service
import { TokensRepository } from "@/modules/tokens/tokens.repository";
import { CreateManagedPlatformUserInput } from "@/modules/users/inputs/create-managed-platform-user.input";
import { UsersRepository } from "@/modules/users/users.repository";
-import { Injectable } from "@nestjs/common";
+import { BadRequestException, Injectable } from "@nestjs/common";
import { User } from "@prisma/client";
import * as crypto from "crypto";
@@ -24,23 +24,24 @@ export class OAuthClientUsersService {
) {
let user: User;
if (!organizationId) {
- const username = generateShortHash(body.email, oAuthClientId);
- user = await this.userRepository.create(body, username, oAuthClientId, isPlatformManaged);
+ throw new BadRequestException("You cannot create a managed user outside of an organization");
} else {
+ const [username, emailDomain] = body.email.split("@");
+ const email = `${username}+${oAuthClientId}@${emailDomain}`;
user = (
await createNewUsersConnectToOrgIfExists({
- usernamesOrEmails: [body.email],
+ usernamesOrEmails: [email],
input: {
teamId: organizationId,
role: "MEMBER",
- usernameOrEmail: [body.email],
+ usernameOrEmail: [email],
isOrg: true,
language: "en",
},
parentId: null,
autoAcceptEmailDomain: "never-auto-accept-email-domain-for-managed-users",
connectionInfoMap: {
- [body.email]: {
+ [email]: {
orgId: organizationId,
autoAccept: true,
},