fix(collab): 🛂 Hide folders for guests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { withSentry } from '@sentry/nextjs'
|
import { withSentry } from '@sentry/nextjs'
|
||||||
import { DashboardFolder } from 'db'
|
import { DashboardFolder, WorkspaceRole } from 'db'
|
||||||
import prisma from 'libs/prisma'
|
import prisma from 'libs/prisma'
|
||||||
import { NextApiRequest, NextApiResponse } from 'next'
|
import { NextApiRequest, NextApiResponse } from 'next'
|
||||||
import { getAuthenticatedUser } from 'services/api/utils'
|
import { getAuthenticatedUser } from 'services/api/utils'
|
||||||
@@ -18,8 +18,37 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
if (!workspaceId) return badRequest(res)
|
if (!workspaceId) return badRequest(res)
|
||||||
const folders = await prisma.dashboardFolder.findMany({
|
const folders = await prisma.dashboardFolder.findMany({
|
||||||
where: {
|
where: {
|
||||||
parentFolderId,
|
AND: [
|
||||||
workspace: { members: { some: { userId: user.id, workspaceId } } },
|
{
|
||||||
|
parentFolderId,
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
OR: [
|
||||||
|
{
|
||||||
|
workspace: {
|
||||||
|
members: {
|
||||||
|
some: {
|
||||||
|
userId: user.id,
|
||||||
|
role: { not: WorkspaceRole.GUEST },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
typebots: {
|
||||||
|
some: {
|
||||||
|
collaborators: {
|
||||||
|
some: {
|
||||||
|
userId: user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -255,6 +255,14 @@ const createAnswers = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const createFolder = (workspaceId: string, name: string) =>
|
||||||
|
prisma.dashboardFolder.create({
|
||||||
|
data: {
|
||||||
|
workspaceId,
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const parseTypebotToPublicTypebot = (
|
const parseTypebotToPublicTypebot = (
|
||||||
id: string,
|
id: string,
|
||||||
typebot: Typebot
|
typebot: Typebot
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { CollaborationType, Plan, WorkspaceRole } from 'db'
|
|||||||
import prisma from 'libs/prisma'
|
import prisma from 'libs/prisma'
|
||||||
import { InputBlockType, defaultTextInputOptions } from 'models'
|
import { InputBlockType, defaultTextInputOptions } from 'models'
|
||||||
import {
|
import {
|
||||||
|
createFolder,
|
||||||
createResults,
|
createResults,
|
||||||
createTypebots,
|
createTypebots,
|
||||||
parseDefaultGroupWithBlock,
|
parseDefaultGroupWithBlock,
|
||||||
@@ -96,10 +97,13 @@ test.describe('Collaborator', () => {
|
|||||||
type: CollaborationType.READ,
|
type: CollaborationType.READ,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
await createFolder(guestWorkspaceId, 'Guest folder')
|
||||||
await createResults({ typebotId })
|
await createResults({ typebotId })
|
||||||
await page.goto(`/typebots`)
|
await page.goto(`/typebots`)
|
||||||
await page.click("text=Pro user's workspace")
|
await page.click("text=Pro user's workspace")
|
||||||
await page.click('text=Guest workspace #2')
|
await page.click('text=Guest workspace #2')
|
||||||
|
await expect(page.locator('text=Guest typebot')).toBeVisible()
|
||||||
|
await expect(page.locator('text=Guest folder')).toBeHidden()
|
||||||
await page.click('text=Guest typebot')
|
await page.click('text=Guest typebot')
|
||||||
await page.click('button[aria-label="Show collaboration menu"]')
|
await page.click('button[aria-label="Show collaboration menu"]')
|
||||||
await page.click('text=Everyone at Guest workspace')
|
await page.click('text=Everyone at Guest workspace')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { CollaborationType, PrismaClient } from 'db'
|
import { PrismaClient } from 'db'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
const prisma = new PrismaClient({
|
const prisma = new PrismaClient({
|
||||||
log: [
|
log: [
|
||||||
@@ -34,9 +34,6 @@ const main = async () => {
|
|||||||
console.log('Params: ' + e.params)
|
console.log('Params: ' + e.params)
|
||||||
console.log('Duration: ' + e.duration + 'ms')
|
console.log('Duration: ' + e.duration + 'ms')
|
||||||
})
|
})
|
||||||
const results =
|
|
||||||
await prisma.$queryRaw`DELETE FROM "public"."Result" WHERE "public"."Result"."typebotId"='ckzqqer3j002509l3np5x3v2y'`
|
|
||||||
console.log(results)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main().then()
|
main().then()
|
||||||
|
|||||||
Reference in New Issue
Block a user