From 073adbe48c6f9093879f64b4b945fbc90fa7dfd2 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 11 Jul 2023 11:19:01 +0200 Subject: [PATCH 1/3] do not allow to create room with self --- backend/src/schema/resolvers/rooms.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/schema/resolvers/rooms.ts b/backend/src/schema/resolvers/rooms.ts index 02309e172..293cd6e91 100644 --- a/backend/src/schema/resolvers/rooms.ts +++ b/backend/src/schema/resolvers/rooms.ts @@ -32,6 +32,9 @@ export default { const { user: { id: currentUserId }, } = context + if (userId === currentUserId) { + throw new Error('Cannot create a room with yourself') + } const session = context.driver.session() const writeTxResultPromise = session.writeTransaction(async (transaction) => { const createRoomCypher = ` From dd4e6bf2dca0debe9457bdf674aab7292e7701e9 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 11 Jul 2023 12:13:46 +0200 Subject: [PATCH 2/3] fix open chat functionality after relog co-authored-by: Ogerly --- webapp/layouts/default.spec.js | 2 +- webapp/layouts/default.vue | 5 ++++- webapp/store/chat.js | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/webapp/layouts/default.spec.js b/webapp/layouts/default.spec.js index 1b83491d7..cce8c2eca 100644 --- a/webapp/layouts/default.spec.js +++ b/webapp/layouts/default.spec.js @@ -37,7 +37,7 @@ describe('default.vue', () => { getters: { 'auth/isLoggedIn': () => true, 'chat/showChat': () => { - return { showChat: false, roomID: 'u0' } + return { showChat: false, roomID: null } }, }, }) diff --git a/webapp/layouts/default.vue b/webapp/layouts/default.vue index 8b6b80604..f14c4055f 100644 --- a/webapp/layouts/default.vue +++ b/webapp/layouts/default.vue @@ -16,7 +16,7 @@
RoomID: {{ $store.getters['chat/showChat'].roomID }} - + x @@ -41,6 +41,9 @@ export default { ChatModule, }, mixins: [seo, mobile()], + beforeCreate() { + this.$store.commit('chat/SET_OPEN_CHAT', { showChat: false, roomID: null }) + }, } diff --git a/webapp/store/chat.js b/webapp/store/chat.js index 2ee8a47ad..be4ddaec0 100644 --- a/webapp/store/chat.js +++ b/webapp/store/chat.js @@ -1,14 +1,14 @@ export const state = () => { return { showChat: false, - roomID: 'u0', + roomID: null, } } export const mutations = { SET_OPEN_CHAT(state, ctx) { state.showChat = ctx.showChat || false - state.roomID = ctx.roomID || 'u0' + state.roomID = ctx.roomID || null }, } From a4bb523cb4d1e50abc1f3c528dc01460fabf3a7d Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 11 Jul 2023 12:57:37 +0200 Subject: [PATCH 3/3] unit test for error when creating room with self --- backend/src/schema/resolvers/rooms.spec.ts | 15 +++++++++++++++ backend/src/schema/resolvers/rooms.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/src/schema/resolvers/rooms.spec.ts b/backend/src/schema/resolvers/rooms.spec.ts index d27c64e57..03c3d4456 100644 --- a/backend/src/schema/resolvers/rooms.spec.ts +++ b/backend/src/schema/resolvers/rooms.spec.ts @@ -92,6 +92,21 @@ describe('Room', () => { }) }) + describe('user id is self', () => { + it('throws error', async () => { + await expect( + mutate({ + mutation: createRoomMutation(), + variables: { + userId: 'chatting-user', + }, + }), + ).resolves.toMatchObject({ + errors: [{ message: 'Cannot create a room with self' }], + }) + }) + }) + describe('user id exists', () => { it('returns the id of the room', async () => { const result = await mutate({ diff --git a/backend/src/schema/resolvers/rooms.ts b/backend/src/schema/resolvers/rooms.ts index 293cd6e91..d5015a03b 100644 --- a/backend/src/schema/resolvers/rooms.ts +++ b/backend/src/schema/resolvers/rooms.ts @@ -33,7 +33,7 @@ export default { user: { id: currentUserId }, } = context if (userId === currentUserId) { - throw new Error('Cannot create a room with yourself') + throw new Error('Cannot create a room with self') } const session = context.driver.session() const writeTxResultPromise = session.writeTransaction(async (transaction) => {