feat: from org team invite (#9569)

* Initial commit

* Adding feature flag

* Desktop first banner, mobile pending

* Removing dead code and img

* AppInstallButtonBase

* WIP

* Adds Email verification template+translations for organizations (#9202)

* feat: Orgs Schema Changing `scopedMembers` to `orgUsers` (#9209)

* Change scopedMembers to orgMembers

* Change to orgUsers

* First step done

* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding

* Session logic to show org label

* Step 2 done, avatar not working

* List orgs and list teams specific if orgs exist

* Conditionally show org - fix settings layout - add labels for all pages

* Profile Page + update

* Org specific team creation

* appearance page

* Ensure members cant of org cant update settings in UI

* Fix update handler imports

* hide billing on sub teams

* Update profile slug page

* Letting duplicate slugs for teams to support orgs

* Add slug coliisions for org

* Covering null on unique clauses

* Covering null on unique clauses

* Extract to utils

* Update settings to use subdomain path in team url , team + org

* Supporting having the orgId in the session cookie

* Onboarding admins step

* Last step to create teams

* Update handler comments

* Upgrade ORG banner - disabled team banner for child teams

* Handle publishing ORGS

* Fix licenese issue

* Update packages/trpc/server/routers/viewer/teams/create.handler.ts

* Split into function calls to make this file more explisit

* Update parents stripe sub not teamID

* Moving change password handler, improving verifying code flow

* Clearing error before submitting

* Reverting email testing api changes

* Reverting having the banner for now

* Consistent exported components

* Remove unneeded files from banner

* Removing uneeded code

* Fixing avatar selector

* Using meta component for head/descr

* Missing i18n strings

* Create org membership also - billing portal page

* A11ly

* Hide create team if no valid permisisons

* Get Org members router

* Handle updating subscription if orgId

* Fix double upgrade banner

* Update constants

* Feedback

* Copy change

* Making an org avatar (temp)

* Add slug colission detection for user and team name

* Fix Import

* Remove update password func

* Fix module import over relative

* feat: organization event type filter (#9253)

Signed-off-by: Udit Takkar <[email protected]>

* Missing changes to support orgs schema changes

* Fix import again

* Throw no team found before auth error

* Check if invited found user is already in differnt org

* feat: organization settings general page

Signed-off-by: Udit Takkar <[email protected]>

* feat: add members page

Signed-off-by: Udit Takkar <[email protected]>

* chore: remove

Signed-off-by: Udit Takkar <[email protected]>

* fix: use invalidate

Signed-off-by: Udit Takkar <[email protected]>

* Move to for of loop to throw errors in usenamelist

* fix: delete mutation

Signed-off-by: Udit Takkar <[email protected]>

* fix: remove organization id

Signed-off-by: Udit Takkar <[email protected]>

* chore

Signed-off-by: Udit Takkar <[email protected]>

* Remove app install button sa its in 9337

* Remove i18n key not being used

* feat: Onboarding process to create an organization (#9184)

* Desktop first banner, mobile pending

* Removing dead code and img

* WIP

* Adds Email verification template+translations for organizations (#9202)

* First step done

* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding

* Step 2 done, avatar not working

* Covering null on unique clauses

* Onboarding admins step

* Last step to create teams

* Moving change password handler, improving verifying code flow

* Clearing error before submitting

* Reverting email testing api changes

* Reverting having the banner for now

* Consistent exported components

* Remove unneeded files from banner

* Removing uneeded code

* Fixing avatar selector

* Using meta component for head/descr

* Missing i18n strings

* Feedback

* Making an org avatar (temp)

* Check for subteams slug clashes with usernames

* Fixing create teams onsuccess

* feedback

* Making sure we check requestedSlug now

---------

Co-authored-by: sean-brydon <[email protected]>

* feat: [CAL-1816] Organization subdomain support (#9345)

* Desktop first banner, mobile pending

* Removing dead code and img

* WIP

* Adds Email verification template+translations for organizations (#9202)

* First step done

* Merge branch 'feat/organizations-onboarding' of github.com:calcom/cal.com into feat/organizations-onboarding

* Step 2 done, avatar not working

* Covering null on unique clauses

* Onboarding admins step

* Last step to create teams

* Moving change password handler, improving verifying code flow

* Clearing error before submitting

* Reverting email testing api changes

* Reverting having the banner for now

* Consistent exported components

* Remove unneeded files from banner

* Removing uneeded code

* Fixing avatar selector

* Using meta component for head/descr

* Missing i18n strings

* Feedback

* Making an org avatar (temp)

* Check for subteams slug clashes with usernames

* Fixing create teams onsuccess

* Covering users and subteams, excluding non-org users

* Unpublished teams shows correctly

* Create subdomain in Vercel

* feedback

* Renaming Vercel env vars

* Vercel domain check before creation

* Supporting cal-staging.com

* Change to have vercel detect it

* vercel domain check data message error

* Remove check domain

* Making sure we check requestedSlug now

* Feedback and unneeded code

* Reverting unneeded changes

* Unneeded changes

---------

Co-authored-by: sean-brydon <[email protected]>

* Vercel subdomain creation in PROD only

* Fix router

* fix: use zod schema

Signed-off-by: Udit Takkar <[email protected]>

* feat: organization settings general and members page (#9266)

* feat: organization settings general page

Signed-off-by: Udit Takkar <[email protected]>

* feat: add members page

Signed-off-by: Udit Takkar <[email protected]>

* chore: remove

Signed-off-by: Udit Takkar <[email protected]>

* fix: use invalidate

Signed-off-by: Udit Takkar <[email protected]>

* fix: delete mutation

Signed-off-by: Udit Takkar <[email protected]>

* fix: remove organization id

Signed-off-by: Udit Takkar <[email protected]>

* chore

Signed-off-by: Udit Takkar <[email protected]>

* fix: use zod schema

Signed-off-by: Udit Takkar <[email protected]>

---------

Signed-off-by: Udit Takkar <[email protected]>

* Type fixes

* Use org Stripe product when upgrading

* Removed unused code

* UI completed

* Reverting changes

* Update UsernameTextfield.tsx

* More reverts

* Update next-auth-options.ts

* Update common.json

* Type fixes

* Include invite token for orgs

* Update org schema

* Make token settings optional as it isnt used in orgs yet

* Reverts

* Add correct array logic and move to controlled component

* Fix toggle group default | Update toggle group bg

* Darkmode toggle group

* Distinct user

* Hide modal if no org members

* Extract toggle logic

* Update packages/features/ee/organizations/components/TeamInviteFromOrg.tsx

* remove yarn.lock from commit

* Fix types

* Add getMember router back

* As a query lol

* Fix types

* Fix accepted param defaulting to true as we want both

* Fix list not pulling back people who have not joined the org yet

* Fix tests to handle invite a existing org user to a team

* Fix test

* Fix an error sometimes when existing org user is invited

* Updates radix & fixes bug

---------

Signed-off-by: Udit Takkar <[email protected]>
Co-authored-by: Leo Giovanetti <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Shivam Kalra <[email protected]>
This commit is contained in:
14 files changed
+458 -707

No files matched your search

@@ -19,9 +19,9 @@ type OrganizationsRouterHandlerCache = {
setPassword?: typeof import("./setPassword.handler").setPasswordHandler;
adminGetUnverified?: typeof import("./adminGetUnverified.handler").adminGetUnverifiedHandler;
adminVerify?: typeof import("./adminVerify.handler").adminVerifyHandler;
getMembers?: typeof import("./getMembers.handler").getMembersHandler;
listMembers?: typeof import("./listMembers.handler").listMembersHandler;
getBrand?: typeof import("./getBrand.handler").getBrandHandler;
getMembers?: typeof import("./getMembers.handler").getMembersHandler;
};
const UNSTABLE_HANDLER_CACHE: OrganizationsRouterHandlerCache = {};
@@ -146,6 +146,23 @@ export const viewerOrganizationsRouter = router({
input,
});
}),
getMembers: authedProcedure.input(ZGetMembersInput).query(async ({ ctx, input }) => {
if (!UNSTABLE_HANDLER_CACHE.getMembers) {
UNSTABLE_HANDLER_CACHE.getMembers = await import("./getMembers.handler").then(
(mod) => mod.getMembersHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.getMembers) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.getMembers({
ctx,
input,
});
}),
adminGetUnverified: authedAdminProcedure.query(async ({ ctx }) => {
if (!UNSTABLE_HANDLER_CACHE.adminGetUnverified) {
UNSTABLE_HANDLER_CACHE.adminGetUnverified = await import("./adminGetUnverified.handler").then(
@@ -207,21 +224,4 @@ export const viewerOrganizationsRouter = router({
ctx,
});
}),
getMembers: authedProcedure.input(ZGetMembersInput).query(async ({ ctx, input }) => {
if (!UNSTABLE_HANDLER_CACHE.getMembers) {
UNSTABLE_HANDLER_CACHE.getMembers = await import("./getMembers.handler").then(
(mod) => mod.getMembersHandler
);
}
// Unreachable code but required for type safety
if (!UNSTABLE_HANDLER_CACHE.getMembers) {
throw new Error("Failed to load handler");
}
return UNSTABLE_HANDLER_CACHE.getMembers({
ctx,
input,
});
}),
});
@@ -11,32 +11,44 @@ type CreateOptions = {
};
export const getMembersHandler = async ({ input, ctx }: CreateOptions) => {
const { teamIdToExclude } = input;
const { teamIdToExclude, accepted, distinctUser } = input;
if (!ctx.user.organizationId) return null;
if (!ctx.user.organizationId) return [];
const users = await prisma.membership.findMany({
const teamQuery = await prisma.team.findUnique({
where: {
user: {
organizationId: ctx.user.organizationId,
},
...(teamIdToExclude && {
teamId: {
not: teamIdToExclude,
},
}),
id: ctx.user.organizationId,
},
include: {
user: {
select: {
id: true,
username: true,
email: true,
completedOnboarding: true,
select: {
members: {
where: {
teamId: {
not: teamIdToExclude,
},
accepted,
},
select: {
accepted: true,
disableImpersonation: true,
id: true,
teamId: true,
role: true,
userId: true,
user: {
select: {
id: true,
username: true,
email: true,
completedOnboarding: true,
name: true,
},
},
},
...(distinctUser && {
distinct: ["userId"],
}),
},
},
});
return users;
return teamQuery?.members || [];
};
@@ -2,6 +2,8 @@ import { z } from "zod";
export const ZGetMembersInput = z.object({
teamIdToExclude: z.number().optional(),
accepted: z.boolean().optional(),
distinctUser: z.boolean().optional().default(false),
});
export type TGetMembersInputSchema = z.infer<typeof ZGetMembersInput>;
@@ -40,7 +40,8 @@ const mockedTeam: TeamWithParent = {
timeFormat: null,
metadata: null,
parentId: null,
parent: null
parent: null,
isPrivate:false
};
const mockUser: User = {
@@ -263,7 +264,8 @@ describe("Invite Member Utils", () => {
};
const isOrg = false;
it("should throw a TRPCError with code FORBIDDEN if the invitee is already a member of another organization", () => {
it("should not throw when inviting an existing user to the same organization", () => {
const inviteeWithOrg: User = {
...invitee,
organizationId: 2,
@@ -272,6 +274,19 @@ describe("Invite Member Utils", () => {
...mockedTeam,
parentId: 2,
}
expect(() =>
throwIfInviteIsToOrgAndUserExists(inviteeWithOrg, teamWithOrg, isOrg)
).not.toThrow();
});
it("should throw a TRPCError with code FORBIDDEN if the invitee is already a member of another organization", () => {
const inviteeWithOrg: User = {
...invitee,
organizationId: 2,
};
const teamWithOrg = {
...mockedTeam,
parentId: 3,
}
expect(() =>
throwIfInviteIsToOrgAndUserExists(inviteeWithOrg, teamWithOrg, isOrg)
).toThrow(TRPCError);
@@ -120,7 +120,6 @@ export function getOrgConnectionInfo({
if (usersEmail.split("@")[1] == orgAutoAcceptDomain) {
autoAccept = orgVerified ?? true;
} else {
// No longer throw error - not needed we just dont auto accept them
orgId = undefined;
autoAccept = false;
}
@@ -279,12 +278,17 @@ export async function sendVerificationEmail({
}
export function throwIfInviteIsToOrgAndUserExists(invitee: User, team: TeamWithParent, isOrg: boolean) {
if (invitee.organizationId && invitee.organizationId === team.parentId) {
return;
}
if (invitee.organizationId && invitee.organizationId !== team.parentId) {
throw new TRPCError({
code: "FORBIDDEN",
message: `User ${invitee.username} is already a member of another organization.`,
});
}
if ((invitee && isOrg) || (team.parentId && invitee)) {
throw new TRPCError({
code: "FORBIDDEN",