Feat/impersonate users (#2503)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]>
This commit is contained in:
13 files changed
+285
-34
No files matched your search
@@ -8,7 +8,7 @@
|
||||
"jsx": "preserve",
|
||||
"paths": {
|
||||
"@lib/*": ["../../../apps/web/lib/*"]
|
||||
},
|
||||
}
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": ["dist", "build", "node_modules", "test-cal.tsx"]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "UserPermissionRole" AS ENUM ('USER', 'ADMIN');
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "role" "UserPermissionRole" NOT NULL DEFAULT E'USER';
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Impersonations" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"impersonatedUserId" INTEGER NOT NULL,
|
||||
"impersonatedById" INTEGER NOT NULL,
|
||||
|
||||
CONSTRAINT "Impersonations_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Impersonations" ADD CONSTRAINT "Impersonations_impersonatedUserId_fkey" FOREIGN KEY ("impersonatedUserId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Impersonations" ADD CONSTRAINT "Impersonations_impersonatedById_fkey" FOREIGN KEY ("impersonatedById") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -107,6 +107,11 @@ model DestinationCalendar {
|
||||
eventTypeId Int? @unique
|
||||
}
|
||||
|
||||
enum UserPermissionRole {
|
||||
USER
|
||||
ADMIN
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
username String? @unique
|
||||
@@ -155,6 +160,9 @@ model User {
|
||||
allowDynamicBooking Boolean? @default(true)
|
||||
metadata Json?
|
||||
verified Boolean? @default(false)
|
||||
role UserPermissionRole @default(USER)
|
||||
impersonatedUsers Impersonations[] @relation("impersonated_user")
|
||||
impersonatedBy Impersonations[] @relation("impersonated_by_user")
|
||||
apiKeys ApiKey[]
|
||||
|
||||
@@map(name: "users")
|
||||
@@ -376,6 +384,15 @@ model Webhook {
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model Impersonations {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
impersonatedUser User @relation("impersonated_user", fields: [impersonatedUserId], references: [id])
|
||||
impersonatedBy User @relation("impersonated_by_user", fields: [impersonatedById], references: [id])
|
||||
impersonatedUserId Int
|
||||
impersonatedById Int
|
||||
}
|
||||
|
||||
model ApiKey {
|
||||
id String @id @unique @default(cuid())
|
||||
userId Int
|
||||
|
||||
Vendored
+3
@@ -1,3 +1,4 @@
|
||||
import { UserPermissionRole } from "@prisma/client";
|
||||
import NextAuth, { DefaultSession } from "next-auth";
|
||||
|
||||
declare module "next-auth" {
|
||||
@@ -5,6 +6,8 @@ declare module "next-auth" {
|
||||
type CalendsoSessionUser = DefaultSessionUser & {
|
||||
id: number;
|
||||
username: string;
|
||||
impersonatedByUID?: number;
|
||||
role: UserPermissionRole;
|
||||
};
|
||||
/**
|
||||
* Returned by `useSession`, `getSession` and received as a prop on the `Provider` React Context
|
||||
|
||||
Reference in new issue
Block a user