Skip to content

Commit

Permalink
ref: remove OrganizationAbsoluteUrlMixin (#75360)
Browse files Browse the repository at this point in the history
blocker for upgrading to django-stubs 5.0.4

- handled deprecated names in getsentry:
getsentry/getsentry#14786
- introduced new names in sentry:
#75340

<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Jul 31, 2024
1 parent 438743c commit 9ca135c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
4 changes: 0 additions & 4 deletions src/sentry/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
from sentry.models.apitoken import is_api_token_auth
from sentry.models.organization import Organization
from sentry.models.orgauthtoken import is_org_auth_token_auth
from sentry.organizations.absolute_url import ( # noqa: F401 # XXX: for compatibility, remove after getsentry is updated
customer_domain_path,
generate_organization_url,
)
from sentry.organizations.services.organization import (
RpcOrganization,
RpcOrganizationMember,
Expand Down
26 changes: 24 additions & 2 deletions src/sentry/models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from sentry.locks import locks
from sentry.models.outbox import OutboxCategory
from sentry.notifications.services import notifications_service
from sentry.organizations.absolute_url import has_customer_domain, organization_absolute_url
from sentry.roles.manager import Role
from sentry.types.organization import OrganizationAbsoluteUrlMixin
from sentry.users.services.user import RpcUser, RpcUserProfile
from sentry.users.services.user.service import user_service
from sentry.utils.http import is_using_customer_domain
Expand Down Expand Up @@ -145,7 +145,7 @@ def get_organizations_where_user_is_owner(self, user_id: int) -> QuerySet:

@snowflake_id_model
@region_silo_model
class Organization(ReplicatedRegionModel, OrganizationAbsoluteUrlMixin):
class Organization(ReplicatedRegionModel):
"""
An organization represents a group of individuals which maintain ownership of projects.
"""
Expand Down Expand Up @@ -467,6 +467,28 @@ def get_url(slug: str) -> str:
except NoReverseMatch:
return reverse(Organization.get_url_viewname())

@cached_property
def __has_customer_domain(self) -> bool:
"""
Check if the current organization is using or has access to customer domains.
"""
return has_customer_domain()

def absolute_url(self, path: str, query: str | None = None, fragment: str | None = None) -> str:
"""
Get an absolute URL to `path` for this organization.
This method takes customer-domains into account and will update the path when
customer-domains are active.
"""
return organization_absolute_url(
has_customer_domain=self.__has_customer_domain,
slug=self.slug,
path=path,
query=query,
fragment=fragment,
)

def get_scopes(self, role: Role) -> frozenset[str]:
"""
Note that scopes for team-roles are filtered through this method too.
Expand Down
27 changes: 25 additions & 2 deletions src/sentry/organizations/services/organization/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections.abc import Callable, Iterable, Mapping, Sequence
from datetime import datetime
from enum import IntEnum
from functools import cached_property
from typing import Any

from django.dispatch import Signal
Expand All @@ -14,12 +15,12 @@

from sentry import roles
from sentry.hybridcloud.rpc import RpcModel
from sentry.organizations.absolute_url import has_customer_domain, organization_absolute_url
from sentry.projects.services.project import RpcProject
from sentry.roles import team_roles
from sentry.roles.manager import TeamRole
from sentry.signals import sso_enabled
from sentry.silo.base import SiloMode
from sentry.types.organization import OrganizationAbsoluteUrlMixin
from sentry.users.services.user.model import RpcUser


Expand Down Expand Up @@ -204,7 +205,7 @@ class RpcOrganizationInvite(RpcModel):
email: str = ""


class RpcOrganizationSummary(RpcModel, OrganizationAbsoluteUrlMixin):
class RpcOrganizationSummary(RpcModel):
"""
The subset of organization metadata available from the control silo specifically.
"""
Expand Down Expand Up @@ -241,6 +242,28 @@ def delete_option(self, key: str) -> None:

organization_service.delete_option(organization_id=self.id, key=key)

@cached_property
def __has_customer_domain(self) -> bool:
"""
Check if the current organization is using or has access to customer domains.
"""
return has_customer_domain()

def absolute_url(self, path: str, query: str | None = None, fragment: str | None = None) -> str:
"""
Get an absolute URL to `path` for this organization.
This method takes customer-domains into account and will update the path when
customer-domains are active.
"""
return organization_absolute_url(
has_customer_domain=self.__has_customer_domain,
slug=self.slug,
path=path,
query=query,
fragment=fragment,
)


class RpcOrganization(RpcOrganizationSummary):
# Represents the full set of teams and projects associated with the org. Note that these are not filtered by
Expand Down
37 changes: 0 additions & 37 deletions src/sentry/types/organization.py

This file was deleted.

0 comments on commit 9ca135c

Please sign in to comment.