Skip to content

Commit 4890581

Browse files
fix(issues): Make system URL prefix handling more consistent (getsentry#40968)
fixing up PR [here](getsentry#39597) so that tests pass this makes system url prefix handling more consistent by using the sentry.http.utils.absolute_uri function Co-authored-by: Ville Laitila <[email protected]>
1 parent 0d37a0e commit 4890581

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

src/sentry/api/endpoints/chunk.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
from gzip import GzipFile
44
from io import BytesIO
5-
from urllib.parse import urljoin
65

76
from django.conf import settings
87
from django.urls import reverse
@@ -16,6 +15,7 @@
1615
from sentry.models import FileBlob
1716
from sentry.ratelimits.config import RateLimitConfig
1817
from sentry.utils.files import get_max_file_size
18+
from sentry.utils.http import absolute_uri
1919

2020
MAX_CHUNKS_PER_REQUEST = 64
2121
MAX_REQUEST_SIZE = 32 * 1024 * 1024
@@ -74,11 +74,10 @@ def get(self, request: Request, organization) -> Response:
7474
url = relative_url.lstrip(API_PREFIX)
7575
# Otherwise, if we do not support them, return an absolute, versioned endpoint with a default, system-wide prefix
7676
else:
77-
endpoint = options.get("system.url-prefix")
78-
url = urljoin(endpoint.rstrip("/") + "/", relative_url.lstrip("/"))
77+
url = absolute_uri(relative_url)
7978
else:
8079
# If user overridden upload url prefix, we want an absolute, versioned endpoint, with user-configured prefix
81-
url = urljoin(endpoint.rstrip("/") + "/", relative_url.lstrip("/"))
80+
url = absolute_uri(relative_url, endpoint)
8281

8382
return Response(
8483
{

src/sentry/middleware/customer_domain.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from rest_framework.request import Request
1010
from rest_framework.response import Response
1111

12-
from sentry import options
1312
from sentry.api.base import resolve_region
1413
from sentry.api.utils import generate_organization_url
1514
from sentry.models import Organization
1615
from sentry.utils import auth
16+
from sentry.utils.http import absolute_uri
1717

1818

1919
def _org_exists(slug):
@@ -91,9 +91,7 @@ def __call__(self, request: Request) -> Response:
9191
# DISALLOWED_CUSTOMER_DOMAINS is a list of org slugs that are explicitly not allowed to use customer domains.
9292
# We kick any request to the logout view.
9393
logout(request)
94-
url_prefix = options.get("system.url-prefix")
95-
logout_view = reverse("sentry-logout")
96-
redirect_url = f"{url_prefix}{logout_view}"
94+
redirect_url = absolute_uri(reverse("sentry-logout"))
9795
return HttpResponseRedirect(redirect_url)
9896

9997
activeorg = _resolve_activeorg(request)

src/sentry/models/authprovider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django.utils import timezone
55

66
from bitfield import BitField
7-
from sentry import options
87
from sentry.db.models import (
98
BoundedPositiveIntegerField,
109
FlexibleForeignKey,
@@ -13,6 +12,7 @@
1312
sane_repr,
1413
)
1514
from sentry.db.models.fields.jsonfield import JSONField
15+
from sentry.utils.http import absolute_uri
1616

1717
logger = logging.getLogger("sentry.authprovider")
1818

@@ -99,9 +99,8 @@ def get_scim_token(self):
9999

100100
def get_scim_url(self):
101101
if self.flags.scim_enabled:
102-
url_prefix = options.get("system.url-prefix")
103102
# the SCIM protocol doesn't use trailing slashes in URLs
104-
return f"{url_prefix}/api/0/organizations/{self.organization.slug}/scim/v2"
103+
return absolute_uri(f"api/0/organizations/{self.organization.slug}/scim/v2")
105104

106105
else:
107106
return None

src/sentry/templatetags/sentry_avatars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from django.urls import reverse
55
from django.utils.safestring import mark_safe
66

7-
from sentry import options
87
from sentry.models import User, UserAvatar
98
from sentry.utils.avatar import get_email_avatar, get_gravatar_url, get_letter_avatar
9+
from sentry.utils.http import absolute_uri
1010

1111
register = template.Library()
1212

@@ -33,7 +33,7 @@ def profile_photo_url(context, user_id, size=None):
3333
url = reverse("sentry-user-avatar-url", args=[avatar.ident])
3434
if size:
3535
url += "?" + urlencode({"s": size})
36-
return options.get("system.url-prefix") + url
36+
return absolute_uri(url)
3737

3838

3939
# Don't use this in any situations where you're rendering more

src/sentry/web/frontend/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from rest_framework.request import Request
1616
from rest_framework.response import Response
1717

18-
from sentry import options
1918
from sentry.api.serializers import serialize
2019
from sentry.api.utils import is_member_disabled_from_limit
2120
from sentry.auth import access
@@ -26,6 +25,7 @@
2625
from sentry.utils import auth
2726
from sentry.utils.audit import create_audit_entry
2827
from sentry.utils.auth import is_valid_redirect, make_login_link_with_redirect
28+
from sentry.utils.http import absolute_uri
2929
from sentry.web.frontend.generic import FOREVER_CACHE
3030
from sentry.web.helpers import render_to_response
3131
from sudo.views import redirect_to_sudo
@@ -178,8 +178,7 @@ def redirect_to_org(self, request: Request):
178178
else:
179179
url = "/organizations/new/"
180180
if request.subdomain:
181-
base = options.get("system.url-prefix")
182-
url = f"{base}{url}"
181+
url = absolute_uri(url)
183182
return HttpResponseRedirect(url)
184183

185184

0 commit comments

Comments
 (0)