From 7e13995f18df489556bee0307819fbc6fd37b2a7 Mon Sep 17 00:00:00 2001 From: Harish Mohan Raj Date: Tue, 21 Nov 2023 14:12:44 +0530 Subject: [PATCH] Restrict access to other user conversations (#32) --- main.wasp | 3 +++ .../migration.sql | 5 +++++ src/server/actions.ts | 1 + src/server/queries.ts | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 migrations/20231116051633_add_user_id_to_conversation_model/migration.sql diff --git a/main.wasp b/main.wasp index f476a1d..f63183d 100644 --- a/main.wasp +++ b/main.wasp @@ -91,6 +91,7 @@ entity User {=psl externalAuthAssociations SocialLogin[] chats Chat[] + conversations Conversation[] psl=} // relatedObject RelatedObject[] - add in line 86 entity SocialLogin {=psl @@ -130,6 +131,8 @@ entity Conversation {=psl updatedAt DateTime @updatedAt chat Chat? @relation(fields: [chatId], references: [id]) chatId Int? + user User? @relation(fields: [userId], references: [id]) + userId Int? psl=} diff --git a/migrations/20231116051633_add_user_id_to_conversation_model/migration.sql b/migrations/20231116051633_add_user_id_to_conversation_model/migration.sql new file mode 100644 index 0000000..79804a1 --- /dev/null +++ b/migrations/20231116051633_add_user_id_to_conversation_model/migration.sql @@ -0,0 +1,5 @@ +-- AlterTable +ALTER TABLE "Conversation" ADD COLUMN "userId" INTEGER; + +-- AddForeignKey +ALTER TABLE "Conversation" ADD CONSTRAINT "Conversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/src/server/actions.ts b/src/server/actions.ts index 50a8b9a..bc38b86 100644 --- a/src/server/actions.ts +++ b/src/server/actions.ts @@ -180,6 +180,7 @@ export const createChat: CreateChat = async (_args, context) }, ], chat: { connect: { id: chat.id } }, + user: { connect: { id: context.user.id } }, }, }); } diff --git a/src/server/queries.ts b/src/server/queries.ts index be7bce8..4aa674c 100644 --- a/src/server/queries.ts +++ b/src/server/queries.ts @@ -45,7 +45,7 @@ export const getConversations: GetConversations