zerver: Replace `realm_uri` with `realm_url` in backend files.

Co-authored-by: Junyao Chen <junyao.chen@socitydao.org>
This commit is contained in:
Vector73 2024-06-03 14:17:42 +05:30 committed by Tim Abbott
parent c514d39efc
commit 4430ab9cbe
4 changed files with 16 additions and 16 deletions

View File

@ -132,7 +132,7 @@ class MessageRenderingResult:
@dataclass
class DbData:
mention_data: MentionData
realm_uri: str
realm_url: str
realm_alert_words_automaton: Optional[ahocorasick.Automaton]
active_realm_emoji: Dict[str, EmojiInfo]
sent_by_bot: bool
@ -274,9 +274,9 @@ def rewrite_local_links_to_relative(db_data: Optional[DbData], link: str) -> str
"""
if db_data:
realm_uri_prefix = db_data.realm_uri + "/"
if link.startswith((realm_uri_prefix + "#", realm_uri_prefix + "user_uploads/")):
return link[len(realm_uri_prefix) :]
realm_url_prefix = db_data.realm_url + "/"
if link.startswith((realm_url_prefix + "#", realm_url_prefix + "user_uploads/")):
return link[len(realm_url_prefix) :]
return link
@ -2664,7 +2664,7 @@ def do_convert(
realm_alert_words_automaton=realm_alert_words_automaton,
mention_data=mention_data,
active_realm_emoji=active_realm_emoji,
realm_uri=message_realm.url,
realm_url=message_realm.url,
sent_by_bot=sent_by_bot,
stream_names=stream_name_info,
translate_emoticons=translate_emoticons,

View File

@ -1449,13 +1449,13 @@ def send_test_push_notification_directly_to_devices(
apple_payload = copy.deepcopy(payload)
android_payload = copy.deepcopy(payload)
realm_uri = base_payload["realm_uri"]
realm_url = base_payload["realm_url"]
realm_name = base_payload["realm_name"]
apns_data = {
"alert": {
"title": _("Test notification"),
"body": _("This is a test notification from {realm_name} ({realm_uri}).").format(
realm_name=realm_name, realm_uri=realm_uri
"body": _("This is a test notification from {realm_name} ({realm_url}).").format(
realm_name=realm_name, realm_url=realm_url
),
},
"sound": "default",

View File

@ -467,19 +467,19 @@ def finish_mobile_flow(request: HttpRequest, user_profile: UserProfile, otp: str
def create_response_for_otp_flow(
key: str, otp: str, user_profile: UserProfile, encrypted_key_field_name: str
) -> HttpResponse:
realm_uri = user_profile.realm.url
realm_url = user_profile.realm.url
# Check if the mobile URI is overridden in settings, if so, replace it
# This block should only apply to the mobile flow, so we if add others, this
# needs to be conditional.
if realm_uri in settings.REALM_MOBILE_REMAP_URIS:
realm_uri = settings.REALM_MOBILE_REMAP_URIS[realm_uri]
if realm_url in settings.REALM_MOBILE_REMAP_URIS:
realm_url = settings.REALM_MOBILE_REMAP_URIS[realm_url]
params = {
encrypted_key_field_name: otp_encrypt_api_key(key, otp),
"email": user_profile.delivery_email,
"user_id": user_profile.id,
"realm": realm_uri,
"realm": realm_url,
}
# We can't use HttpResponseRedirect, since it only allows HTTP(S) URLs
response = HttpResponse(status=302)
@ -830,7 +830,7 @@ class TwoFactorLoginView(BaseTwoFactorLoginView):
We need to override this function so that we can redirect to
realm.url instead of '/'.
"""
realm_uri = self.get_user().realm.url
realm_url = self.get_user().realm.url
# This mock.patch business is an unpleasant hack that we'd
# ideally like to remove by instead patching the upstream
# module to support better configurability of the
@ -839,7 +839,7 @@ class TwoFactorLoginView(BaseTwoFactorLoginView):
# process involving pbr -> pkgresources (which is really slow).
from unittest.mock import patch
with patch.object(settings, "LOGIN_REDIRECT_URL", realm_uri):
with patch.object(settings, "LOGIN_REDIRECT_URL", realm_url):
return super().done(form_list, **kwargs)

View File

@ -154,12 +154,12 @@ def api_dev_list_users(request: HttpRequest) -> HttpResponse:
request,
data=dict(
direct_admins=[
dict(email=u.delivery_email, realm_uri=u.realm.url)
dict(email=u.delivery_email, realm_url=u.realm.url)
for u in users
if u.is_realm_admin
],
direct_users=[
dict(email=u.delivery_email, realm_uri=u.realm.url)
dict(email=u.delivery_email, realm_url=u.realm.url)
for u in users
if not u.is_realm_admin
],