From e2101845fd59320a85c1540515bafd2be8899441 Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman Date: Sun, 31 Mar 2024 20:22:48 -0700 Subject: [PATCH 1/3] Bug fix --- app/(protected)/projects/page-client.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/(protected)/projects/page-client.tsx b/app/(protected)/projects/page-client.tsx index 32364234..85aa8c36 100644 --- a/app/(protected)/projects/page-client.tsx +++ b/app/(protected)/projects/page-client.tsx @@ -90,9 +90,11 @@ export default function PageClient({ email }: { email: string }) { } function ProjectCard({ + key, project, teamId, }: { + key: number; project: Project; teamId: string; }) { @@ -111,7 +113,7 @@ function ProjectCard({ return
Loading...
; } return ( -
+
{!fetchProjecStats.isLoading && fetchProjecStats.data && From ef1ce1f4fe36e24b66b0f954bf4f8ef9c39c667e Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman Date: Sun, 31 Mar 2024 21:16:18 -0700 Subject: [PATCH 2/3] signup bug fix --- app/(protected)/settings/members/page-client.tsx | 2 ++ app/api/user/route.ts | 5 +++-- lib/middleware/app.ts | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/(protected)/settings/members/page-client.tsx b/app/(protected)/settings/members/page-client.tsx index 85471691..d758ca0b 100644 --- a/app/(protected)/settings/members/page-client.tsx +++ b/app/(protected)/settings/members/page-client.tsx @@ -76,6 +76,8 @@ export function InviteMember({ user }: { user: any }) { email: data.email, name: data.name, team_id: user.teamId, + role: "member", + status: "invited", }), }); diff --git a/app/api/user/route.ts b/app/api/user/route.ts index 9ab6ce52..49c7532b 100644 --- a/app/api/user/route.ts +++ b/app/api/user/route.ts @@ -96,7 +96,6 @@ export async function PUT(req: NextRequest) { }); } -// may not work / be necessary if users only get created through google auth export async function POST(req: NextRequest) { const session = await getServerSession(authOptions); if (!session || !session.user) { @@ -104,13 +103,15 @@ export async function POST(req: NextRequest) { } const data = await req.json(); - const { email, name, team_id } = data; + const { email, name, team_id, status, role } = data; const user = await prisma.user.create({ data: { email, name, teamId: team_id, + status, + role, }, }); diff --git a/lib/middleware/app.ts b/lib/middleware/app.ts index 848e9d27..5b14e492 100644 --- a/lib/middleware/app.ts +++ b/lib/middleware/app.ts @@ -16,7 +16,7 @@ export default async function AppMiddleware(req: NextRequest) { email?: string; user?: User; }; - if (session && path === "/login") { + if (session && (path === "/login" || path === "/signup")) { const userReq = await fetch( `${process.env.NEXT_PUBLIC_HOST}/api/user?email=${session?.email}`, { @@ -38,6 +38,8 @@ export default async function AppMiddleware(req: NextRequest) { body: JSON.stringify({ name: "My Team", userId: user.id, + role: "owner", + status: "active", }), }); } From e77b9f0bd9db6f91bafb547e76fb407f1b384cfd Mon Sep 17 00:00:00 2001 From: Karthik Kalyanaraman Date: Sun, 31 Mar 2024 21:55:41 -0700 Subject: [PATCH 3/3] user invite --- .../settings/members/page-client.tsx | 10 +++--- app/api/user/route.ts | 35 ++++++++++++++++++- lib/auth/options.ts | 2 ++ lib/middleware/app.ts | 30 ++++++++-------- .../migration.sql | 2 ++ prisma/schema.prisma | 2 +- 6 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 prisma/migrations/20240401042126_user_schema_fix/migration.sql diff --git a/app/(protected)/settings/members/page-client.tsx b/app/(protected)/settings/members/page-client.tsx index d758ca0b..351f0efd 100644 --- a/app/(protected)/settings/members/page-client.tsx +++ b/app/(protected)/settings/members/page-client.tsx @@ -217,11 +217,11 @@ function ManageRole({ member }: { member: any }) { defaultValue={type} >
- +

