feat: Toggle auto adding users to an org if they signup without an invite (#25051)
* Remove auto adding users to an org * Update tests * Fix tests * fix: Update organization invitation E2E tests to not expect auto-accept before signup - Changed isMemberShipAccepted expectations from true to false before signup - Users with emails matching orgAutoAcceptEmail are no longer auto-accepted - They must explicitly accept the invitation after signup - Fixed lint warnings for unused parameters Co-Authored-By: [email protected] <[email protected]> * fix: Update E2E tests to expect pending membership after signup without auto-accept Since auto-accept functionality was removed, users with emails matching orgAutoAcceptEmail are no longer automatically accepted into organizations after signup. They remain in pending state until explicitly accepted. Updated assertions in: - 'nonexisting user is invited to Org' test - 'nonexisting user is invited to a team inside organization' test Both tests now correctly expect isMemberShipAccepted: false after signup. Co-Authored-By: [email protected] <[email protected]> * Restore `verify-email` and tests from `main` * Add `orgAutoJoinOnSignup` to `organizationSettings` * Update `OrganizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail` to find orgs where `orgAutoJoinOnSignup` is true * `organization.update` lint fix * `organization.update` to handle `orgAutoJoinOnSignup` * Create toggle for `orgAutoJoinOnSignup` * test: Add comprehensive tests for orgAutoJoinOnSignup functionality - Update existing test to expect null instead of error when multiple orgs match - Add test for when orgAutoJoinOnSignup is false (should return null) - Add test for when orgAutoJoinOnSignup is true (should return org) - Add test for default behavior (orgAutoJoinOnSignup defaults to true) These tests verify that the new orgAutoJoinOnSignup setting correctly controls whether users are automatically added to organizations during email verification. Co-Authored-By: [email protected] <[email protected]> * Type fix * e2e: invited users should be accepted after signup (address cubic r2511916791) Reverted post-signup isMemberShipAccepted assertions from false to true for explicit invite scenarios. When users are explicitly invited to an org/team and complete signup via invite link, their membership should be accepted. This is distinct from auto-join by domain (controlled by orgAutoJoinOnSignup), which only affects users who sign up without an invite but match the org's email domain. Backend sets membership.accepted = true on invite completion in: packages/features/auth/signup/utils/createOrUpdateMemberships.ts:61,67,77,83 Co-Authored-By: [email protected] <[email protected]> * Fix API V2 build --------- Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
12 files changed
+154
-37
No files matched your search
@@ -0,0 +1,51 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import { SettingsToggle } from "@calcom/ui/components/form";
|
||||
import { showToast } from "@calcom/ui/components/toast";
|
||||
|
||||
interface IOrgAutoJoinSettingProps {
|
||||
orgId: number;
|
||||
orgAutoJoinEnabled: boolean;
|
||||
emailDomain: string;
|
||||
}
|
||||
|
||||
const OrgAutoJoinSetting = (props: IOrgAutoJoinSettingProps) => {
|
||||
const utils = trpc.useUtils();
|
||||
const [isEnabled, setIsEnabled] = useState(props.orgAutoJoinEnabled);
|
||||
const { t } = useLocale();
|
||||
|
||||
const mutation = trpc.viewer.organizations.update.useMutation({
|
||||
onSuccess: async () => {
|
||||
showToast(t("your_org_updated_successfully"), "success");
|
||||
},
|
||||
onError: () => {
|
||||
showToast(t("error_updating_settings"), "error");
|
||||
},
|
||||
onSettled: () => {
|
||||
utils.viewer.organizations.listCurrent.invalidate();
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<SettingsToggle
|
||||
toggleSwitchAtTheEnd={true}
|
||||
checked={isEnabled}
|
||||
title={t("org_auto_join_title", { emailDomain: props.emailDomain })}
|
||||
labelClassName="text-sm"
|
||||
description={t("org_auto_join_description")}
|
||||
data-testid="make-team-private-check"
|
||||
onCheckedChange={(checked) => {
|
||||
mutation.mutate({
|
||||
orgAutoJoinOnSignup: checked,
|
||||
});
|
||||
setIsEnabled(checked);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrgAutoJoinSetting;
|
||||
@@ -11,6 +11,8 @@ import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
import { BlocklistTable } from "~/settings/organizations/privacy/blocklist-table";
|
||||
|
||||
import OrgAutoJoinSetting from "../components/OrgAutoJoinSetting";
|
||||
|
||||
const PrivacyView = ({
|
||||
permissions,
|
||||
watchlistPermissions,
|
||||
@@ -42,6 +44,14 @@ const PrivacyView = ({
|
||||
disabled={isDisabled}
|
||||
/>
|
||||
|
||||
{currentOrg.organizationSettings?.orgAutoAcceptEmail && (
|
||||
<OrgAutoJoinSetting
|
||||
orgId={currentOrg.id}
|
||||
orgAutoJoinEnabled={!!currentOrg.organizationSettings.orgAutoJoinOnSignup}
|
||||
emailDomain={currentOrg.organizationSettings.orgAutoAcceptEmail}
|
||||
/>
|
||||
)}
|
||||
|
||||
{watchlistPermissions?.canRead && (
|
||||
<div>
|
||||
<div>
|
||||
|
||||
@@ -81,13 +81,15 @@ describe("Organization.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail", () =
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should throw an error if multiple organizations match the email domain", async () => {
|
||||
it("should return null if multiple organizations match the email domain", async () => {
|
||||
await createReviewedOrganization({ name: "Test Org 1", orgAutoAcceptEmail: "example.com" });
|
||||
await createReviewedOrganization({ name: "Test Org 2", orgAutoAcceptEmail: "example.com" });
|
||||
|
||||
await expect(
|
||||
organizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({ email: "[email protected]" })
|
||||
).rejects.toThrow("Multiple organizations found with the same auto accept email domain");
|
||||
const result = await organizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
||||
email: "[email protected]",
|
||||
});
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should return the parsed organization if a single match is found", async () => {
|
||||
@@ -122,6 +124,65 @@ describe("Organization.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail", () =
|
||||
|
||||
expect(result).toEqual(null);
|
||||
});
|
||||
|
||||
it("should return null when orgAutoJoinOnSignup is false", async () => {
|
||||
await prismock.team.create({
|
||||
data: {
|
||||
name: "Test Org",
|
||||
isOrganization: true,
|
||||
organizationSettings: {
|
||||
create: {
|
||||
orgAutoAcceptEmail: "example.com",
|
||||
isOrganizationVerified: true,
|
||||
isAdminReviewed: true,
|
||||
orgAutoJoinOnSignup: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await organizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
||||
email: "[email protected]",
|
||||
});
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should return organization when orgAutoJoinOnSignup is true", async () => {
|
||||
const organization = await prismock.team.create({
|
||||
data: {
|
||||
name: "Test Org",
|
||||
isOrganization: true,
|
||||
organizationSettings: {
|
||||
create: {
|
||||
orgAutoAcceptEmail: "example.com",
|
||||
isOrganizationVerified: true,
|
||||
isAdminReviewed: true,
|
||||
orgAutoJoinOnSignup: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = await organizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
||||
email: "[email protected]",
|
||||
});
|
||||
|
||||
expect(result).toEqual(organization);
|
||||
});
|
||||
|
||||
it("should return organization when orgAutoJoinOnSignup is not explicitly set (defaults to true)", async () => {
|
||||
const organization = await createReviewedOrganization({
|
||||
name: "Test Org",
|
||||
orgAutoAcceptEmail: "example.com",
|
||||
});
|
||||
|
||||
const result = await organizationRepository.findUniqueNonPlatformOrgsByMatchingAutoAcceptEmail({
|
||||
email: "[email protected]",
|
||||
});
|
||||
|
||||
expect(result).toEqual(organization);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Organization.getVerifiedOrganizationByAutoAcceptEmailDomain", () => {
|
||||
|
||||
@@ -242,16 +242,18 @@ export class OrganizationRepository {
|
||||
orgAutoAcceptEmail: emailDomain,
|
||||
isOrganizationVerified: true,
|
||||
isAdminReviewed: true,
|
||||
orgAutoJoinOnSignup: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (orgs.length > 1) {
|
||||
logger.error(
|
||||
"Multiple organizations found with the same auto accept email domain",
|
||||
safeStringify({ orgs, emailDomain })
|
||||
safeStringify({ orgIds: orgs.map((org) => org.id), emailDomain })
|
||||
);
|
||||
// Detect and fail just in case this situation arises. We should really identify the problem in this case and fix the data.
|
||||
throw new Error("Multiple organizations found with the same auto accept email domain");
|
||||
|
||||
// If we cannot reliably confirm a unique org then return nothing
|
||||
return null;
|
||||
}
|
||||
const org = orgs[0];
|
||||
if (!org) {
|
||||
@@ -285,6 +287,7 @@ export class OrganizationRepository {
|
||||
orgProfileRedirectsToVerifiedDomain: true,
|
||||
orgAutoAcceptEmail: true,
|
||||
disablePhoneOnlySMSNotifications: true,
|
||||
orgAutoJoinOnSignup: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -303,6 +306,7 @@ export class OrganizationRepository {
|
||||
orgProfileRedirectsToVerifiedDomain: organizationSettings?.orgProfileRedirectsToVerifiedDomain,
|
||||
orgAutoAcceptEmail: organizationSettings?.orgAutoAcceptEmail,
|
||||
disablePhoneOnlySMSNotifications: organizationSettings?.disablePhoneOnlySMSNotifications,
|
||||
orgAutoJoinOnSignup: organizationSettings?.orgAutoJoinOnSignup,
|
||||
},
|
||||
user: {
|
||||
role: membership?.role,
|
||||
|
||||
Reference in new issue
Block a user