Skip to content
Closed
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
67 changes: 14 additions & 53 deletions src/sentry/api/endpoints/accept_organization_invite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import logging
from collections.abc import Mapping

from django.contrib.auth import logout
from django.http import HttpRequest, HttpResponse
Expand All @@ -20,10 +19,7 @@
)
from sentry.demo_mode.utils import is_demo_user
from sentry.models.authprovider import AuthProvider
from sentry.models.organizationmapping import OrganizationMapping
from sentry.models.organizationmembermapping import OrganizationMemberMapping
from sentry.organizations.services.organization import RpcUserInviteContext, organization_service
from sentry.types.cell import CellResolutionError, get_cell_by_name
from sentry.utils import auth

logger = logging.getLogger(__name__)
Expand All @@ -32,41 +28,9 @@
def handle_empty_organization_id_or_slug(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to keep this function? It is not used in getsentry.

member_id: int, user_id: int | None, request: HttpRequest
) -> RpcUserInviteContext | None:
member_mapping: OrganizationMemberMapping | None = None
member_mappings: Mapping[int, OrganizationMemberMapping] = {
omm.organization_id: omm
for omm in OrganizationMemberMapping.objects.filter(organizationmember_id=member_id).all()
}
org_mappings = OrganizationMapping.objects.filter(
organization_id__in=list(member_mappings.keys())
)
for mapping in org_mappings:
try:
if get_cell_by_name(mapping.cell_name).is_historic_monolith_region():
member_mapping = member_mappings.get(mapping.organization_id)
break
except CellResolutionError:
pass

if member_mapping is None:
return None
invite_context = organization_service.get_invite_by_id(
organization_id=member_mapping.organization_id,
organization_member_id=member_id,
user_id=user_id,
)

logger.info(
"organization.member_invite.no_id_or_slug",
extra={
"member_id": member_id,
"org_id": member_mapping.organization_id,
"url": request.path,
"method": request.method,
},
)

return invite_context
# The pre-silo migration invite URL format omitted the org ID/slug.
# Those links have long since expired, so we no longer attempt to resolve them.
return None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dead function stub with unused parameters remains

Low Severity

handle_empty_organization_id_or_slug now unconditionally returns None and none of its three parameters (member_id, user_id, request) are used. This is dead code that outlived the cleanup — the function and its call in get_invite_state could be replaced with a direct return None (with the comment inline), removing an unnecessary layer of indirection.

Additional Locations (1)
Fix in Cursor Fix in Web



def get_invite_state(
Expand All @@ -78,21 +42,18 @@ def get_invite_state(
if organization_id_or_slug is None:
return handle_empty_organization_id_or_slug(member_id, user_id, request)

if str(organization_id_or_slug).isdecimal():
return organization_service.get_invite_by_id(
organization_id=organization_id_or_slug,
organization_member_id=member_id,
user_id=user_id,
)
else:
if str(organization_id_or_slug).isdecimal():
invite_context = organization_service.get_invite_by_id(
organization_id=organization_id_or_slug,
organization_member_id=member_id,
user_id=user_id,
)
else:
invite_context = organization_service.get_invite_by_slug(
organization_member_id=member_id,
slug=organization_id_or_slug,
user_id=user_id,
)

return invite_context
return organization_service.get_invite_by_slug(
organization_member_id=member_id,
slug=organization_id_or_slug,
user_id=user_id,
)


@control_silo_endpoint
Expand Down
15 changes: 0 additions & 15 deletions src/sentry/types/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,6 @@ def validate(self) -> None:

CELL_ID.validate(self.snowflake_id)

def is_historic_monolith_region(self) -> bool:
"""Check whether this is a historic monolith region.

In a monolith environment, there exists only the one monolith "region",
which is a dummy object.

In a siloed environment whose data was migrated from a monolith environment,
all region-scoped entities that existed before the migration belong to the
historic monolith region by default. Unlike in the monolith environment,
this region is not a dummy object, but nonetheless is subject to special
cases to ensure that legacy data is handled correctly.
"""

return self.name == settings.SENTRY_MONOLITH_REGION


class CellResolutionError(Exception):
"""Indicate that a cell's identity could not be resolved."""
Expand Down
Loading