feat: org team app install (#15704)
* feat: remove dropdown from app-store and redirect to new-app-install-flow * removed extra code * fix: account select loading issue * removed getPaymentCredential (unused) * fix: only redirect after the app has been added to all the event-types * remove overflowIndicatorStyles * refactor getUserAdminTeams * send teamId instead of id * seperate locations component * for conferencing apps skip select account page * refactor InstallAppButtonChild * installing conferencing apps shows locations dropdown in configure step * send location data to the handler * send location data to the handler * add the newly installed to the locations dropdown (prefillLocation) * fix: type errors * fix: handle es-lint errors * fix: app is added again on submit * only add app if not already added * fix: type erros * filter out managed events for now * fix: show installed count badge * remove 2 toast message * feat: added tests for conferencing apps * fix: loading indicator * Update apps/web/pages/apps/installation/[[...step]].tsx Co-authored-by: Joe Au-Yeung <[email protected]> * Update apps/web/pages/apps/installation/[[...step]].tsx Co-authored-by: Joe Au-Yeung <[email protected]> * move `getUserAdminTeams` to `UserRepository` * fix: zoom and jelly not redirecting to the new app install flow * fix: typo * add `installableOnTeams` prop * split `configureStepCard` into smaller components * fix: step count * fix: show loading indicator until the new page is loaded * fix: organizer_default_conferencing_app not visible in a team * Introduce QueryClient to app card tests * fix: typo * add installableOnTeams prop * fix: tests * seated events shouldn't have multiple locations #15174 * fix: o365 callback * fix: office365_video not redirecting to event-types step * Revert "fix: o365 callback" This reverts commit bba841035ea34f8c31201b64c77221b8d8c3e626. * add TEAM_SELECT_STEP * add apps to orgs and their sub-teams initial commit * undo team select step * small ui fix * fix: wrong step numbers * fix: dont allow app installation without cretendialId * fix: don't show acme team as it cannot have any events * refactor useAddAppMutation * removed console.log * added comment * added comment * move locationOptions from getServerSideProps a trpc query * fix: failing tests * Update conferencingApps.e2e.ts * refactor useAddAppMutation * refactor useAddAppMutation 2 * fix: test failing * fix: unit test * Revert "fix: unit test" This reverts commit 6d74032211d094478c6d7cf9aedbce696dfb768d. * fix: failing test * Increase test timeout for conferencing app tests * fix: write separate tests for each conferencing app to prevent hitting 6000 ms timeout * improved tests naming * fix: correct message and translation key #15657 * fix: write separate tests for each analytics app to prevent hitting 6000 ms timeout * fix: analytics apps test * attempt to fix failing tests * fix typo * refactor * update: replace text-gray with text-stuble - works with light mode too * update: use userRepository.getUserAdminTeams * Merge branch 'main' into feat/org-team-app-install-2 * fix: after merge conflict from app router migration * remove consoles --------- Co-authored-by: Omar López <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
16 files changed
+658
-474
No files matched your search
@@ -29,20 +29,7 @@ const createOAuthAppCredential = async (
|
||||
|
||||
if (state?.teamId) {
|
||||
// Check that the user belongs to the team
|
||||
const team = await prisma.team.findFirst({
|
||||
where: {
|
||||
id: state.teamId,
|
||||
members: {
|
||||
some: {
|
||||
userId: req.session?.user.id,
|
||||
accepted: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: { id: true, members: { select: { userId: true } } },
|
||||
});
|
||||
|
||||
if (!team) throw new Error("User does not belong to the team");
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: state?.teamId ?? null, userId });
|
||||
|
||||
return await prisma.credential.create({
|
||||
data: {
|
||||
@@ -54,8 +41,6 @@ const createOAuthAppCredential = async (
|
||||
});
|
||||
}
|
||||
|
||||
await throwIfNotHaveAdminAccessToTeam({ teamId: state?.teamId ?? null, userId });
|
||||
|
||||
return await prisma.credential.create({
|
||||
data: {
|
||||
type: appData.type,
|
||||
|
||||
@@ -11,7 +11,8 @@ export const throwIfNotHaveAdminAccessToTeam = async ({
|
||||
if (!teamId) {
|
||||
return;
|
||||
}
|
||||
const teamsUserHasAdminAccessFor = await UserRepository.getUserAdminTeams(userId);
|
||||
const userAdminTeams = await UserRepository.getUserAdminTeams(userId);
|
||||
const teamsUserHasAdminAccessFor = userAdminTeams?.teams?.map(({ team }) => team.id) ?? [];
|
||||
const hasAdminAccessToTeam = teamsUserHasAdminAccessFor.some((id) => id === teamId);
|
||||
|
||||
if (!hasAdminAccessToTeam) {
|
||||
|
||||
@@ -67,8 +67,8 @@ function useAddAppMutation(_type: App["type"] | null, options?: UseAddAppMutatio
|
||||
const state: IntegrationOAuthCallbackState = {
|
||||
onErrorReturnTo,
|
||||
fromApp: true,
|
||||
...(type === "google_calendar" && { installGoogleVideo: options?.installGoogleVideo }),
|
||||
...(teamId && { teamId }),
|
||||
...(type === "google_calendar" && { installGoogleVideo: options?.installGoogleVideo }),
|
||||
...(returnTo && { returnTo }),
|
||||
...(defaultInstall && { defaultInstall }),
|
||||
};
|
||||
|
||||
@@ -516,7 +516,58 @@ export class UserRepository {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
static async getUserAdminTeams(userId: number) {
|
||||
return prisma.user.findFirst({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
avatarUrl: true,
|
||||
name: true,
|
||||
username: true,
|
||||
teams: {
|
||||
where: {
|
||||
accepted: true,
|
||||
OR: [
|
||||
{
|
||||
role: { in: [MembershipRole.ADMIN, MembershipRole.OWNER] },
|
||||
},
|
||||
{
|
||||
team: {
|
||||
parent: {
|
||||
members: {
|
||||
some: {
|
||||
id: userId,
|
||||
role: { in: [MembershipRole.ADMIN, MembershipRole.OWNER] },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
logoUrl: true,
|
||||
isOrganization: true,
|
||||
parent: {
|
||||
select: {
|
||||
logoUrl: true,
|
||||
name: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
static async isAdminOfTeamOrParentOrg({ userId, teamId }: { userId: number; teamId: number }) {
|
||||
const membershipQuery = {
|
||||
members: {
|
||||
@@ -543,29 +594,6 @@ export class UserRepository {
|
||||
return !!teams.length;
|
||||
}
|
||||
|
||||
static async getUserAdminTeams(userId: number): Promise<number[]> {
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
select: {
|
||||
teams: {
|
||||
where: {
|
||||
accepted: true,
|
||||
role: { in: [MembershipRole.ADMIN, MembershipRole.OWNER] },
|
||||
},
|
||||
select: { teamId: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const teamIds = [];
|
||||
for (const team of user?.teams || []) {
|
||||
teamIds.push(team.teamId);
|
||||
}
|
||||
return teamIds;
|
||||
}
|
||||
|
||||
static async getTimeZoneAndDefaultScheduleId({ userId }: { userId: number }) {
|
||||
return await prisma.user.findUnique({
|
||||
where: {
|
||||
|
||||
@@ -15,6 +15,7 @@ type AppCredentialsByTypeOptions = {
|
||||
export const appCredentialsByTypeHandler = async ({ ctx, input }: AppCredentialsByTypeOptions) => {
|
||||
const { user } = ctx;
|
||||
const userAdminTeams = await UserRepository.getUserAdminTeams(ctx.user.id);
|
||||
const userAdminTeamsIds = userAdminTeams?.teams?.map(({ team }) => team.id) ?? [];
|
||||
|
||||
const credentials = await prisma.credential.findMany({
|
||||
where: {
|
||||
@@ -22,7 +23,7 @@ export const appCredentialsByTypeHandler = async ({ ctx, input }: AppCredentials
|
||||
{ userId: user.id },
|
||||
{
|
||||
teamId: {
|
||||
in: userAdminTeams,
|
||||
in: userAdminTeamsIds,
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -34,6 +35,6 @@ export const appCredentialsByTypeHandler = async ({ ctx, input }: AppCredentials
|
||||
// return user.credentials.filter((app) => app.type == input.appType).map((credential) => credential.id);
|
||||
return {
|
||||
credentials,
|
||||
userAdminTeams,
|
||||
userAdminTeams: userAdminTeamsIds,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user