🐛 (collaboration) Fix a database rule preventing collaborators to edit a bot

Also check if new user has invitations when signup is disabled

Closes #265
This commit is contained in:
Baptiste Arnaud
2023-01-20 09:30:25 +01:00
parent 4435fb0d7e
commit fe2952d407
10 changed files with 209 additions and 108 deletions

View File

@@ -1,4 +1,4 @@
import { Plan, Prisma, User, WorkspaceRole } from 'db'
import { CollaborationType, Plan, Prisma, User, WorkspaceRole } from 'db'
import prisma from '@/lib/prisma'
import { NextApiResponse } from 'next'
import { env, isNotEmpty } from 'utils'
@@ -7,16 +7,26 @@ import { forbidden } from 'utils/api'
export const canWriteTypebots = (
typebotIds: string[] | string,
user: Pick<User, 'email' | 'id'>
): Prisma.TypebotWhereInput => ({
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
workspace: isNotEmpty(env('E2E_TEST'))
? undefined
): Prisma.TypebotWhereInput =>
isNotEmpty(env('E2E_TEST'))
? {}
: {
members: {
some: { userId: user.id, role: { not: WorkspaceRole.GUEST } },
},
},
})
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
OR: [
{
workspace: {
members: {
some: { userId: user.id, role: { not: WorkspaceRole.GUEST } },
},
},
},
{
collaborators: {
some: { userId: user.id, type: { not: CollaborationType.READ } },
},
},
],
}
export const canReadTypebots = (
typebotIds: string | string[],