-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🛂 (billing) Add isPastDue field in workspace
Closes #1039
- Loading branch information
1 parent
94886ca
commit 55cb6e8
Showing
25 changed files
with
339 additions
and
70 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
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
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
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
37 changes: 18 additions & 19 deletions
37
apps/builder/src/features/typebot/helpers/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 |
---|---|---|
@@ -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)) |
34 changes: 18 additions & 16 deletions
34
apps/builder/src/features/typebot/helpers/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 |
---|---|---|
@@ -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' | ||
} |
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
Oops, something went wrong.