-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🛂 (billing) Add isPastDue field in workspace #1046
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,18 @@ export const unpublishTypebot = authenticatedProcedure | |
include: { | ||
collaborators: true, | ||
publishedTypebot: true, | ||
workspace: { | ||
select: { | ||
isQuarantined: true, | ||
isPastDue: true, | ||
members: { | ||
select: { | ||
userId: true, | ||
role: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Comment on lines
32
to
47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
}) | ||
if (!existingTypebot?.publishedTypebot) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,7 +79,6 @@ export const updateTypebot = authenticatedProcedure | |||||||||||||||||||||||||||||||
id: true, | ||||||||||||||||||||||||||||||||
customDomain: true, | ||||||||||||||||||||||||||||||||
publicId: true, | ||||||||||||||||||||||||||||||||
workspaceId: true, | ||||||||||||||||||||||||||||||||
collaborators: { | ||||||||||||||||||||||||||||||||
select: { | ||||||||||||||||||||||||||||||||
userId: true, | ||||||||||||||||||||||||||||||||
Comment on lines
79
to
84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous comment about the missing closing bracket for the - type: true,
+ type: true
+ } Commitable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
|
@@ -88,7 +87,16 @@ export const updateTypebot = authenticatedProcedure | |||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
workspace: { | ||||||||||||||||||||||||||||||||
select: { | ||||||||||||||||||||||||||||||||
id: true, | ||||||||||||||||||||||||||||||||
plan: true, | ||||||||||||||||||||||||||||||||
isQuarantined: true, | ||||||||||||||||||||||||||||||||
isPastDue: true, | ||||||||||||||||||||||||||||||||
members: { | ||||||||||||||||||||||||||||||||
select: { | ||||||||||||||||||||||||||||||||
userId: true, | ||||||||||||||||||||||||||||||||
role: true, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||
updatedAt: true, | ||||||||||||||||||||||||||||||||
|
@@ -160,7 +168,7 @@ export const updateTypebot = authenticatedProcedure | |||||||||||||||||||||||||||||||
selectedThemeTemplateId: typebot.selectedThemeTemplateId, | ||||||||||||||||||||||||||||||||
events: typebot.events ?? undefined, | ||||||||||||||||||||||||||||||||
groups: typebot.groups | ||||||||||||||||||||||||||||||||
? await sanitizeGroups(existingTypebot.workspaceId)(typebot.groups) | ||||||||||||||||||||||||||||||||
? await sanitizeGroups(existingTypebot.workspace.id)(typebot.groups) | ||||||||||||||||||||||||||||||||
: undefined, | ||||||||||||||||||||||||||||||||
theme: typebot.theme ? typebot.theme : undefined, | ||||||||||||||||||||||||||||||||
settings: typebot.settings | ||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
import prisma from '@typebot.io/lib/prisma' | ||
import { env } from '@typebot.io/env' | ||
import { CollaboratorsOnTypebots, User } from '@typebot.io/prisma' | ||
import { Typebot } from '@typebot.io/schemas' | ||
import { | ||
CollaboratorsOnTypebots, | ||
User, | ||
Workspace, | ||
MemberInWorkspace, | ||
} from '@typebot.io/prisma' | ||
|
||
export const isReadTypebotForbidden = async ( | ||
typebot: Pick<Typebot, 'workspaceId'> & { | ||
typebot: { | ||
collaborators: Pick<CollaboratorsOnTypebots, 'userId'>[] | ||
} & { | ||
workspace: Pick<Workspace, 'isQuarantined' | 'isPastDue'> & { | ||
members: Pick<MemberInWorkspace, 'userId'>[] | ||
} | ||
}, | ||
user: Pick<User, 'email' | 'id'> | ||
) => { | ||
if ( | ||
env.ADMIN_EMAIL === user.email || | ||
typebot.collaborators.find( | ||
) => | ||
typebot.workspace.isQuarantined || | ||
typebot.workspace.isPastDue || | ||
(env.ADMIN_EMAIL !== user.email && | ||
!typebot.collaborators.some( | ||
(collaborator) => collaborator.userId === user.id | ||
) | ||
) | ||
return false | ||
const memberInWorkspace = await prisma.memberInWorkspace.findFirst({ | ||
where: { | ||
workspaceId: typebot.workspaceId, | ||
userId: user.id, | ||
}, | ||
}) | ||
return memberInWorkspace === null | ||
} | ||
) && | ||
!typebot.workspace.members.some((member) => member.userId === user.id)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
import prisma from '@typebot.io/lib/prisma' | ||
import { | ||
CollaborationType, | ||
CollaboratorsOnTypebots, | ||
MemberInWorkspace, | ||
User, | ||
Workspace, | ||
} from '@typebot.io/prisma' | ||
import { Typebot } from '@typebot.io/schemas' | ||
import { isNotDefined } from '@typebot.io/lib' | ||
|
||
export const isWriteTypebotForbidden = async ( | ||
typebot: Pick<Typebot, 'workspaceId'> & { | ||
typebot: { | ||
collaborators: Pick<CollaboratorsOnTypebots, 'userId' | 'type'>[] | ||
} & { | ||
workspace: Pick<Workspace, 'isQuarantined' | 'isPastDue'> & { | ||
members: Pick<MemberInWorkspace, 'userId' | 'role'>[] | ||
} | ||
}, | ||
user: Pick<User, 'id'> | ||
) => { | ||
if ( | ||
typebot.collaborators.find( | ||
(collaborator) => collaborator.userId === user.id | ||
)?.type === CollaborationType.WRITE | ||
return ( | ||
typebot.workspace.isQuarantined || | ||
typebot.workspace.isPastDue || | ||
!( | ||
typebot.collaborators.find( | ||
(collaborator) => collaborator.userId === user.id | ||
)?.type === CollaborationType.WRITE && | ||
typebot.workspace.members.some( | ||
(m) => m.userId === user.id && m.role !== 'GUEST' | ||
) | ||
) | ||
) | ||
return false | ||
const memberInWorkspace = await prisma.memberInWorkspace.findFirst({ | ||
where: { | ||
workspaceId: typebot.workspaceId, | ||
userId: user.id, | ||
}, | ||
}) | ||
return isNotDefined(memberInWorkspace) || memberInWorkspace.role === 'GUEST' | ||
} |
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.
The error message 'Typebot not found' is still used for both a missing typebot and forbidden read access. Consider implementing the previously suggested changes to provide clearer feedback to the client.
Commitable suggestion