forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements basic user locking for admins
- Loading branch information
Showing
10 changed files
with
118 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/prisma/migrations/20231117002911_add_users_locked/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "users" ADD COLUMN "locked" BOOLEAN NOT NULL DEFAULT false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/trpc/server/routers/viewer/admin/lockUserAccount.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { prisma } from "@calcom/prisma"; | ||
|
||
import type { TrpcSessionUser } from "../../../trpc"; | ||
import type { TAdminLockUserAccountSchema } from "./lockUserAccount.schema"; | ||
|
||
type GetOptions = { | ||
ctx: { | ||
user: NonNullable<TrpcSessionUser>; | ||
}; | ||
input: TAdminLockUserAccountSchema; | ||
}; | ||
|
||
const lockUserAccountHandler = async ({ input }: GetOptions) => { | ||
const { userId, locked } = input; | ||
|
||
const user = await prisma.user.update({ | ||
where: { | ||
id: userId, | ||
}, | ||
data: { | ||
locked, | ||
}, | ||
}); | ||
|
||
if (!user) { | ||
throw new Error("User not found"); | ||
} | ||
|
||
return { | ||
success: true, | ||
userId, | ||
locked, | ||
}; | ||
}; | ||
|
||
export default lockUserAccountHandler; |
8 changes: 8 additions & 0 deletions
8
packages/trpc/server/routers/viewer/admin/lockUserAccount.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from "zod"; | ||
|
||
export const ZAdminLockUserAccountSchema = z.object({ | ||
userId: z.number(), | ||
locked: z.boolean(), | ||
}); | ||
|
||
export type TAdminLockUserAccountSchema = z.infer<typeof ZAdminLockUserAccountSchema>; |