-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️ (results) Improve result delete queries
- Loading branch information
1 parent
bac97a8
commit 1d4d39c
Showing
7 changed files
with
128 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import prisma from '@/lib/prisma' | ||
import { Prisma, User } from 'db' | ||
import { isReadTypebotForbidden } from './isReadTypebotForbidden' | ||
import { isWriteTypebotForbidden } from './isWriteTypebotForbidden' | ||
|
||
type Props<T extends Prisma.TypebotSelect> = { | ||
typebotId: string | ||
user: Pick<User, 'id' | 'email'> | ||
accessLevel: 'read' | 'write' | ||
select?: T | ||
} | ||
|
||
export const getTypebot = async <T extends Prisma.TypebotSelect>({ | ||
typebotId, | ||
user, | ||
accessLevel, | ||
select, | ||
}: Props<T>) => { | ||
const typebot = await prisma.typebot.findFirst({ | ||
where: { | ||
id: typebotId, | ||
}, | ||
select: { | ||
...select, | ||
workspaceId: true, | ||
collaborators: { select: { userId: true, type: true } }, | ||
}, | ||
}) | ||
if (!typebot) return null | ||
if (accessLevel === 'read' && (await isReadTypebotForbidden(typebot, user))) | ||
return null | ||
if (accessLevel === 'write' && (await isWriteTypebotForbidden(typebot, user))) | ||
return null | ||
return typebot | ||
} |
26 changes: 26 additions & 0 deletions
26
apps/builder/src/features/typebot/api/utils/isReadTypebotForbidden.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import prisma from '@/lib/prisma' | ||
import { CollaboratorsOnTypebots, User } from 'db' | ||
import { Typebot } from 'models' | ||
import { isNotDefined } from 'utils' | ||
|
||
export const isReadTypebotForbidden = async ( | ||
typebot: Pick<Typebot, 'workspaceId'> & { | ||
collaborators: Pick<CollaboratorsOnTypebots, 'userId' | 'type'>[] | ||
}, | ||
user: Pick<User, 'email' | 'id'> | ||
) => { | ||
if ( | ||
process.env.ADMIN_EMAIL === user.email || | ||
typebot.collaborators.find( | ||
(collaborator) => collaborator.userId === user.id | ||
) | ||
) | ||
return false | ||
const memberInWorkspace = await prisma.memberInWorkspace.findFirst({ | ||
where: { | ||
workspaceId: typebot.workspaceId, | ||
userId: user.id, | ||
}, | ||
}) | ||
return isNotDefined(memberInWorkspace) | ||
} |
26 changes: 26 additions & 0 deletions
26
apps/builder/src/features/typebot/api/utils/isWriteTypebotForbidden.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import prisma from '@/lib/prisma' | ||
import { CollaborationType, CollaboratorsOnTypebots, User } from 'db' | ||
import { Typebot } from 'models' | ||
import { isNotDefined } from 'utils' | ||
|
||
export const isWriteTypebotForbidden = async ( | ||
typebot: Pick<Typebot, 'workspaceId'> & { | ||
collaborators: Pick<CollaboratorsOnTypebots, 'userId' | 'type'>[] | ||
}, | ||
user: Pick<User, 'email' | 'id'> | ||
) => { | ||
if ( | ||
process.env.ADMIN_EMAIL === user.email || | ||
typebot.collaborators.find( | ||
(collaborator) => collaborator.userId === user.id | ||
)?.type === CollaborationType.WRITE | ||
) | ||
return false | ||
const memberInWorkspace = await prisma.memberInWorkspace.findFirst({ | ||
where: { | ||
workspaceId: typebot.workspaceId, | ||
userId: user.id, | ||
}, | ||
}) | ||
return isNotDefined(memberInWorkspace) || memberInWorkspace.role === 'GUEST' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1d4d39c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
builder-v2 – ./apps/builder
app.typebot.io
builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
1d4d39c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
landing-page-v2 – ./apps/landing-page
landing-page-v2-git-main-typebot-io.vercel.app
www.typebot.io
landing-page-v2-typebot-io.vercel.app
typebot.io
get-typebot.com
www.get-typebot.com
1d4d39c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viewer-v2 – ./apps/viewer
bot.winglabs.com.br
carsalesenquiry.com
chat.marius.digital
chatbot.matthesv.de
chatbot.repplai.com
demo.botscientis.us
demo.wemakebots.xyz
forms.webisharp.com
kbsub.wpwakanda.com
live.botscientis.us
mentoria.omelhor.vc
nutrisamirbayde.com
order.maitempah.com
help.comebackreward.com
link.venturasuceder.com
mainmenu.diddancing.com
manualhandlingcourse.ie
register.kandabrand.com
signup.hypemarketing.in
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
typebot.influencer.love
91181264.your-access.one
ai.chromebookstoreph.com
form.sergiolimajr.com.br
hunterbot.saleshunter.ai
invite.bridesquadapp.com
link.cascadigital.com.br
onboarding.growthside.io
reward.onlinebotdemo.xyz
stap.venturemarketing.in
type.opaulovieira.com.br
aibot.angrybranding.co.uk
bot.aidigitalmarketing.kr
bot.amicidisanfaustino.it
bot.arraesecenteno.com.br
bot.blackboxsports.com.br
bot.cabinrentalagency.com
bot.fusionstarreviews.com
boyfriend-breakup.riku.ai
brigadeirosemdrama.com.br
chat.ertcrebateportal.com
chat.thehomebuyersusa.com
chat.thisiscrushhouse.com
forms.hiabhaykulkarni.com
healthandsafetycourses.uk
sellmyharleylouisiana.com
testbot.sharemyreview.net
typebot-viewer.vercel.app
verfica.botmachine.com.br
bot.adventureconsulting.hu
casestudyemb.wpwakanda.com
chat.atlasoutfittersk9.com
configurator.bouclidom.com
help.atlasoutfittersk9.com
herbalife.barrettamario.it
homepageonly.wpwakanda.com
liveconvert.kandalearn.com
mainmenu1one.wpwakanda.com
tarian.theiofoundation.org
ted.meujalecobrasil.com.br
type.dericsoncalari.com.br
bot.pinpointinteractive.com
bot.polychromes-project.com
bot.seidinembroseanchetu.it
chatbot.berbelanjabiz.trade
designguide.techyscouts.com
liveconvert2.kandalearn.com
presente.empresarias.com.mx
sell.sellthemotorhome.co.uk
anamnese.odontopavani.com.br
austin.channelautomation.com
bot.marketingplusmindset.com
bot.seidibergamoseanchetu.it
desabafe.sergiolimajr.com.br
download.venturemarketing.in
piazzatorre.barrettamario.it
type.cookieacademyonline.com
bot.brigadeirosemdrama.com.br
forms.escoladeautomacao.com.br
onboarding.libertydreamcare.ie
type.talitasouzamarques.com.br
agendamento.sergiolimajr.com.br
anamnese.clinicamegasjdr.com.br
bookings.littlepartymonkeys.com
bot.comercializadoraomicron.com
elevateyourmind.groovepages.com
viewer-v2-typebot-io.vercel.app
yourfeedback.comebackreward.com
gerador.verificadordehospedes.com
personal-trainer.barrettamario.it
preagendamento.sergiolimajr.com.br
studiotecnicoimmobiliaremerelli.it
download.thailandmicespecialist.com
register.thailandmicespecialist.com
bot.studiotecnicoimmobiliaremerelli.it
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
viewer-v2-git-main-typebot-io.vercel.app
1d4d39c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./apps/docs
docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io