feat: Enable Conferencing Apps for Team Events [CAL-1925] (#10383)
Co-authored-by: Omar López <[email protected]> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
30 files changed
+310
-140
No files matched your search
@@ -27,6 +27,7 @@ export const metadata = {
|
||||
},
|
||||
key: { apikey: randomString(12) },
|
||||
dirName: "huddle01video",
|
||||
concurrentMeetings: true,
|
||||
} as AppMeta;
|
||||
|
||||
export default metadata;
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwIfNotHaveAdminAccessToTeam";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
@@ -13,12 +14,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
if (!req.session?.user?.id) {
|
||||
return res.status(401).json({ message: "You must be logged in to do this" });
|
||||
}
|
||||
const { teamId } = req.query;
|
||||
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: Number(teamId) ?? null, userId: req.session.user.id });
|
||||
const installForObject = teamId ? { teamId: Number(teamId) } : { userId: req.session.user.id };
|
||||
|
||||
const appType = "huddle01_video";
|
||||
try {
|
||||
const alreadyInstalled = await prisma.credential.findFirst({
|
||||
where: {
|
||||
type: appType,
|
||||
userId: req.session.user.id,
|
||||
...installForObject,
|
||||
},
|
||||
});
|
||||
if (alreadyInstalled) {
|
||||
@@ -28,7 +34,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
data: {
|
||||
type: appType,
|
||||
key: {},
|
||||
userId: req.session.user.id,
|
||||
...installForObject,
|
||||
appId: "huddle01",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -24,6 +24,7 @@ export const metadata = {
|
||||
},
|
||||
},
|
||||
dirName: "jitsivideo",
|
||||
concurrentMeetings: true,
|
||||
} as AppMeta;
|
||||
|
||||
export default metadata;
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwIfNotHaveAdminAccessToTeam";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import getInstalledAppPath from "../../_utils/getInstalledAppPath";
|
||||
@@ -13,12 +14,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
if (!req.session?.user?.id) {
|
||||
return res.status(401).json({ message: "You must be logged in to do this" });
|
||||
}
|
||||
const { teamId } = req.query;
|
||||
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: Number(teamId) ?? null, userId: req.session.user.id });
|
||||
|
||||
const installForObject = teamId ? { teamId: Number(teamId) } : { userId: req.session.user.id };
|
||||
const appType = "jitsi_video";
|
||||
try {
|
||||
const alreadyInstalled = await prisma.credential.findFirst({
|
||||
where: {
|
||||
type: appType,
|
||||
userId: req.session.user.id,
|
||||
...installForObject,
|
||||
},
|
||||
});
|
||||
if (alreadyInstalled) {
|
||||
@@ -28,7 +34,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
data: {
|
||||
type: appType,
|
||||
key: {},
|
||||
userId: req.session.user.id,
|
||||
...installForObject,
|
||||
appId: "jitsi",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -344,9 +344,11 @@ export const getLocationValueForDB = (
|
||||
eventLocations: LocationObject[]
|
||||
) => {
|
||||
let bookingLocation = bookingLocationTypeOrValue;
|
||||
let conferenceCredentialId = undefined;
|
||||
eventLocations.forEach((location) => {
|
||||
if (location.type === bookingLocationTypeOrValue) {
|
||||
const eventLocationType = getEventLocationType(bookingLocationTypeOrValue);
|
||||
conferenceCredentialId = location.credentialId;
|
||||
if (!eventLocationType) {
|
||||
return;
|
||||
}
|
||||
@@ -359,7 +361,7 @@ export const getLocationValueForDB = (
|
||||
bookingLocation = location[eventLocationType.defaultValueVariable] || bookingLocation;
|
||||
}
|
||||
});
|
||||
return bookingLocation;
|
||||
return { bookingLocation, conferenceCredentialId };
|
||||
};
|
||||
|
||||
export const getEventLocationValue = (eventLocations: LocationObject[], bookingLocation: LocationObject) => {
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
"label": "MS Teams"
|
||||
}
|
||||
},
|
||||
"dirName": "office365video"
|
||||
"dirName": "office365video",
|
||||
"concurrentMeetings": true
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import type { TFunction } from "next-i18next";
|
||||
|
||||
import type { CredentialDataWithTeamName } from "@calcom/app-store/utils";
|
||||
import getEnabledApps from "@calcom/lib/apps/getEnabledApps";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import { AppCategories } from "@calcom/prisma/enums";
|
||||
|
||||
import { defaultLocations } from "./locations";
|
||||
|
||||
export async function getLocationGroupedOptions(
|
||||
userOrTeamId: { userId: number } | { teamId: number },
|
||||
t: TFunction
|
||||
) {
|
||||
const apps: Record<
|
||||
string,
|
||||
{
|
||||
label: string;
|
||||
value: string;
|
||||
disabled?: boolean;
|
||||
icon?: string;
|
||||
slug?: string;
|
||||
credential?: CredentialDataWithTeamName;
|
||||
}[]
|
||||
> = {};
|
||||
|
||||
let idToSearchObject = {};
|
||||
|
||||
if ("teamId" in userOrTeamId) {
|
||||
const teamId = userOrTeamId.teamId;
|
||||
// See if the team event belongs to an org
|
||||
const org = await prisma.team.findFirst({
|
||||
where: {
|
||||
children: {
|
||||
some: {
|
||||
id: teamId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (org) {
|
||||
idToSearchObject = {
|
||||
teamId: {
|
||||
in: [teamId, org.id],
|
||||
},
|
||||
};
|
||||
} else {
|
||||
idToSearchObject = { teamId };
|
||||
}
|
||||
} else {
|
||||
idToSearchObject = { userId: userOrTeamId.userId };
|
||||
}
|
||||
|
||||
const credentials = await prisma.credential.findMany({
|
||||
where: {
|
||||
...idToSearchObject,
|
||||
app: {
|
||||
categories: {
|
||||
hasSome: [AppCategories.conferencing, AppCategories.video],
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
key: true,
|
||||
userId: true,
|
||||
teamId: true,
|
||||
appId: true,
|
||||
invalid: true,
|
||||
team: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const integrations = await getEnabledApps(credentials, true);
|
||||
|
||||
integrations.forEach((app) => {
|
||||
if (app.locationOption) {
|
||||
// All apps that are labeled as a locationOption are video apps. Extract the secondary category if available
|
||||
let category =
|
||||
app.categories.length >= 2
|
||||
? app.categories.find(
|
||||
(category) =>
|
||||
!([AppCategories.video, AppCategories.conferencing] as string[]).includes(category)
|
||||
)
|
||||
: app.category;
|
||||
if (!category) category = AppCategories.conferencing;
|
||||
|
||||
for (const credential of app.credentials) {
|
||||
const label = `${app.locationOption.label} ${
|
||||
credential.team?.name ? `(${credential.team.name})` : ""
|
||||
}`;
|
||||
const option = { ...app.locationOption, label, icon: app.logo, slug: app.slug, credential };
|
||||
if (apps[category]) {
|
||||
apps[category] = [...apps[category], option];
|
||||
} else {
|
||||
apps[category] = [option];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
defaultLocations.forEach((l) => {
|
||||
const category = l.category;
|
||||
if (apps[category]) {
|
||||
apps[category] = [
|
||||
...apps[category],
|
||||
{
|
||||
label: l.label,
|
||||
value: l.type,
|
||||
icon: l.iconUrl,
|
||||
},
|
||||
];
|
||||
} else {
|
||||
apps[category] = [
|
||||
{
|
||||
label: l.label,
|
||||
value: l.type,
|
||||
icon: l.iconUrl,
|
||||
},
|
||||
];
|
||||
}
|
||||
});
|
||||
const locations = [];
|
||||
|
||||
// Translating labels and pushing into array
|
||||
for (const category in apps) {
|
||||
const tmp = {
|
||||
label: t(category),
|
||||
options: apps[category].map((l) => ({
|
||||
...l,
|
||||
label: t(l.label),
|
||||
})),
|
||||
};
|
||||
|
||||
locations.push(tmp);
|
||||
}
|
||||
|
||||
return locations;
|
||||
}
|
||||
+27
-71
@@ -1,13 +1,9 @@
|
||||
import type { Credential } from "@prisma/client";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import type { TFunction } from "next-i18next";
|
||||
|
||||
// If you import this file on any app it should produce circular dependency
|
||||
// import appStore from "./index";
|
||||
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
|
||||
import type { EventLocationType } from "@calcom/app-store/locations";
|
||||
import { defaultLocations } from "@calcom/app-store/locations";
|
||||
import { AppCategories } from "@calcom/prisma/enums";
|
||||
import type { App, AppMeta } from "@calcom/types/App";
|
||||
|
||||
export * from "./_utils/getEventTypeAppData";
|
||||
@@ -39,77 +35,19 @@ const credentialData = Prisma.validator<Prisma.CredentialArgs>()({
|
||||
|
||||
export type CredentialData = Prisma.CredentialGetPayload<typeof credentialData>;
|
||||
|
||||
export type CredentialDataWithTeamName = CredentialData & {
|
||||
team?: {
|
||||
name: string;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export const ALL_APPS = Object.values(ALL_APPS_MAP);
|
||||
|
||||
export function getLocationGroupedOptions(integrations: ReturnType<typeof getApps>, t: TFunction) {
|
||||
const apps: Record<
|
||||
string,
|
||||
{ label: string; value: string; disabled?: boolean; icon?: string; slug?: string }[]
|
||||
> = {};
|
||||
integrations.forEach((app) => {
|
||||
if (app.locationOption) {
|
||||
// All apps that are labeled as a locationOption are video apps. Extract the secondary category if available
|
||||
let category =
|
||||
app.categories.length >= 2
|
||||
? app.categories.find(
|
||||
(category) =>
|
||||
!([AppCategories.video, AppCategories.conferencing] as string[]).includes(category)
|
||||
)
|
||||
: app.category;
|
||||
if (!category) category = AppCategories.conferencing;
|
||||
const option = { ...app.locationOption, icon: app.logo, slug: app.slug };
|
||||
if (apps[category]) {
|
||||
apps[category] = [...apps[category], option];
|
||||
} else {
|
||||
apps[category] = [option];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
defaultLocations.forEach((l) => {
|
||||
const category = l.category;
|
||||
if (apps[category]) {
|
||||
apps[category] = [
|
||||
...apps[category],
|
||||
{
|
||||
label: l.label,
|
||||
value: l.type,
|
||||
icon: l.iconUrl,
|
||||
},
|
||||
];
|
||||
} else {
|
||||
apps[category] = [
|
||||
{
|
||||
label: l.label,
|
||||
value: l.type,
|
||||
icon: l.iconUrl,
|
||||
},
|
||||
];
|
||||
}
|
||||
});
|
||||
const locations = [];
|
||||
|
||||
// Translating labels and pushing into array
|
||||
for (const category in apps) {
|
||||
const tmp = {
|
||||
label: t(category),
|
||||
options: apps[category].map((l) => ({
|
||||
...l,
|
||||
label: t(l.label),
|
||||
})),
|
||||
};
|
||||
|
||||
locations.push(tmp);
|
||||
}
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* This should get all available apps to the user based on his saved
|
||||
* credentials, this should also get globally available apps.
|
||||
*/
|
||||
function getApps(credentials: CredentialData[], filterOnCredentials?: boolean) {
|
||||
function getApps(credentials: CredentialDataWithTeamName[], filterOnCredentials?: boolean) {
|
||||
const apps = ALL_APPS.reduce((reducedArray, appMeta) => {
|
||||
const appCredentials = credentials.filter((credential) => credential.type === appMeta.type);
|
||||
|
||||
@@ -125,9 +63,12 @@ function getApps(credentials: CredentialData[], filterOnCredentials?: boolean) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
key: appMeta.key!,
|
||||
userId: 0,
|
||||
teamId: 0,
|
||||
teamId: null,
|
||||
appId: appMeta.slug,
|
||||
invalid: false,
|
||||
team: {
|
||||
name: "Global",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -154,7 +95,7 @@ function getApps(credentials: CredentialData[], filterOnCredentials?: boolean) {
|
||||
});
|
||||
|
||||
return reducedArray;
|
||||
}, [] as (App & { credential: Credential; credentials: Credential[]; locationOption: LocationOption | null })[]);
|
||||
}, [] as (App & { credential: CredentialDataWithTeamName; credentials: CredentialDataWithTeamName[]; locationOption: LocationOption | null })[]);
|
||||
|
||||
return apps;
|
||||
}
|
||||
@@ -191,4 +132,19 @@ export function getAppFromLocationValue(type: string): AppMeta | undefined {
|
||||
return ALL_APPS.find((app) => app?.appData?.location?.type === type);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appCategories - from app metadata
|
||||
* @param concurrentMeetings - from app metadata
|
||||
* @returns - true if app supports team install
|
||||
*/
|
||||
export function doesAppSupportTeamInstall(
|
||||
appCategories: string[],
|
||||
concurrentMeetings: boolean | undefined = undefined
|
||||
) {
|
||||
return !appCategories.some(
|
||||
(category) => category === "calendar" || (category === "conferencing" && !concurrentMeetings)
|
||||
);
|
||||
}
|
||||
|
||||
export default getApps;
|
||||
@@ -21,5 +21,6 @@
|
||||
},
|
||||
"isTemplate": false,
|
||||
"__createdUsingCli": true,
|
||||
"__template": "basic"
|
||||
"__template": "basic",
|
||||
"concurrentMeetings": true
|
||||
}
|
||||
Reference in new issue
Block a user