- Create projects and deploy AI models. + Standard-level permissions. Can view and edit projects.

@@ -256,21 +256,19 @@ function ManageRole({ member }: { member: any }) { function RemoveMemberDialog({ member }: { member: any }) { const [busy, setBusy] = useState(false); - const [type, setType] = useState(member.role); const [open, setOpen] = useState(false); const queryClient = useQueryClient(); const removeUser = async (member: any) => { try { setBusy(true); - await fetch(`/api/user?id=${member.id}`, { - method: "PUT", + await fetch("/api/user", { + method: "DELETE", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ id: member.id, - teamId: null, }), }); queryClient.invalidateQueries({ queryKey: ["getUsers"] }).then(() => { diff --git a/app/api/user/route.ts b/app/api/user/route.ts index 49c7532b..d7e95f34 100644 --- a/app/api/user/route.ts +++ b/app/api/user/route.ts @@ -52,7 +52,7 @@ export async function PUT(req: NextRequest) { } const data = await req.json(); - const { id, name, teamId, role } = data; + const { id, name, teamId, role, status } = data; if ("teamId" in data) { const user = await prisma.user.update({ @@ -82,6 +82,21 @@ export async function PUT(req: NextRequest) { }); } + if ("status" in data) { + console.log("updating status"); + const user = await prisma.user.update({ + where: { + id, + }, + data: { + status, + }, + }); + return NextResponse.json({ + data: user, + }); + } + const user = await prisma.user.update({ where: { id, @@ -119,3 +134,21 @@ export async function POST(req: NextRequest) { data: user, }); } + +export async function DELETE(req: NextRequest) { + const session = await getServerSession(authOptions); + if (!session || !session.user) { + redirect("/login"); + } + + const data = await req.json(); + const { id } = data; + + const user = await prisma.user.delete({ + where: { + id, + }, + }); + + return NextResponse.json({}); +} diff --git a/lib/auth/options.ts b/lib/auth/options.ts index 8d69afee..c5a15f98 100644 --- a/lib/auth/options.ts +++ b/lib/auth/options.ts @@ -40,6 +40,8 @@ export const authOptions: NextAuthOptions = { email: process.env.ADMIN_EMAIL, name: "Admin", image: null, + role: "owner", + status: "active", }, }); } diff --git a/lib/middleware/app.ts b/lib/middleware/app.ts index 5b14e492..74b0112c 100644 --- a/lib/middleware/app.ts +++ b/lib/middleware/app.ts @@ -28,20 +28,22 @@ export default async function AppMiddleware(req: NextRequest) { ); const response = await userReq.json(); const user = response.data; - if (user && !user.teamId) { - // create a team - await fetch(`${process.env.NEXT_PUBLIC_HOST}/api/team`, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - name: "My Team", - userId: user.id, - role: "owner", - status: "active", - }), - }); + if (user) { + if (!user.teamId) { + // create a team + await fetch(`${process.env.NEXT_PUBLIC_HOST}/api/team`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + name: "My Team", + userId: user.id, + role: "owner", + status: "active", + }), + }); + } } // if there's a session diff --git a/prisma/migrations/20240401042126_user_schema_fix/migration.sql b/prisma/migrations/20240401042126_user_schema_fix/migration.sql new file mode 100644 index 00000000..7b21d326 --- /dev/null +++ b/prisma/migrations/20240401042126_user_schema_fix/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "User" ALTER COLUMN "role" SET DEFAULT 'owner'; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2f1cef1c..6ec8461e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -53,7 +53,7 @@ model User { teamId String? Team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade) status String? @default("active") // invited, active - role Role? @default(member) + role Role? @default(owner) createdAt DateTime @default(now()) Evaluation Evaluation[] }