mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge pull request #6530 from Ocelot-Social-Community/fix-backend-room-with-self
fix(backend): chat - do not allow to create room with self
This commit is contained in:
commit
ab5b7a0b8a
@ -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', () => {
|
describe('user id exists', () => {
|
||||||
it('returns the id of the room', async () => {
|
it('returns the id of the room', async () => {
|
||||||
const result = await mutate({
|
const result = await mutate({
|
||||||
|
|||||||
@ -32,6 +32,9 @@ export default {
|
|||||||
const {
|
const {
|
||||||
user: { id: currentUserId },
|
user: { id: currentUserId },
|
||||||
} = context
|
} = context
|
||||||
|
if (userId === currentUserId) {
|
||||||
|
throw new Error('Cannot create a room with self')
|
||||||
|
}
|
||||||
const session = context.driver.session()
|
const session = context.driver.session()
|
||||||
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
const writeTxResultPromise = session.writeTransaction(async (transaction) => {
|
||||||
const createRoomCypher = `
|
const createRoomCypher = `
|
||||||
|
|||||||
@ -37,7 +37,7 @@ describe('default.vue', () => {
|
|||||||
getters: {
|
getters: {
|
||||||
'auth/isLoggedIn': () => true,
|
'auth/isLoggedIn': () => true,
|
||||||
'chat/showChat': () => {
|
'chat/showChat': () => {
|
||||||
return { showChat: false, roomID: 'u0' }
|
return { showChat: false, roomID: null }
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
<div v-if="$store.getters['chat/showChat'].showChat" class="chat-modul">
|
<div v-if="$store.getters['chat/showChat'].showChat" class="chat-modul">
|
||||||
<ds-text align="right" class="close">
|
<ds-text align="right" class="close">
|
||||||
RoomID: {{ $store.getters['chat/showChat'].roomID }}
|
RoomID: {{ $store.getters['chat/showChat'].roomID }}
|
||||||
<ds-button @click="$store.commit('chat/SET_OPEN_CHAT', { showChat: false, roomID: 'u0' })">
|
<ds-button @click="$store.commit('chat/SET_OPEN_CHAT', { showChat: false, roomID: null })">
|
||||||
x
|
x
|
||||||
</ds-button>
|
</ds-button>
|
||||||
</ds-text>
|
</ds-text>
|
||||||
@ -41,6 +41,9 @@ export default {
|
|||||||
ChatModule,
|
ChatModule,
|
||||||
},
|
},
|
||||||
mixins: [seo, mobile()],
|
mixins: [seo, mobile()],
|
||||||
|
beforeCreate() {
|
||||||
|
this.$store.commit('chat/SET_OPEN_CHAT', { showChat: false, roomID: null })
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
export const state = () => {
|
export const state = () => {
|
||||||
return {
|
return {
|
||||||
showChat: false,
|
showChat: false,
|
||||||
roomID: 'u0',
|
roomID: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
SET_OPEN_CHAT(state, ctx) {
|
SET_OPEN_CHAT(state, ctx) {
|
||||||
state.showChat = ctx.showChat || false
|
state.showChat = ctx.showChat || false
|
||||||
state.roomID = ctx.roomID || 'u0'
|
state.roomID = ctx.roomID || null
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user