-
Notifications
You must be signed in to change notification settings - Fork 501
Bootsecurity dev #1022
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
Bootsecurity dev #1022
Changes from all commits
cf8e76b
1701d2d
6940ffe
631b831
3bdf720
866cfaf
2af2c86
a27b1f4
e63c0cc
729f46e
7d71fc3
35b8460
a40c521
708fe14
6bf8977
38dfd88
38664c9
75f1416
d697810
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 |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| import { teamMembershipsCrudHandlers } from "@/app/api/latest/team-memberships/crud"; | ||
| import { sendEmailFromTemplate } from "@/lib/emails"; | ||
| import { getItemQuantityForCustomer } from "@/lib/payments"; | ||
| import { grantTeamPermission } from "@/lib/permissions"; | ||
| import { getSoleTenancyFromProjectBranch } from "@/lib/tenancies"; | ||
| import { getPrismaClientForTenancy } from "@/prisma-client"; | ||
| import { createVerificationCodeHandler } from "@/route-handlers/verification-code-handler"; | ||
| import { VerificationCodeType } from "@prisma/client"; | ||
| import { KnownErrors } from "@stackframe/stack-shared"; | ||
| import { emailSchema, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
| import { emailSchema, permissionDefinitionIdSchema, yupArray, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
| import { teamsCrudHandlers } from "../../teams/crud"; | ||
|
|
||
| export const teamInvitationCodeHandler = createVerificationCodeHandler({ | ||
|
|
@@ -30,6 +31,7 @@ export const teamInvitationCodeHandler = createVerificationCodeHandler({ | |
| type: VerificationCodeType.TEAM_INVITATION, | ||
| data: yupObject({ | ||
| team_id: yupString().defined(), | ||
| permission_ids: yupArray(permissionDefinitionIdSchema.defined()).optional(), | ||
| }).defined(), | ||
| method: yupObject({ | ||
| email: emailSchema.defined(), | ||
|
|
@@ -67,7 +69,7 @@ export const teamInvitationCodeHandler = createVerificationCodeHandler({ | |
|
|
||
| return codeObj; | ||
| }, | ||
| async handler(tenancy, {}, data, body, user) { | ||
| async handler(tenancy, { }, data, body, user) { | ||
| if (!user) throw new KnownErrors.UserAuthenticationRequired; | ||
| const prisma = await getPrismaClientForTenancy(tenancy); | ||
|
|
||
|
|
@@ -112,6 +114,19 @@ export const teamInvitationCodeHandler = createVerificationCodeHandler({ | |
| user_id: user.id, | ||
| data: {}, | ||
| }); | ||
|
|
||
| // Apply additional specific permissions if provided (with deduplication) | ||
| if (data.permission_ids && data.permission_ids.length > 0) { | ||
| const uniquePermissionIds = [...new Set(data.permission_ids)]; | ||
| for (const permissionId of uniquePermissionIds) { | ||
| await grantTeamPermission(prisma, { | ||
| tenancy, | ||
| teamId: data.team_id, | ||
| userId: user.id, | ||
| permissionId, | ||
| }); | ||
| } | ||
| } | ||
|
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. Bug: Permissions not granted for existing team membersWhen an existing team member accepts an invitation with |
||
| } | ||
|
|
||
| return { | ||
|
|
@@ -120,7 +135,7 @@ export const teamInvitationCodeHandler = createVerificationCodeHandler({ | |
| body: {} | ||
| }; | ||
| }, | ||
| async details(tenancy, {}, data, body, user) { | ||
| async details(tenancy, { }, data, body, user) { | ||
| if (!user) throw new KnownErrors.UserAuthenticationRequired; | ||
|
|
||
| const team = await teamsCrudHandlers.adminRead({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { listPermissionDefinitions } from "@/lib/permissions"; | ||
| import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler"; | ||
| import { adaptSchema, clientOrHigherAuthTypeSchema, yupArray, yupBoolean, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields"; | ||
|
|
||
| export const GET = createSmartRouteHandler({ | ||
| metadata: { | ||
| summary: "Get role-based permissions for team invitations", | ||
| description: "Fetch available role-based permissions that can be assigned to team members during invitations. Only returns role-based permissions, not system permissions.", | ||
BilalG1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tags: ["Teams"], | ||
| }, | ||
| request: yupObject({ | ||
| auth: yupObject({ | ||
| type: clientOrHigherAuthTypeSchema, | ||
| tenancy: adaptSchema.defined(), | ||
| user: adaptSchema.optional(), | ||
| }).defined(), | ||
| }), | ||
| response: yupObject({ | ||
| statusCode: yupNumber().oneOf([200]).defined(), | ||
| bodyType: yupString().oneOf(["json"]).defined(), | ||
| body: yupObject({ | ||
| items: yupArray(yupObject({ | ||
| id: yupString().defined(), | ||
| description: yupString().optional(), | ||
| contained_permission_ids: yupArray(yupString().defined()).defined(), | ||
| }).defined()).defined(), | ||
| is_paginated: yupBoolean().oneOf([false]).defined(), | ||
| }).defined(), | ||
| }), | ||
| async handler({ auth }) { | ||
| const allPermissions = await listPermissionDefinitions({ | ||
| scope: "team", | ||
| tenancy: auth.tenancy, | ||
| }); | ||
|
|
||
| // Return all permissions including system permissions (starting with $) | ||
| return { | ||
| statusCode: 200, | ||
| bodyType: "json", | ||
| body: { | ||
| items: allPermissions, | ||
| is_paginated: false, | ||
| }, | ||
| }; | ||
| }, | ||
| }); | ||
|
Comment on lines
+5
to
+46
Contributor
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. Clarify whether system permissions should be included. There's an inconsistency between the metadata description and the implementation:
Please clarify the intended behavior and update either:
🤖 Prompt for AI Agents |
||
Uh oh!
There was an error while loading. Please reload this page.