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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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 } },
},
},
})