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

@@ -21,8 +21,8 @@ import { Typebot } from 'models'
import { useTypebotDnd } from 'contexts/TypebotDndContext' import { useTypebotDnd } from 'contexts/TypebotDndContext'
import { useDebounce } from 'use-debounce' import { useDebounce } from 'use-debounce'
import { EmojiOrImageIcon } from 'components/shared/EmojiOrImageIcon' import { EmojiOrImageIcon } from 'components/shared/EmojiOrImageIcon'
import { useUser } from 'contexts/UserContext'
import { Plan } from 'db' import { Plan } from 'db'
import { useWorkspace } from 'contexts/WorkspaceContext'
type ChatbotCardProps = { type ChatbotCardProps = {
typebot: Pick<Typebot, 'id' | 'publishedTypebotId' | 'name' | 'icon'> typebot: Pick<Typebot, 'id' | 'publishedTypebotId' | 'name' | 'icon'>
@@ -38,7 +38,7 @@ export const TypebotButton = ({
onMouseDown, onMouseDown,
}: ChatbotCardProps) => { }: ChatbotCardProps) => {
const router = useRouter() const router = useRouter()
const { user } = useUser() const { workspace } = useWorkspace()
const { draggedTypebot } = useTypebotDnd() const { draggedTypebot } = useTypebotDnd()
const [draggedTypebotDebounced] = useDebounce(draggedTypebot, 200) const [draggedTypebotDebounced] = useDebounce(draggedTypebot, 200)
const { const {
@@ -79,7 +79,7 @@ export const TypebotButton = ({
if (!typebotToDuplicate) return { error: new Error('Typebot not found') } if (!typebotToDuplicate) return { error: new Error('Typebot not found') }
const { data: createdTypebot, error } = await importTypebot( const { data: createdTypebot, error } = await importTypebot(
data.typebot, data.typebot,
user?.plan ?? Plan.FREE workspace?.plan ?? Plan.FREE
) )
if (error) if (error)
return toast({ return toast({

View File

@@ -12,7 +12,6 @@ import {
import { TrashIcon } from 'assets/icons' import { TrashIcon } from 'assets/icons'
import { UpgradeButton } from 'components/shared/buttons/UpgradeButton' import { UpgradeButton } from 'components/shared/buttons/UpgradeButton'
import { useTypebot } from 'contexts/TypebotContext/TypebotContext' import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
import { useUser } from 'contexts/UserContext'
import { useWorkspace } from 'contexts/WorkspaceContext' import { useWorkspace } from 'contexts/WorkspaceContext'
import React from 'react' import React from 'react'
import { parseDefaultPublicId } from 'services/typebots' import { parseDefaultPublicId } from 'services/typebots'

View File

@@ -13,7 +13,6 @@ import {
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { ChevronLeftIcon, PlusIcon, TrashIcon } from 'assets/icons' import { ChevronLeftIcon, PlusIcon, TrashIcon } from 'assets/icons'
import React, { useState } from 'react' import React, { useState } from 'react'
import { useUser } from 'contexts/UserContext'
import { CustomDomainModal } from './CustomDomainModal' import { CustomDomainModal } from './CustomDomainModal'
import { deleteCustomDomain, useCustomDomains } from 'services/user' import { deleteCustomDomain, useCustomDomains } from 'services/user'
import { useWorkspace } from 'contexts/WorkspaceContext' import { useWorkspace } from 'contexts/WorkspaceContext'

View File

@@ -1,7 +1,6 @@
import { useTypebot } from 'contexts/TypebotContext' import { useTypebot } from 'contexts/TypebotContext'
import { useUser } from 'contexts/UserContext' import { useUser } from 'contexts/UserContext'
import { useWorkspace } from 'contexts/WorkspaceContext' import { useWorkspace } from 'contexts/WorkspaceContext'
import { Plan } from 'db'
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import { isCloudProdInstance } from 'services/utils' import { isCloudProdInstance } from 'services/utils'
import { planToReadable } from 'services/workspace' import { planToReadable } from 'services/workspace'

View File

@@ -40,7 +40,6 @@ export const CreateNewTypebotButtons = () => {
...typebot, ...typebot,
folderId, folderId,
workspaceId: workspace.id, workspaceId: workspace.id,
ownerId: user.id,
theme: { theme: {
...typebot.theme, ...typebot.theme,
chat: { chat: {

View File

@@ -34,7 +34,6 @@ export function CustomAdapter(p: PrismaClient): Adapter {
...data, ...data,
id: user.id, id: user.id,
apiToken: randomUUID(), apiToken: randomUUID(),
plan: process.env.ADMIN_EMAIL === data.email ? Plan.PRO : Plan.FREE,
workspaces: workspaces:
workspaceInvitations.length > 0 workspaceInvitations.length > 0
? undefined ? undefined

View File

@@ -81,7 +81,6 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
'blocks' in data 'blocks' in data
? data ? data
: (parseNewTypebot({ : (parseNewTypebot({
ownerId: user.id,
ownerAvatarUrl: user.image, ownerAvatarUrl: user.image,
...data, ...data,
}) as Prisma.TypebotUncheckedCreateInput), }) as Prisma.TypebotUncheckedCreateInput),

View File

@@ -24,7 +24,7 @@ const DashboardPage = () => {
useEffect(() => { useEffect(() => {
const subscribePlan = query.subscribePlan as 'pro' | 'team' | undefined const subscribePlan = query.subscribePlan as 'pro' | 'team' | undefined
if (workspace && subscribePlan && user && user.plan === 'FREE') { if (workspace && subscribePlan && user && workspace.plan === 'FREE') {
setIsLoading(true) setIsLoading(true)
pay({ pay({
user, user,

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T08:16:59.215Z", "createdAt": "2022-02-04T08:16:59.215Z",
"updatedAt": "2022-02-04T08:16:59.215Z", "updatedAt": "2022-02-04T08:16:59.215Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-21T15:01:46.107Z", "createdAt": "2022-03-21T15:01:46.107Z",
"updatedAt": "2022-03-21T15:03:07.312Z", "updatedAt": "2022-03-21T15:03:07.312Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "cl10hgjy90000lm1a1gyccuqj",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T13:40:19.455Z", "createdAt": "2022-02-04T13:40:19.455Z",
"updatedAt": "2022-02-04T13:40:19.455Z", "updatedAt": "2022-02-04T13:40:19.455Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T13:40:19.455Z", "createdAt": "2022-02-04T13:40:19.455Z",
"updatedAt": "2022-02-04T13:40:19.455Z", "updatedAt": "2022-02-04T13:40:19.455Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-07T10:06:35.274Z", "createdAt": "2022-02-07T10:06:35.274Z",
"updatedAt": "2022-02-07T10:06:35.274Z", "updatedAt": "2022-02-07T10:06:35.274Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T13:44:30.386Z", "createdAt": "2022-02-04T13:44:30.386Z",
"updatedAt": "2022-02-04T13:44:30.386Z", "updatedAt": "2022-02-04T13:44:30.386Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T14:14:21.394Z", "createdAt": "2022-02-04T14:14:21.394Z",
"updatedAt": "2022-02-04T14:14:21.394Z", "updatedAt": "2022-02-04T14:14:21.394Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T13:47:42.459Z", "createdAt": "2022-02-04T13:47:42.459Z",
"updatedAt": "2022-02-04T13:47:42.459Z", "updatedAt": "2022-02-04T13:47:42.459Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-09T07:01:25.917Z", "createdAt": "2022-03-09T07:01:25.917Z",
"updatedAt": "2022-03-09T07:01:25.917Z", "updatedAt": "2022-03-09T07:01:25.917Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "cl0cfi60r0000381a2bft9yis",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-08T17:18:50.337Z", "createdAt": "2022-03-08T17:18:50.337Z",
"updatedAt": "2022-03-08T21:05:28.825Z", "updatedAt": "2022-03-08T21:05:28.825Z",
"name": "Another typebot", "name": "Another typebot",
"ownerId": "cl0cfi60r0000381a2bft9yis",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T14:14:21.394Z", "createdAt": "2022-02-04T14:14:21.394Z",
"updatedAt": "2022-02-04T14:14:21.394Z", "updatedAt": "2022-02-04T14:14:21.394Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T14:15:06.953Z", "createdAt": "2022-02-04T14:15:06.953Z",
"updatedAt": "2022-02-04T14:15:06.953Z", "updatedAt": "2022-02-04T14:15:06.953Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-05T06:21:16.522Z", "createdAt": "2022-02-05T06:21:16.522Z",
"updatedAt": "2022-02-05T06:21:16.522Z", "updatedAt": "2022-02-05T06:21:16.522Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckzmhmiey001009mnzt5nkxu8",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-10T10:50:23.912Z", "createdAt": "2022-03-10T10:50:23.912Z",
"updatedAt": "2022-03-10T10:50:23.912Z", "updatedAt": "2022-03-10T10:50:23.912Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "cl0cfi60r0000381a2bft9yis",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T14:17:20.022Z", "createdAt": "2022-02-04T14:17:20.022Z",
"updatedAt": "2022-02-04T14:17:20.022Z", "updatedAt": "2022-02-04T14:17:20.022Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-04T14:19:29.412Z", "createdAt": "2022-02-04T14:19:29.412Z",
"updatedAt": "2022-02-04T14:19:29.412Z", "updatedAt": "2022-02-04T14:19:29.412Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -249,7 +249,6 @@ const parseTypebotToPublicTypebot = (
const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({ const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
id: partialTypebot.id ?? 'typebot', id: partialTypebot.id ?? 'typebot',
ownerId: 'proUser',
workspaceId: proWorkspaceId, workspaceId: proWorkspaceId,
folderId: null, folderId: null,
name: 'My typebot', name: 'My typebot',
@@ -312,10 +311,9 @@ export const importTypebotInDatabase = async (
path: string, path: string,
updates?: Partial<Typebot> updates?: Partial<Typebot>
) => { ) => {
const typebot: any = { const typebot: Typebot = {
...JSON.parse(readFileSync(path).toString()), ...JSON.parse(readFileSync(path).toString()),
workspaceId: proWorkspaceId, workspaceId: proWorkspaceId,
ownerId: 'proUser',
...updates, ...updates,
} }
await prisma.typebot.create({ await prisma.typebot.create({

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-22T14:33:05.037Z", "createdAt": "2022-03-22T14:33:05.037Z",
"updatedAt": "2022-03-22T16:33:37.928Z", "updatedAt": "2022-03-22T16:33:37.928Z",
"name": "Onboarding", "name": "Onboarding",
"ownerId": "ckzmhmiey001009mnzt5nkxu8",
"publishedTypebotId": "cl128n64i00092e69wenv1dlx", "publishedTypebotId": "cl128n64i00092e69wenv1dlx",
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -4,7 +4,6 @@
"updatedAt": "2022-03-25T15:42:12.544Z", "updatedAt": "2022-03-25T15:42:12.544Z",
"name": "Customer Support", "name": "Customer Support",
"icon": "😍", "icon": "😍",
"ownerId": "cl13od3wt0000pl1aat7bdrxf",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -4,7 +4,6 @@
"updatedAt": "2022-02-05T06:21:16.522Z", "updatedAt": "2022-02-05T06:21:16.522Z",
"name": "Lead Generation", "name": "Lead Generation",
"icon": "🤝", "icon": "🤝",
"ownerId": "ckz6t9iep0006k31a22j05fwq",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -4,7 +4,6 @@
"updatedAt": "2022-04-09T22:35:22.449Z", "updatedAt": "2022-04-09T22:35:22.449Z",
"icon": "🏆", "icon": "🏆",
"name": "Lead Scoring", "name": "Lead Scoring",
"ownerId": "cl1qykt2w00007w1agho81e26",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -4,7 +4,6 @@
"updatedAt": "2022-04-08T23:03:34.726Z", "updatedAt": "2022-04-08T23:03:34.726Z",
"icon": "🕹️", "icon": "🕹️",
"name": "Digital Marketing Quiz", "name": "Digital Marketing Quiz",
"ownerId": "cl1qykt2w00007w1agho81e26",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -24,7 +24,7 @@ export const useCredentials = ({
} }
export const createCredentials = async ( export const createCredentials = async (
credentials: Omit<Credentials, 'id' | 'iv' | 'createdAt' | 'ownerId'> credentials: Omit<Credentials, 'id' | 'iv' | 'createdAt'>
) => ) =>
sendRequest<{ sendRequest<{
credentials: Credentials credentials: Credentials

View File

@@ -13,7 +13,7 @@ export const useCustomDomains = ({
onError: (error: Error) => void onError: (error: Error) => void
}) => { }) => {
const { data, error, mutate } = useSWR< const { data, error, mutate } = useSWR<
{ customDomains: Omit<CustomDomain, 'createdAt' | 'ownerId'>[] }, { customDomains: Omit<CustomDomain, 'createdAt'>[] },
Error Error
>( >(
workspaceId ? `/api/customDomains?${stringify({ workspaceId })}` : null, workspaceId ? `/api/customDomains?${stringify({ workspaceId })}` : null,
@@ -29,7 +29,7 @@ export const useCustomDomains = ({
export const createCustomDomain = async ( export const createCustomDomain = async (
workspaceId: string, workspaceId: string,
customDomain: Omit<CustomDomain, 'createdAt' | 'workspaceId' | 'ownerId'> customDomain: Omit<CustomDomain, 'createdAt' | 'workspaceId'>
) => ) =>
sendRequest<{ sendRequest<{
credentials: Credentials credentials: Credentials

View File

@@ -36,7 +36,6 @@ export const parsePublicTypebotToTypebot = (
updatedAt: existingTypebot.updatedAt, updatedAt: existingTypebot.updatedAt,
publishedTypebotId: typebot.id, publishedTypebotId: typebot.id,
folderId: existingTypebot.folderId, folderId: existingTypebot.folderId,
ownerId: existingTypebot.ownerId,
icon: existingTypebot.icon, icon: existingTypebot.icon,
workspaceId: existingTypebot.workspaceId, workspaceId: existingTypebot.workspaceId,
}) })

View File

@@ -418,7 +418,6 @@ export const parseNewTypebot = ({
steps: [startStep], steps: [startStep],
} }
return { return {
ownerId: null,
folderId, folderId,
name, name,
workspaceId, workspaceId,

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-15T12:54:54.778Z", "createdAt": "2022-03-15T12:54:54.778Z",
"updatedAt": "2022-03-15T13:13:54.482Z", "updatedAt": "2022-03-15T13:13:54.482Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckzmhmiey001009mnzt5nkxu8",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-15T15:41:00.241Z", "createdAt": "2022-03-15T15:41:00.241Z",
"updatedAt": "2022-03-15T17:32:29.840Z", "updatedAt": "2022-03-15T17:32:29.840Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckzmhmiey001009mnzt5nkxu8",
"publishedTypebotId": "pioizXgk6U9Xtz1BdyjPFy", "publishedTypebotId": "pioizXgk6U9Xtz1BdyjPFy",
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-02-05T06:21:16.522Z", "createdAt": "2022-02-05T06:21:16.522Z",
"updatedAt": "2022-02-05T06:21:16.522Z", "updatedAt": "2022-02-05T06:21:16.522Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "ckzwaq0p000149f1a2ejh3qm0",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-09T16:17:51.321Z", "createdAt": "2022-03-09T16:17:51.321Z",
"updatedAt": "2022-03-09T16:19:07.037Z", "updatedAt": "2022-03-09T16:19:07.037Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "cl0cfi60r0000381a2bft9yis",
"publishedTypebotId": "dm12bh6hmEQemywn86osJD", "publishedTypebotId": "dm12bh6hmEQemywn86osJD",
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-08T15:58:49.720Z", "createdAt": "2022-03-08T15:58:49.720Z",
"updatedAt": "2022-03-08T16:07:18.899Z", "updatedAt": "2022-03-08T16:07:18.899Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "cl0cfi60r0000381a2bft9yis",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-08T15:59:06.589Z", "createdAt": "2022-03-08T15:59:06.589Z",
"updatedAt": "2022-03-08T15:59:10.498Z", "updatedAt": "2022-03-08T15:59:10.498Z",
"name": "Another typebot", "name": "Another typebot",
"ownerId": "cl0cfi60r0000381a2bft9yis",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -3,7 +3,6 @@
"createdAt": "2022-03-23T08:41:30.106Z", "createdAt": "2022-03-23T08:41:30.106Z",
"updatedAt": "2022-03-23T08:41:30.106Z", "updatedAt": "2022-03-23T08:41:30.106Z",
"name": "My typebot", "name": "My typebot",
"ownerId": "cl139ni700000481a01gxhw4z",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -4,7 +4,6 @@
"updatedAt": "2022-04-12T14:34:44.287Z", "updatedAt": "2022-04-12T14:34:44.287Z",
"icon": null, "icon": null,
"name": "My typebot", "name": "My typebot",
"ownerId": "ckzmhmiey001009mnzt5nkxu8",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -4,7 +4,6 @@
"updatedAt": "2022-04-19T20:40:48.366Z", "updatedAt": "2022-04-19T20:40:48.366Z",
"icon": null, "icon": null,
"name": "My typebot", "name": "My typebot",
"ownerId": "proUser",
"publishedTypebotId": null, "publishedTypebotId": null,
"folderId": null, "folderId": null,
"blocks": [ "blocks": [

View File

@@ -109,7 +109,6 @@ const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
id: partialTypebot.id ?? 'typebot', id: partialTypebot.id ?? 'typebot',
folderId: null, folderId: null,
name: 'My typebot', name: 'My typebot',
ownerId: 'proUser',
workspaceId: proWorkspaceId, workspaceId: proWorkspaceId,
icon: null, icon: null,
theme: defaultTheme, theme: defaultTheme,
@@ -170,11 +169,10 @@ export const importTypebotInDatabase = async (
path: string, path: string,
updates?: Partial<Typebot> updates?: Partial<Typebot>
) => { ) => {
const typebot: any = { const typebot: Typebot = {
...JSON.parse(readFileSync(path).toString()), ...JSON.parse(readFileSync(path).toString()),
...updates, ...updates,
workspaceId: proWorkspaceId, workspaceId: proWorkspaceId,
ownerId: 'proUser',
} }
await prisma.typebot.create({ await prisma.typebot.create({
data: typebot, data: typebot,
@@ -233,7 +231,6 @@ export const createSmtpCredentials = (
iv, iv,
name: smtpData.from.email as string, name: smtpData.from.email as string,
type: CredentialsType.SMTP, type: CredentialsType.SMTP,
ownerId: 'proUser',
workspaceId: proWorkspaceId, workspaceId: proWorkspaceId,
}, },
}) })

View File

@@ -1,4 +1,4 @@
import { CollaborationType, Prisma, User } from 'db' import { CollaborationType, Prisma, User, WorkspaceRole } from 'db'
const parseWhereFilter = ( const parseWhereFilter = (
typebotIds: string[] | string, typebotIds: string[] | string,
@@ -6,14 +6,6 @@ const parseWhereFilter = (
type: 'read' | 'write' type: 'read' | 'write'
): Prisma.TypebotWhereInput => ({ ): Prisma.TypebotWhereInput => ({
OR: [ 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 }, id: typeof typebotIds === 'string' ? typebotIds : { in: typebotIds },
collaborators: { 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) => export const canWriteTypebots = (typebotIds: string[], user: User) =>
parseWhereFilter(typebotIds, user, 'write') parseWhereFilter(typebotIds, user, 'write')
export const canEditGuests = (user: User, typebotId: string) => ({
id: typebotId,
workspace: {
members: {
some: { userId: user.id, role: { not: WorkspaceRole.GUEST } },
},
},
})

View File

@@ -0,0 +1,50 @@
/*
Warnings:
- You are about to drop the column `ownerId` on the `Credentials` table. All the data in the column will be lost.
- You are about to drop the column `ownerId` on the `CustomDomain` table. All the data in the column will be lost.
- You are about to drop the column `ownerId` on the `DashboardFolder` table. All the data in the column will be lost.
- You are about to drop the column `ownerId` on the `Typebot` table. All the data in the column will be lost.
- You are about to drop the column `plan` on the `User` table. All the data in the column will be lost.
- You are about to drop the column `stripeId` on the `User` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "Credentials" DROP CONSTRAINT "Credentials_ownerId_fkey";
-- DropForeignKey
ALTER TABLE "CustomDomain" DROP CONSTRAINT "CustomDomain_ownerId_fkey";
-- DropForeignKey
ALTER TABLE "DashboardFolder" DROP CONSTRAINT "DashboardFolder_ownerId_fkey";
-- DropForeignKey
ALTER TABLE "Typebot" DROP CONSTRAINT "Typebot_ownerId_fkey";
-- DropIndex
DROP INDEX "Credentials_name_type_ownerId_key";
-- DropIndex
DROP INDEX "DashboardFolder_id_ownerId_key";
-- DropIndex
DROP INDEX "Typebot_id_ownerId_key";
-- DropIndex
DROP INDEX "User_stripeId_key";
-- AlterTable
ALTER TABLE "Credentials" DROP COLUMN "ownerId";
-- AlterTable
ALTER TABLE "CustomDomain" DROP COLUMN "ownerId";
-- AlterTable
ALTER TABLE "DashboardFolder" DROP COLUMN "ownerId";
-- AlterTable
ALTER TABLE "Typebot" DROP COLUMN "ownerId";
-- AlterTable
ALTER TABLE "User" DROP COLUMN "plan",
DROP COLUMN "stripeId";

View File

@@ -48,12 +48,6 @@ model User {
image String? image String?
accounts Account[] accounts Account[]
sessions Session[] sessions Session[]
typebots Typebot[]
folders DashboardFolder[]
plan Plan? @default(FREE)
stripeId String? @unique
credentials Credentials[]
customDomains CustomDomain[]
apiToken String? apiToken String?
CollaboratorsOnTypebots CollaboratorsOnTypebots[] CollaboratorsOnTypebots CollaboratorsOnTypebots[]
company String? company String?
@@ -110,8 +104,6 @@ enum GraphNavigation {
model CustomDomain { model CustomDomain {
name String @id name String @id
createdAt DateTime @default(now()) createdAt DateTime @default(now())
ownerId String?
owner User? @relation(fields: [ownerId], references: [id], onDelete: Cascade)
workspaceId String? workspaceId String?
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade) workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
} }
@@ -119,16 +111,12 @@ model CustomDomain {
model Credentials { model Credentials {
id String @id @default(cuid()) id String @id @default(cuid())
createdAt DateTime @default(now()) createdAt DateTime @default(now())
ownerId String?
owner User? @relation(fields: [ownerId], references: [id], onDelete: Cascade)
workspaceId String? workspaceId String?
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade) workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
data String // Encrypted data data String // Encrypted data
name String name String
type String type String
iv String iv String
@@unique([name, type, ownerId])
} }
enum Plan { enum Plan {
@@ -152,16 +140,12 @@ model DashboardFolder {
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt updatedAt DateTime @default(now()) @updatedAt
name String name String
owner User? @relation(fields: [ownerId], references: [id], onDelete: Cascade)
ownerId String?
parentFolderId String? parentFolderId String?
parentFolder DashboardFolder? @relation("ParentChild", fields: [parentFolderId], references: [id]) parentFolder DashboardFolder? @relation("ParentChild", fields: [parentFolderId], references: [id])
childrenFolder DashboardFolder[] @relation("ParentChild") childrenFolder DashboardFolder[] @relation("ParentChild")
typebots Typebot[] typebots Typebot[]
workspaceId String? workspaceId String?
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade) workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
@@unique([id, ownerId])
} }
model Typebot { model Typebot {
@@ -170,8 +154,6 @@ model Typebot {
updatedAt DateTime @default(now()) @updatedAt updatedAt DateTime @default(now()) @updatedAt
icon String? icon String?
name String name String
ownerId String?
owner User? @relation(fields: [ownerId], references: [id], onDelete: Cascade)
publishedTypebotId String? publishedTypebotId String?
publishedTypebot PublicTypebot? publishedTypebot PublicTypebot?
results Result[] results Result[]
@@ -189,8 +171,6 @@ model Typebot {
webhooks Webhook[] webhooks Webhook[]
workspaceId String? workspaceId String?
workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade) workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
@@unique([id, ownerId])
} }
model Invitation { model Invitation {