Skip to content

fix: require verified email to send invites #66861

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.organization import OrganizationEndpoint, OrganizationPermission
from sentry.api.decorators import email_verification_required
from sentry.api.endpoints.organization_member.index import OrganizationMemberRequestSerializer
from sentry.api.paginator import OffsetPaginator
from sentry.api.serializers import serialize
Expand Down Expand Up @@ -54,6 +55,7 @@ def get(self, request: Request, organization) -> Response:
paginator_cls=OffsetPaginator,
)

@email_verification_required
def post(self, request: Request, organization) -> Response:
"""
Add a invite request to Organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from sentry.models.options.organization_option import OrganizationOption
from sentry.models.organizationmember import InviteStatus, OrganizationMember
from sentry.models.organizationmemberteam import OrganizationMemberTeam
from sentry.models.useremail import UserEmail
from sentry.silo.base import SiloMode
from sentry.testutils.cases import APITestCase, SlackActivityNotificationTest
from sentry.testutils.hybrid_cloud import HybridCloudTestMixin
from sentry.testutils.outbox import outbox_runner
Expand Down Expand Up @@ -115,6 +117,18 @@ def test_simple(self):

self.assert_org_member_mapping(org_member=member)

def test_inviter_must_have_verified_email(self):
with assume_test_silo_mode(SiloMode.CONTROL):
UserEmail.objects.filter(user=self.user).update(is_verified=False)

self.login_as(user=self.user)

response = self.client.post(
self.url, {"email": "eric@localhost", "role": "member", "teams": [self.team.slug]}
)

assert response.status_code == 401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check the response if it's an actual email_verification_required error? Since checking for 401 is a really abstract

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah, I can check the error details. Good idea. :)

The frontend doesn't behave as expected, even though we return a 401. No error is actually rendered, so once I have the frontend changes in place, I'll come back to this PR.


def test_higher_role(self):
self.login_as(user=self.user)
response = self.client.post(
Expand Down
Loading