feat: Populate gCal calendar cache via webhooks (#11928)
* WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Update CalendarService.ts * Type fixes * WIP * fix: improve cache hits * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Feedback * Update CalendarService.ts * Update CalendarService.ts * Update _router.ts * feedback * WIP * WIP * Update schema.prisma * feedback * typefixes * Update Calendar.d.ts * fix: watches when adding a calendar * Discard changes to packages/app-store/googlecalendar/api/add.ts * WIP Signed-off-by: Omar López <[email protected]> * WIP Signed-off-by: Omar López <[email protected]> * WP Signed-off-by: Omar López <[email protected]> * Update calendar.ts * Update calendar.ts * Update callback.ts * Update callback.ts * Conflicts * WIP * WIP * Update CalendarService.ts * Cleanup * Discard changes to packages/features/settings/layouts/SettingsLayout.tsx * Update calendar-cache.repository.ts * WIP * Update getSelectedCalendarsToWatch.sql * WIP * Update CalendarService.ts * Cleanup * Discard changes to packages/app-store/googlecalendar/lib/CalendarService.ts * Create CalendarService.wip.ts * WIP * Update CalendarService.ts * Update getSelectedCalendarsToWatch.sql * Delete CalendarService.wip.ts * test updates * cleanup Signed-off-by: Omar López <[email protected]> * Update CalendarService.test.ts * Update CalendarService.ts * type fixes * Update OAuthManager.ts * Update CalendarService.ts * Almost there * Update CalendarService.test.ts * Update calendar.ts * Update callback.ts * Update toggleFeatureFlag.handler.ts * fix: feedback * Update getSelectedCalendarsToWatch.sql * Fix unit tests --------- Signed-off-by: Omar López <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
1 parent
5012a16794
commit
d294a74aad
40 files changed
+963
-240
No files matched your search
@@ -1,13 +1,12 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { authedAdminProcedure } from "../../../procedures/authedProcedure";
|
||||
import { router, importHandler } from "../../../trpc";
|
||||
import { importHandler, router } from "../../../trpc";
|
||||
import { ZCreateSelfHostedLicenseSchema } from "./createSelfHostedLicenseKey.schema";
|
||||
import { ZListMembersSchema } from "./listPaginated.schema";
|
||||
import { ZAdminLockUserAccountSchema } from "./lockUserAccount.schema";
|
||||
import { ZAdminRemoveTwoFactor } from "./removeTwoFactor.schema";
|
||||
import { ZAdminPasswordResetSchema } from "./sendPasswordReset.schema";
|
||||
import { ZSetSMSLockState } from "./setSMSLockState.schema";
|
||||
import { toggleFeatureFlag } from "./toggleFeatureFlag.procedure";
|
||||
|
||||
const NAMESPACE = "admin";
|
||||
|
||||
@@ -32,16 +31,7 @@ export const adminRouter = router({
|
||||
);
|
||||
return handler(opts);
|
||||
}),
|
||||
toggleFeatureFlag: authedAdminProcedure
|
||||
.input(z.object({ slug: z.string(), enabled: z.boolean() }))
|
||||
.mutation(({ ctx, input }) => {
|
||||
const { prisma, user } = ctx;
|
||||
const { slug, enabled } = input;
|
||||
return prisma.feature.update({
|
||||
where: { slug },
|
||||
data: { enabled, updatedBy: user.id },
|
||||
});
|
||||
}),
|
||||
toggleFeatureFlag,
|
||||
removeTwoFactor: authedAdminProcedure.input(ZAdminRemoveTwoFactor).mutation(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
namespaced("removeTwoFactor"),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
import type { TrpcSessionUser } from "../../../trpc";
|
||||
import type { TAdminToggleFeatureFlagSchema } from "./toggleFeatureFlag.schema";
|
||||
|
||||
type GetOptions = {
|
||||
ctx: {
|
||||
user: NonNullable<TrpcSessionUser>;
|
||||
prisma: PrismaClient;
|
||||
};
|
||||
input: TAdminToggleFeatureFlagSchema;
|
||||
};
|
||||
|
||||
export const toggleFeatureFlagHandler = async (opts: GetOptions) => {
|
||||
const { ctx, input } = opts;
|
||||
const { prisma, user } = ctx;
|
||||
const { slug, enabled } = input;
|
||||
await handleFeatureToggle(opts);
|
||||
return prisma.feature.update({
|
||||
where: { slug },
|
||||
data: { enabled, updatedBy: user.id },
|
||||
});
|
||||
};
|
||||
|
||||
export default toggleFeatureFlagHandler;
|
||||
|
||||
async function handleFeatureToggle({ ctx, input }: GetOptions) {
|
||||
const { prisma } = ctx;
|
||||
const { slug, enabled } = input;
|
||||
// If we're disabling the calendar cache, clear it
|
||||
if (slug === "calendar-cache" && enabled === false) {
|
||||
logger.info("Clearing calendar cache");
|
||||
await prisma.calendarCache.deleteMany();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { authedAdminProcedure } from "../../../procedures/authedProcedure";
|
||||
import { importHandler } from "../../../trpc";
|
||||
import { ZAdminToggleFeatureFlagSchema } from "./toggleFeatureFlag.schema";
|
||||
|
||||
export const toggleFeatureFlag = authedAdminProcedure
|
||||
.input(ZAdminToggleFeatureFlagSchema)
|
||||
.mutation(async (opts) => {
|
||||
const handler = await importHandler(
|
||||
"admin.toggleFeatureFlag",
|
||||
() => import("./toggleFeatureFlag.handler")
|
||||
);
|
||||
return handler(opts);
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const ZAdminToggleFeatureFlagSchema = z.object({
|
||||
slug: z.string(),
|
||||
enabled: z.boolean(),
|
||||
});
|
||||
|
||||
export type TAdminToggleFeatureFlagSchema = z.infer<typeof ZAdminToggleFeatureFlagSchema>;
|
||||
Reference in new issue
Block a user