-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[VPAT-51] fix: update workspace invitation flow to use token for validation #8508
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
base: preview
Are you sure you want to change the base?
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -159,10 +159,10 @@ class WorkspaceJoinEndpoint(BaseAPIView): | |||||
| def post(self, request, slug, pk): | ||||||
| workspace_invite = WorkspaceMemberInvite.objects.get(pk=pk, workspace__slug=slug) | ||||||
|
|
||||||
| email = request.data.get("email", "") | ||||||
| token = request.data.get("token", "") | ||||||
|
|
||||||
| # Check the email | ||||||
| if email == "" or workspace_invite.email != email: | ||||||
| # Validate the token to verify the user received the invitation email | ||||||
| if not token or workspace_invite.token != token: | ||||||
|
||||||
| return Response( | ||||||
| {"error": "You do not have permission to join the workspace"}, | ||||||
|
||||||
| {"error": "You do not have permission to join the workspace"}, | |
| {"error": "Invalid or expired invitation token"}, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import React from "react"; | ||
| import { observer } from "mobx-react"; | ||
| import { useSearchParams } from "next/navigation"; | ||
| import useSWR from "swr"; | ||
|
|
@@ -28,8 +27,8 @@ function WorkspaceInvitationPage() { | |
| // query params | ||
| const searchParams = useSearchParams(); | ||
| const invitation_id = searchParams.get("invitation_id"); | ||
| const email = searchParams.get("email"); | ||
| const slug = searchParams.get("slug"); | ||
| const token = searchParams.get("token"); | ||
|
||
| // store hooks | ||
| const { data: currentUser } = useUser(); | ||
|
|
||
|
|
@@ -45,29 +44,29 @@ function WorkspaceInvitationPage() { | |
| workspaceService | ||
| .joinWorkspace(invitationDetail.workspace.slug, invitationDetail.id, { | ||
| accepted: true, | ||
| email: invitationDetail.email, | ||
| token: token, | ||
| }) | ||
| .then(() => { | ||
| if (email === currentUser?.email) { | ||
| if (invitationDetail.email === currentUser?.email) { | ||
| router.push(`/${invitationDetail.workspace.slug}`); | ||
| } else { | ||
| router.push(`/?${searchParams.toString()}`); | ||
| router.push("/"); | ||
| } | ||
| }) | ||
| .catch((err) => console.error(err)); | ||
| .catch((err: unknown) => console.error(err)); | ||
| }; | ||
|
|
||
| const handleReject = () => { | ||
| if (!invitationDetail) return; | ||
| workspaceService | ||
| if (!invitationDetail || !token) return; | ||
| void workspaceService | ||
|
||
| .joinWorkspace(invitationDetail.workspace.slug, invitationDetail.id, { | ||
| accepted: false, | ||
| email: invitationDetail.email, | ||
| token: token, | ||
| }) | ||
| .then(() => { | ||
| router.push("/"); | ||
| }) | ||
| .catch((err) => console.error(err)); | ||
| .catch((err: unknown) => console.error(err)); | ||
| }; | ||
|
|
||
| return ( | ||
|
|
||
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 API endpoint lacks proper error handling for the case where the WorkspaceMemberInvite object doesn't exist. If pk or slug are invalid, this will raise a DoesNotExist exception which will result in a 500 error instead of a more appropriate 404 error. Consider using get_object_or_404 or wrapping this in a try-except block to return a proper 404 response.