* 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 * 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 * A11ly * Feedback * 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 <udit.07814802719@cse.mait.ac.in> * Missing changes to support orgs schema changes * 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 <55134778+sean-brydon@users.noreply.github.com> * 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 <55134778+sean-brydon@users.noreply.github.com> * Vercel subdomain creation in PROD only * feat: organization settings general and members page (#9266) * feat: organization settings general page Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * feat: add members page Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * chore: remove Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: use invalidate Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: delete mutation Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: remove organization id Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * chore Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * fix: use zod schema Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> --------- Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> * Type fixes * 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 * Fix missing prop --------- Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> Co-authored-by: Leo Giovanetti <hello@leog.me> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
153 lines
3.3 KiB
TypeScript
153 lines
3.3 KiB
TypeScript
import { Prisma } from "@prisma/client";
|
|
|
|
import prisma, { baseEventTypeSelect } from "@calcom/prisma";
|
|
import { SchedulingType } from "@calcom/prisma/enums";
|
|
import { EventTypeMetaDataSchema, teamMetadataSchema } from "@calcom/prisma/zod-utils";
|
|
|
|
import { WEBAPP_URL } from "../../../constants";
|
|
|
|
export type TeamWithMembers = Awaited<ReturnType<typeof getTeamWithMembers>>;
|
|
|
|
export async function getTeamWithMembers(id?: number, slug?: string, userId?: number) {
|
|
const userSelect = Prisma.validator<Prisma.UserSelect>()({
|
|
username: true,
|
|
email: true,
|
|
name: true,
|
|
id: true,
|
|
bio: true,
|
|
});
|
|
const teamSelect = Prisma.validator<Prisma.TeamSelect>()({
|
|
id: true,
|
|
name: true,
|
|
slug: true,
|
|
logo: true,
|
|
bio: true,
|
|
hideBranding: true,
|
|
hideBookATeamMember: true,
|
|
metadata: true,
|
|
parent: {
|
|
select: {
|
|
id: true,
|
|
slug: true,
|
|
name: true,
|
|
logo: true,
|
|
},
|
|
},
|
|
children: {
|
|
select: {
|
|
name: true,
|
|
logo: true,
|
|
slug: true,
|
|
members: {
|
|
select: {
|
|
user: {
|
|
select: {
|
|
name: true,
|
|
username: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
members: {
|
|
select: {
|
|
accepted: true,
|
|
role: true,
|
|
disableImpersonation: true,
|
|
user: {
|
|
select: userSelect,
|
|
},
|
|
},
|
|
},
|
|
theme: true,
|
|
brandColor: true,
|
|
darkBrandColor: true,
|
|
eventTypes: {
|
|
where: {
|
|
hidden: false,
|
|
schedulingType: {
|
|
not: SchedulingType.MANAGED,
|
|
},
|
|
},
|
|
select: {
|
|
users: {
|
|
select: userSelect,
|
|
},
|
|
metadata: true,
|
|
...baseEventTypeSelect,
|
|
},
|
|
},
|
|
inviteToken: {
|
|
select: {
|
|
token: true,
|
|
expires: true,
|
|
expiresInDays: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
const where: Prisma.TeamFindFirstArgs["where"] = {};
|
|
|
|
if (userId) where.members = { some: { userId } };
|
|
if (id) where.id = id;
|
|
if (slug) where.slug = slug;
|
|
|
|
const team = await prisma.team.findFirst({
|
|
where,
|
|
select: teamSelect,
|
|
});
|
|
|
|
if (!team) return null;
|
|
const members = team.members.map((obj) => {
|
|
return {
|
|
...obj.user,
|
|
role: obj.role,
|
|
accepted: obj.accepted,
|
|
disableImpersonation: obj.disableImpersonation,
|
|
avatar: `${WEBAPP_URL}/${obj.user.username}/avatar.png`,
|
|
};
|
|
});
|
|
|
|
const eventTypes = team.eventTypes.map((eventType) => ({
|
|
...eventType,
|
|
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
|
}));
|
|
return { ...team, metadata: teamMetadataSchema.parse(team.metadata), eventTypes, members };
|
|
}
|
|
|
|
// also returns team
|
|
export async function isTeamAdmin(userId: number, teamId: number) {
|
|
return (
|
|
(await prisma.membership.findFirst({
|
|
where: {
|
|
userId,
|
|
teamId,
|
|
accepted: true,
|
|
OR: [{ role: "ADMIN" }, { role: "OWNER" }],
|
|
},
|
|
})) || false
|
|
);
|
|
}
|
|
|
|
export async function isTeamOwner(userId: number, teamId: number) {
|
|
return !!(await prisma.membership.findFirst({
|
|
where: {
|
|
userId,
|
|
teamId,
|
|
accepted: true,
|
|
role: "OWNER",
|
|
},
|
|
}));
|
|
}
|
|
|
|
export async function isTeamMember(userId: number, teamId: number) {
|
|
return !!(await prisma.membership.findFirst({
|
|
where: {
|
|
userId,
|
|
teamId,
|
|
accepted: true,
|
|
},
|
|
}));
|
|
}
|