This commit is contained in:
1 parent
50df22928b
commit
7c0ee9f186
38 files changed
+920
-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