2
0

feat(editor): 🔒️ Add verification on backend for file input deployment

This commit is contained in:
Baptiste Arnaud
2022-06-13 08:21:48 +02:00
parent 910b871556
commit 14afd2249e
7 changed files with 112 additions and 17 deletions

View File

@ -1,5 +1,7 @@
import { CollaborationType, Prisma, User, WorkspaceRole } from 'db'
import { isNotEmpty } from 'utils'
import { CollaborationType, Plan, Prisma, User, WorkspaceRole } from 'db'
import prisma from 'libs/prisma'
import { NextApiResponse } from 'next'
import { forbidden, isNotEmpty } from 'utils'
const parseWhereFilter = (
typebotIds: string[] | string,
@ -51,3 +53,27 @@ export const canEditGuests = (user: User, typebotId: string) => ({
},
},
})
export const canPublishFileInput = async ({
userId,
workspaceId,
res,
}: {
userId: string
workspaceId: string
res: NextApiResponse
}) => {
const workspace = await prisma.workspace.findFirst({
where: { id: workspaceId, members: { some: { userId } } },
select: { plan: true },
})
if (!workspace) {
forbidden(res, 'workspace not found')
return false
}
if (workspace?.plan === Plan.FREE) {
forbidden(res, 'You need to upgrade your plan to use this feature')
return false
}
return true
}

View File

@ -37,19 +37,23 @@ export const parsePublicTypebotToTypebot = (
workspaceId: existingTypebot.workspaceId,
})
export const createPublishedTypebot = async (typebot: PublicTypebot) =>
export const createPublishedTypebot = async (
typebot: PublicTypebot,
workspaceId: string
) =>
sendRequest<PublicTypebot>({
url: `/api/publicTypebots`,
url: `/api/publicTypebots?workspaceId=${workspaceId}`,
method: 'POST',
body: typebot,
})
export const updatePublishedTypebot = async (
id: string,
typebot: Omit<PublicTypebot, 'id'>
typebot: Omit<PublicTypebot, 'id'>,
workspaceId: string
) =>
sendRequest({
url: `/api/publicTypebots/${id}`,
url: `/api/publicTypebots/${id}?workspaceId=${workspaceId}`,
method: 'PUT',
body: typebot,
})