2
0

chore: 🔥 Remove ownerIds

This commit is contained in:
Baptiste Arnaud
2022-05-14 16:52:05 -07:00
parent 210bad32f9
commit bda4116fbc
47 changed files with 81 additions and 81 deletions

View File

@ -1,4 +1,4 @@
import { CollaborationType, Prisma, User } from 'db'
import { CollaborationType, Prisma, User, WorkspaceRole } from 'db'
const parseWhereFilter = (
typebotIds: string[] | string,
@ -6,14 +6,6 @@ const parseWhereFilter = (
type: 'read' | 'write'
): Prisma.TypebotWhereInput => ({
OR: [
{
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
ownerId:
(type === 'read' && user.email === process.env.ADMIN_EMAIL) ||
process.env.NEXT_PUBLIC_E2E_TEST
? undefined
: user.id,
},
{
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
collaborators: {
@ -23,6 +15,18 @@ const parseWhereFilter = (
},
},
},
{
id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
workspace:
(type === 'read' && user.email === process.env.ADMIN_EMAIL) ||
process.env.NEXT_PUBLIC_E2E_TEST
? undefined
: {
members: {
some: { userId: user.id, role: { not: WorkspaceRole.GUEST } },
},
},
},
],
})
@ -37,3 +41,12 @@ export const canReadTypebots = (typebotIds: string[], user: User) =>
export const canWriteTypebots = (typebotIds: string[], user: User) =>
parseWhereFilter(typebotIds, user, 'write')
export const canEditGuests = (user: User, typebotId: string) => ({
id: typebotId,
workspace: {
members: {
some: { userId: user.id, role: { not: WorkspaceRole.GUEST } },
},
},
})