Skip to content

Commit f618700

Browse files
committed
wip: check verified emails on invite get
1 parent c500add commit f618700

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/sentry/api/endpoints/accept_organization_invite.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.http import HttpRequest
77
from django.urls import reverse
88
from rest_framework import status
9+
from rest_framework.authentication import SessionAuthentication
910
from rest_framework.request import Request
1011
from rest_framework.response import Response
1112

@@ -89,6 +90,7 @@ class AcceptOrganizationInvite(Endpoint):
8990
"POST": ApiPublishStatus.UNKNOWN,
9091
}
9192
# Disable authentication and permission requirements.
93+
authentication_classes = (SessionAuthentication,)
9294
permission_classes = ()
9395

9496
@staticmethod
@@ -146,6 +148,20 @@ def get(
146148

147149
response = Response(None)
148150

151+
# if the user is already authenticated, let's make sure
152+
# they have the email that the invite was sent to as a
153+
# verified email on their account
154+
if self.request.user.is_authenticated:
155+
user_verified_emails = {e.email for e in self.request.user.get_verified_emails()}
156+
157+
if organization_member.email not in user_verified_emails:
158+
return Response(
159+
status=403,
160+
data={
161+
"details": "Your account must have a verified email matching the email the invite was sent to."
162+
},
163+
)
164+
149165
# Allow users to register an account when accepting an invite
150166
if not helper.user_authenticated:
151167
request.session["can_register"] = True
@@ -203,6 +219,7 @@ def post(
203219
user_id=request.user.id,
204220
request=request,
205221
)
222+
206223
if invite_context is None:
207224
return self.respond_invalid()
208225

src/sentry/api/invite_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def from_session_or_email(
8686
invite = organization_service.get_invite_by_id(
8787
organization_id=organization_id, email=email, user_id=request.user.id
8888
)
89+
8990
if invite is None:
9091
# Unable to locate the pending organization member. Cannot setup
9192
# the invite helper.
@@ -114,6 +115,7 @@ def from_session(
114115
organization_id=invite_details.invite_organization_id,
115116
user_id=request.user.id,
116117
)
118+
117119
if invite_context is None:
118120
if logger:
119121
logger.exception("Invalid pending invite cookie")

0 commit comments

Comments
 (0)