models: Replace realm.uri with realm.url.

In #23380, we are changing all occurrences of uri with url in order to
follow the latest URL standard. Previous PRs #25038 and #25045 has
replaced the occurences of uri that has no direct relation with realm.

This commit changes just the model property, which has no API
compatibility concerns.
This commit is contained in:
Vector73 2024-05-06 18:57:22 +05:30 committed by Tim Abbott
parent 0bef960b34
commit 8ab526a25a
51 changed files with 125 additions and 125 deletions

View File

@ -201,7 +201,7 @@ def confirmation_url(
url_args = dict(url_args)
url_args["confirmation_key"] = confirmation_key
return urljoin(
settings.ROOT_DOMAIN_URI if realm is None else realm.uri,
settings.ROOT_DOMAIN_URI if realm is None else realm.url,
reverse(_properties[confirmation_type].url_name, kwargs=url_args),
)

View File

@ -389,7 +389,7 @@ def payment_method_string(stripe_customer: stripe.Customer) -> str:
def build_support_url(support_view: str, query_text: str) -> str:
support_realm_url = get_realm(settings.STAFF_SUBDOMAIN).uri
support_realm_url = get_realm(settings.STAFF_SUBDOMAIN).url
support_url = urljoin(support_realm_url, reverse(support_view))
query = urlencode({"q": query_text})
support_url = append_url_query_string(support_url, query)
@ -3756,7 +3756,7 @@ class RealmBillingSession(BillingSession):
@override
@property
def billing_session_url(self) -> str:
return self.realm.uri
return self.realm.url
@override
@property
@ -5310,7 +5310,7 @@ def downgrade_small_realms_behind_on_payments_as_needed() -> None:
billing_session.downgrade_now_without_creating_additional_invoices()
billing_session.void_all_open_invoices()
context: Dict[str, Union[str, Realm]] = {
"upgrade_url": f"{realm.uri}{reverse('upgrade_page')}",
"upgrade_url": f"{realm.url}{reverse('upgrade_page')}",
"realm": realm,
}
send_email_to_billing_admins_and_realm_owners(

View File

@ -112,9 +112,9 @@ class CloudSupportData:
def get_realm_support_url(realm: Realm) -> str:
support_realm_uri = get_realm(settings.STAFF_SUBDOMAIN).uri
support_realm_url = get_realm(settings.STAFF_SUBDOMAIN).url
support_url = urljoin(
support_realm_uri,
support_realm_url,
urlunsplit(("", "", reverse("support"), urlencode({"q": realm.string_id}), "")),
)
return support_url

View File

@ -336,7 +336,7 @@ def communities_view(request: HttpRequest) -> HttpResponse:
{
"id": realm.id,
"name": realm.name,
"realm_url": realm.uri,
"realm_url": realm.url,
"logo_url": get_realm_icon_url(realm),
"description": get_realm_text_description(realm),
"org_type_key": org_type,

View File

@ -1,7 +1,7 @@
<div class="realm-support-information">
<span class="cloud-label">Cloud realm</span>
<h3><img src="{{ realm_icon_url(realm) }}" class="support-realm-icon" /> {{ realm.name }}</h3>
<b>URL</b>: <a target="_blank" rel="noopener noreferrer" href="{{ realm.uri }}">{{ realm.uri }}</a> |
<b>URL</b>: <a target="_blank" rel="noopener noreferrer" href="{{ realm.url }}">{{ realm.url }}</a> |
<a target="_blank" rel="noopener noreferrer" href="/stats/realm/{{ realm.string_id }}/">stats</a> |
<a target="_blank" rel="noopener noreferrer" href="/realm_activity/{{ realm.string_id }}/">activity</a><br />
<b>Date created</b>: {{ realm.date_created|timesince }} ago<br />

View File

@ -25,7 +25,7 @@ page can be easily identified in it's respective JavaScript file -->
{% if realm_web_public_access_enabled %}
<h2>{{_('Anonymous user') }}</h2>
<p>
<input type="submit" formaction="{{ current_realm.uri }}{{ url('login-local') }}"
<input type="submit" formaction="{{ current_realm.url }}{{ url('login-local') }}"
name="prefers_web_public_view" class="dev-button dev-login-button" value="Anonymous login" />
</p>
{% endif %}
@ -33,7 +33,7 @@ page can be easily identified in it's respective JavaScript file -->
{% if direct_owners %}
{% for direct_owner in direct_owners %}
<p>
<button type="submit" formaction="{{ direct_owner.realm.uri }}{{ url('login-local') }}"
<button type="submit" formaction="{{ direct_owner.realm.url }}{{ url('login-local') }}"
name="direct_email" class="dev-button dev-login-button" value="{{ direct_owner.delivery_email }}">
{% if direct_owner.realm.demo_organization_scheduled_deletion_date %}
{{ direct_owner.full_name }}
@ -50,7 +50,7 @@ page can be easily identified in it's respective JavaScript file -->
{% if direct_admins %}
{% for direct_admin in direct_admins %}
<p>
<input type="submit" formaction="{{ direct_admin.realm.uri }}{{ url('login-local') }}"
<input type="submit" formaction="{{ direct_admin.realm.url }}{{ url('login-local') }}"
name="direct_email" class="dev-button dev-login-button" value="{{ direct_admin.delivery_email }}" />
</p>
{% endfor %}
@ -61,7 +61,7 @@ page can be easily identified in it's respective JavaScript file -->
{% if direct_moderators %}
{% for direct_moderator in direct_moderators %}
<p>
<input type="submit" formaction="{{ direct_moderator.realm.uri }}{{ url('login-local') }}"
<input type="submit" formaction="{{ direct_moderator.realm.url }}{{ url('login-local') }}"
name="direct_email" class="dev-button dev-login-button" value="{{ direct_moderator.delivery_email }}" />
</p>
{% endfor %}
@ -72,7 +72,7 @@ page can be easily identified in it's respective JavaScript file -->
{% if guest_users %}
{% for guest_user in guest_users %}
<p>
<input type="submit" formaction="{{ guest_user.realm.uri }}{{ url('login-local') }}"
<input type="submit" formaction="{{ guest_user.realm.url }}{{ url('login-local') }}"
name="direct_email" class="dev-button dev-login-button" value="{{ guest_user.delivery_email }}" />
</p>
{% endfor %}
@ -86,7 +86,7 @@ page can be easily identified in it's respective JavaScript file -->
{% if direct_users %}
{% for direct_user in direct_users %}
<p>
<input type="submit" formaction="{{ direct_user.realm.uri }}{{ url('login-local') }}"
<input type="submit" formaction="{{ direct_user.realm.url }}{{ url('login-local') }}"
name="direct_email" class="dev-button dev-login-button" value="{{ direct_user.delivery_email }}" />
</p>
{% endfor %}

View File

@ -16,7 +16,7 @@
<ul>
{% for realm in realms %}
<li><a href="{{ realm.uri }}">{{ realm.name }} ({{ realm.host }})</a></li>
<li><a href="{{ realm.url }}">{{ realm.name }} ({{ realm.host }})</a></li>
{% endfor %}
</ul>

View File

@ -9,7 +9,7 @@
{% for realm in realms %}
* {{ realm.name }}: {{ realm.uri }}
* {{ realm.name }}: {{ realm.url }}
{% endfor %}
{% trans %}If you have trouble logging in, you can reset your password.{% endtrans %}

View File

@ -26,7 +26,7 @@
{{ _("You do have active accounts in the following organization(s).") }}
<ul>
{% for active_account in active_accounts_in_other_realms %}
<li>{{ active_account.realm.uri }}</li>
<li>{{ active_account.realm.url }}</li>
{% endfor %}
</ul>
{% trans %}You can try logging in or resetting your password in the organization(s) above.{% endtrans %}

View File

@ -21,7 +21,7 @@ You do not have an account in that Zulip organization.
{{ _("You do have active accounts in the following organization(s).") }}
{% for active_account in active_accounts_in_other_realms %}
{{ active_account.realm.uri }}
{{ active_account.realm.url }}
{% endfor %}
{% trans -%}

View File

@ -5,7 +5,7 @@
{% endblock %}
{% block content %}
{% trans organization_name_with_link=macros.link_tag(realm.uri, realm.string_id) %}
{% trans organization_name_with_link=macros.link_tag(realm.url, realm.string_id) %}
Your organization, {{ organization_name_with_link }}, has been downgraded to the Zulip Cloud
Free plan because of unpaid invoices. The unpaid invoices have been voided.
{% endtrans %}

View File

@ -1,4 +1,4 @@
Your organization, {{ realm.uri }}, has been downgraded to the Zulip Cloud
Your organization, {{ realm.url }}, has been downgraded to the Zulip Cloud
Free plan because of unpaid invoices. The unpaid invoices have been voided.
To continue on the Zulip Cloud Standard plan, please upgrade again by going

View File

@ -145,7 +145,7 @@ def send_bot_mock_message(
data, _, _ = get_fixture_info(fixture_path)
assert bot.bot_owner is not None
url = f"{bot.bot_owner.realm.uri}"
url = f"{bot.bot_owner.realm.url}"
client = zulip.Client(email=bot.email, api_key=bot.api_key, site=url)
try:
@ -180,7 +180,7 @@ def send_bot_payload_message(
assert isinstance(bot.bot_owner, UserProfile)
stream = integration.stream_name or "devel"
url = f"{bot.bot_owner.realm.uri}/{integration.url}"
url = f"{bot.bot_owner.realm.url}/{integration.url}"
params = {"api_key": bot.api_key, "stream": stream}
params.update(config.extra_params)
@ -226,7 +226,7 @@ def capture_last_message_screenshot(bot: UserProfile, image_path: str) -> None:
return
message_id = str(message.id)
screenshot_script = os.path.join(TOOLS_DIR, "message-screenshot.js")
subprocess.check_call(["node", screenshot_script, message_id, image_path, realm.uri])
subprocess.check_call(["node", screenshot_script, message_id, image_path, realm.url])
def generate_screenshot_from_config(

View File

@ -57,7 +57,7 @@ def do_change_realm_subdomain(
experience for clients.
"""
old_subdomain = realm.subdomain
old_uri = realm.uri
old_uri = realm.url
# If the realm had been a demo organization scheduled for
# deleting, clear that state.
realm.demo_organization_scheduled_deletion_date = None
@ -73,10 +73,10 @@ def do_change_realm_subdomain(
)
# If a realm if being renamed multiple times, we should find all the placeholder
# realms and reset their deactivated_redirect field to point to the new realm uri
# realms and reset their deactivated_redirect field to point to the new realm url
placeholder_realms = Realm.objects.filter(deactivated_redirect=old_uri, deactivated=True)
for placeholder_realm in placeholder_realms:
do_add_deactivated_redirect(placeholder_realm, realm.uri)
do_add_deactivated_redirect(placeholder_realm, realm.url)
# The below block isn't executed in a transaction with the earlier code due to
# the functions called below being complex and potentially sending events,
@ -88,7 +88,7 @@ def do_change_realm_subdomain(
if add_deactivated_redirect:
placeholder_realm = do_create_realm(old_subdomain, realm.name)
do_deactivate_realm(placeholder_realm, acting_user=None)
do_add_deactivated_redirect(placeholder_realm, realm.uri)
do_add_deactivated_redirect(placeholder_realm, realm.url)
def set_realm_permissions_based_on_org_type(realm: Realm) -> None:
@ -331,7 +331,7 @@ def do_create_realm(
support_url = get_realm_support_url(realm)
organization_type = get_org_type_display_name(realm.org_type)
message = f"[{realm.name}]({support_url}) ([{realm.display_subdomain}]({realm.uri})). Organization type: {organization_type}"
message = f"[{realm.name}]({support_url}) ([{realm.display_subdomain}]({realm.url})). Organization type: {organization_type}"
topic_name = "new organizations"
try:

View File

@ -740,7 +740,7 @@ def do_send_realm_reactivation_email(realm: Realm, *, acting_user: Optional[User
)
context = {
"confirmation_url": url,
"realm_uri": realm.uri,
"realm_uri": realm.url,
"realm_name": realm.name,
"corporate_enabled": settings.CORPORATE_ENABLED,
}

View File

@ -42,7 +42,7 @@ def common_context(user: UserProfile) -> Dict[str, Any]:
have a request.
"""
return {
"realm_uri": user.realm.uri,
"realm_uri": user.realm.url,
"realm_name": user.realm.name,
"root_domain_url": settings.ROOT_DOMAIN_URI,
"external_url_scheme": settings.EXTERNAL_URI_SCHEME,
@ -122,7 +122,7 @@ def zulip_default_context(request: HttpRequest) -> Dict[str, Any]:
realm_name = None
realm_icon = None
else:
realm_uri = realm.uri
realm_uri = realm.url
realm_name = realm.name
realm_icon = get_realm_icon_url(realm)

View File

@ -361,7 +361,7 @@ def generate_password_reset_url(
token = token_generator.make_token(user_profile)
uid = urlsafe_base64_encode(str(user_profile.id).encode())
endpoint = reverse("password_reset_confirm", kwargs=dict(uidb64=uid, token=token))
return f"{user_profile.realm.uri}{endpoint}"
return f"{user_profile.realm.url}{endpoint}"
class ZulipPasswordResetForm(PasswordResetForm):
@ -431,7 +431,7 @@ class ZulipPasswordResetForm(PasswordResetForm):
context = {
"email": email,
"realm_uri": realm.uri,
"realm_uri": realm.url,
"realm_name": realm.name,
}

View File

@ -135,7 +135,7 @@ def absolute_avatar_url(user_profile: UserProfile) -> str:
avatar = avatar_url(user_profile)
# avatar_url can return None if client_gravatar=True, however here we use the default value of False
assert avatar is not None
return urljoin(user_profile.realm.uri, avatar)
return urljoin(user_profile.realm.url, avatar)
def is_avatar_new(ldap_avatar: bytes, user_profile: UserProfile) -> bool:

View File

@ -230,13 +230,13 @@ def build_message_list(
# structure of the URL to leverage. We can't use `relative_to_full_url()`
# function here because it uses a stricter regex which will not work for
# plain text.
plain = re.sub(r"/user_uploads/(\S*)", user.realm.uri + r"/user_uploads/\1", plain)
plain = re.sub(r"/user_uploads/(\S*)", user.realm.url + r"/user_uploads/\1", plain)
plain = fix_spoilers_in_text(plain, user.default_language)
plain = add_quote_prefix_in_text(plain)
assert message.rendered_content is not None
fragment = lxml.html.fragment_fromstring(message.rendered_content, create_parent=True)
relative_to_full_url(fragment, user.realm.uri)
relative_to_full_url(fragment, user.realm.url)
fix_emojis(fragment, user.emojiset)
fix_spoilers_in_html(fragment, user.default_language)
change_katex_to_raw_latex(fragment)
@ -784,7 +784,7 @@ def send_account_registered_email(user: UserProfile, realm_creation: bool = Fals
return
from_name, from_address = welcome_sender_information()
realm_url = user.realm.uri
realm_url = user.realm.url
account_registered_context = common_context(user)
account_registered_context.update(
@ -845,7 +845,7 @@ def enqueue_welcome_emails(user: UserProfile, realm_creation: bool = False) -> N
.count()
)
unsubscribe_link = one_click_unsubscribe_link(user, "welcome")
realm_url = user.realm.uri
realm_url = user.realm.url
# Any emails scheduled below should be added to the logic in get_onboarding_email_schedule
# to determine how long to delay sending the email based on when the user signed up.

View File

@ -309,7 +309,7 @@ def fetch_initial_state_data(
state["realm_icon_source"] = realm.icon_source
add_realm_logo_fields(state, realm)
state["realm_uri"] = realm.uri
state["realm_uri"] = realm.url
state["realm_bot_domain"] = realm.get_bot_domain()
state["realm_available_video_chat_providers"] = realm.VIDEO_CHAT_PROVIDERS
state["settings_send_digest_emails"] = settings.SEND_DIGEST_EMAILS

View File

@ -2655,7 +2655,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.uri,
realm_uri=message_realm.url,
sent_by_bot=sent_by_bot,
stream_names=stream_name_info,
translate_emoticons=translate_emoticons,

View File

@ -52,14 +52,14 @@ def send_initial_direct_message(user: UserProfile) -> None:
# request and thus may not have the user's language context yet.
with override_language(user.default_language):
if education_organization:
getting_started_help = user.realm.uri + "/help/using-zulip-for-a-class"
getting_started_help = user.realm.url + "/help/using-zulip-for-a-class"
getting_started_string = (
_(
"If you are new to Zulip, check out our [Using Zulip for a class guide]({getting_started_url})!"
)
).format(getting_started_url=getting_started_help)
else:
getting_started_help = user.realm.uri + "/help/getting-started-with-zulip"
getting_started_help = user.realm.url + "/help/getting-started-with-zulip"
getting_started_string = (
_(
"If you are new to Zulip, check out our [Getting started guide]({getting_started_url})!"
@ -70,7 +70,7 @@ def send_initial_direct_message(user: UserProfile) -> None:
# Add extra content on setting up a new organization for administrators.
if user.is_realm_admin:
if education_organization:
organization_setup_help = user.realm.uri + "/help/setting-up-zulip-for-a-class"
organization_setup_help = user.realm.url + "/help/setting-up-zulip-for-a-class"
organization_setup_string = (
" "
+ _(
@ -79,7 +79,7 @@ def send_initial_direct_message(user: UserProfile) -> None:
).format(organization_setup_url=organization_setup_help)
else:
organization_setup_help = (
user.realm.uri + "/help/getting-your-organization-started-with-zulip"
user.realm.url + "/help/getting-your-organization-started-with-zulip"
)
organization_setup_string = (
" "
@ -91,7 +91,7 @@ def send_initial_direct_message(user: UserProfile) -> None:
demo_organization_warning_string = ""
# Add extra content about automatic deletion for demo organization owners.
if user.is_realm_owner and user.realm.demo_organization_scheduled_deletion_date is not None:
demo_organization_help = user.realm.uri + "/help/demo-organizations"
demo_organization_help = user.realm.url + "/help/demo-organizations"
demo_organization_warning_string = (
_(
"Note that this is a [demo organization]({demo_organization_help_url}) and will be "

View File

@ -948,7 +948,7 @@ def get_base_payload(user_profile: UserProfile) -> Dict[str, Any]:
# These will let the app support logging into multiple realms and servers.
data["server"] = settings.EXTERNAL_HOST
data["realm_id"] = user_profile.realm.id
data["realm_uri"] = user_profile.realm.uri
data["realm_uri"] = user_profile.realm.url
data["realm_name"] = user_profile.realm.name
data["user_id"] = user_profile.id

View File

@ -365,7 +365,7 @@ def get_realms_info_for_push_bouncer(realm_id: Optional[int] = None) -> List[Rea
uuid=realm.uuid,
uuid_owner_secret=realm.uuid_owner_secret,
host=realm.host,
url=realm.uri,
url=realm.url,
deactivated=realm.deactivated,
date_created=realm.date_created.timestamp(),
org_type=realm.org_type,

View File

@ -380,13 +380,13 @@ def base_scim_location_getter(request: HttpRequest, *args: Any, **kwargs: Any) -
Since SCIM synchronization is scoped to an individual realm, we
need these locations to be namespaced within the realm's domain
namespace, which is conveniently accessed via realm.uri.
namespace, which is conveniently accessed via realm.url.
"""
realm = RequestNotes.get_notes(request).realm
assert realm is not None
return realm.uri
return realm.url
class ConflictError(scim_exceptions.IntegrityError):

View File

@ -612,7 +612,7 @@ def send_custom_email(
context: Dict[str, object] = {
"realm": user_profile.realm,
"realm_string_id": user_profile.realm.string_id,
"realm_uri": user_profile.realm.uri,
"realm_uri": user_profile.realm.url,
"realm_name": user_profile.realm.name,
}
if add_context is not None:

View File

@ -213,7 +213,7 @@ def handle_reupload_emojis_event(realm: Realm, logger: logging.Logger) -> None:
assert emoji_filename is not None
emoji_url = get_emoji_url(emoji_filename, realm_emoji.realm_id)
if emoji_url.startswith("/"):
emoji_url = urljoin(realm_emoji.realm.uri, emoji_url)
emoji_url = urljoin(realm_emoji.realm.url, emoji_url)
emoji_file_content = get_emoji_file_content(session, emoji_url, realm_emoji.id, logger)

View File

@ -269,7 +269,7 @@ class LocalUploadBackend(ZulipUploadBackend):
@override
def get_export_tarball_url(self, realm: Realm, export_path: str) -> str:
# export_path has a leading `/`
return realm.uri + export_path
return realm.url + export_path
@override
def upload_export_tarball(
@ -287,7 +287,7 @@ class LocalUploadBackend(ZulipUploadBackend):
abs_path = os.path.join(assert_is_not_none(settings.LOCAL_AVATARS_DIR), path)
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
shutil.copy(tarball_path, abs_path)
public_url = realm.uri + "/user_avatars/" + path
public_url = realm.url + "/user_avatars/" + path
return public_url
@override

View File

@ -22,7 +22,7 @@ def encode_stream(stream_id: int, stream_name: str) -> str:
def personal_narrow_url(*, realm: Realm, sender: UserProfile) -> str:
base_url = f"{realm.uri}/#narrow/dm/"
base_url = f"{realm.url}/#narrow/dm/"
encoded_user_name = re2.sub(r'[ "%\/<>`\p{C}]+', "-", sender.full_name)
pm_slug = str(sender.id) + "-" + encoded_user_name
return base_url + pm_slug
@ -32,17 +32,17 @@ def huddle_narrow_url(*, user: UserProfile, display_recipient: List[UserDisplayR
realm = user.realm
other_user_ids = [r["id"] for r in display_recipient if r["id"] != user.id]
pm_slug = ",".join(str(user_id) for user_id in sorted(other_user_ids)) + "-group"
base_url = f"{realm.uri}/#narrow/dm/"
base_url = f"{realm.url}/#narrow/dm/"
return base_url + pm_slug
def stream_narrow_url(realm: Realm, stream: Stream) -> str:
base_url = f"{realm.uri}/#narrow/stream/"
base_url = f"{realm.url}/#narrow/stream/"
return base_url + encode_stream(stream.id, stream.name)
def topic_narrow_url(*, realm: Realm, stream: Stream, topic_name: str) -> str:
base_url = f"{realm.uri}/#narrow/stream/"
base_url = f"{realm.url}/#narrow/stream/"
return f"{base_url}{encode_stream(stream.id, stream.name)}/topic/{hash_util_encode(topic_name)}"
@ -70,7 +70,7 @@ def near_stream_message_url(realm: Realm, message: Dict[str, Any]) -> str:
encoded_stream = encode_stream(stream_id=stream_id, stream_name=stream_name)
parts = [
realm.uri,
realm.url,
"#narrow",
"stream",
encoded_stream,
@ -92,7 +92,7 @@ def near_pm_message_url(realm: Realm, message: Dict[str, Any]) -> str:
pm_str = ",".join(str_user_ids) + "-pm"
parts = [
realm.uri,
realm.url,
"#narrow",
"dm",
pm_str,

View File

@ -39,12 +39,12 @@ Usage examples:
if realm.deactivated:
print(
self.style.ERROR(
outer_format.format(realm.id, display_string_id, realm.name, realm.uri)
outer_format.format(realm.id, display_string_id, realm.name, realm.url)
)
)
deactivated = True
else:
print(outer_format.format(realm.id, display_string_id, realm.name, realm.uri))
print(outer_format.format(realm.id, display_string_id, realm.name, realm.url))
if deactivated:
print(self.style.WARNING("\nRed rows represent deactivated realms."))
sys.exit(0)

View File

@ -62,7 +62,7 @@ class Command(ZulipBaseCommand):
context = {
"email": user_profile.delivery_email,
"reset_url": generate_password_reset_url(user_profile, default_token_generator),
"realm_uri": user_profile.realm.uri,
"realm_uri": user_profile.realm.url,
"realm_name": user_profile.realm.name,
"active_account_in_realm": True,
}

View File

@ -579,7 +579,7 @@ class HostDomainMiddleware(MiddlewareMixin):
formal_host = request_notes.realm.host
if host != formal_host and not host.startswith(formal_host + ":"):
return HttpResponseRedirect(
urljoin(request_notes.realm.uri, request.get_full_path())
urljoin(request_notes.realm.url, request.get_full_path())
)
return None

View File

@ -45,7 +45,7 @@ def fix_dummy_users(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) ->
"""
do_delete_users had two bugs:
1. Creating the replacement dummy users with active=True
2. Creating the replacement dummy users with email domain set to realm.uri,
2. Creating the replacement dummy users with email domain set to realm.url,
which may not be a valid email domain.
Prior commits fixed the bugs, and this migration fixes the pre-existing objects.
"""

View File

@ -157,7 +157,7 @@ def log_extra_usermessage_rows(apps: StateApps, schema_editor: BaseDatabaseSchem
for message in messages:
realm = message.realm
# Reimplement realm.uri
# Reimplement realm.url
if realm.string_id == "":
hostname = settings.EXTERNAL_HOST
else:

View File

@ -898,7 +898,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
return self.string_id
@property
def uri(self) -> str:
def url(self) -> str:
return settings.EXTERNAL_URI_SCHEME + self.host
@property

View File

@ -36,7 +36,7 @@ def test_generated_curl_examples_for_success(client: Client) -> None:
# A limited Markdown engine that just processes the code example syntax.
realm = get_realm("zulip")
md_engine = markdown.Markdown(
extensions=[markdown_extension.makeExtension(api_url=realm.uri + "/api")]
extensions=[markdown_extension.makeExtension(api_url=realm.url + "/api")]
)
# We run our curl tests in alphabetical order (except that we

View File

@ -1166,7 +1166,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase, ABC):
self.assertEqual(result.status_code, 302)
self.assertEqual(
result["Location"],
f"{user_profile.realm.uri}/login/?"
f"{user_profile.realm.url}/login/?"
+ urlencode({"is_deactivated": user_profile.delivery_email}),
)
self.assertEqual(
@ -1215,7 +1215,7 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase, ABC):
],
)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/register/")
self.assertEqual(result["Location"], realm.url + "/register/")
def test_user_cannot_log_into_nonexisting_realm(self) -> None:
account_data_dict = self.get_account_data_dict(email=self.email, name=self.name)
@ -2842,7 +2842,7 @@ class SAMLAuthBackendTest(SocialAuthBase):
warn_log.output, [self.logger_output("SAML got invalid email argument.", "warning")]
)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/register/")
self.assertEqual(result["Location"], realm.url + "/register/")
def test_social_auth_saml_multiple_idps_configured(self) -> None:
# Set up a new SOCIAL_AUTH_SAML_ENABLED_IDPS dict with two idps.
@ -3984,7 +3984,7 @@ class GitHubAuthBackendTest(SocialAuthBase):
account_data_dict, subdomain=subdomain, email_data=email_data
)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/login/")
self.assertEqual(result["Location"], realm.url + "/login/")
self.assertEqual(
m.output,
[
@ -4006,7 +4006,7 @@ class GitHubAuthBackendTest(SocialAuthBase):
), self.assertLogs(self.logger_string, level="INFO") as mock_info:
result = self.social_auth_test(account_data_dict, subdomain=subdomain)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/login/")
self.assertEqual(result["Location"], realm.url + "/login/")
self.assertEqual(
mock_info.output,
[
@ -4042,7 +4042,7 @@ class GitHubAuthBackendTest(SocialAuthBase):
), self.assertLogs(self.logger_string, level="INFO") as mock_info:
result = self.social_auth_test(account_data_dict, subdomain=subdomain)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/login/")
self.assertEqual(result["Location"], realm.url + "/login/")
self.assertEqual(
mock_info.output,
[
@ -4292,7 +4292,7 @@ class GitHubAuthBackendTest(SocialAuthBase):
email_data=email_data,
)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/login/")
self.assertEqual(result["Location"], realm.url + "/login/")
self.assertEqual(
m.output,
[
@ -4345,7 +4345,7 @@ class GitHubAuthBackendTest(SocialAuthBase):
email_data=email_data,
)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/login/")
self.assertEqual(result["Location"], realm.url + "/login/")
self.assertEqual(
m.output,
[
@ -4377,7 +4377,7 @@ class GitHubAuthBackendTest(SocialAuthBase):
email_data=email_data,
)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/login/")
self.assertEqual(result["Location"], realm.url + "/login/")
self.assertEqual(
m.output,
[
@ -4433,7 +4433,7 @@ class GoogleAuthBackendTest(SocialAuthBase):
with self.assertLogs(self.logger_string, level="WARNING") as m:
result = self.social_auth_test(account_data_dict, subdomain=subdomain)
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], realm.uri + "/login/")
self.assertEqual(result["Location"], realm.url + "/login/")
self.assertEqual(
m.output,
[
@ -5341,7 +5341,7 @@ class TestTwoFactor(ZulipTestCase):
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], "http://zulip.testserver")
# Going to login page should redirect to `realm.uri` if user is
# Going to login page should redirect to `realm.url` if user is
# already logged in.
result = self.client_get("/accounts/login/")
self.assertEqual(result.status_code, 302)

View File

@ -207,7 +207,7 @@ class OpenGraphTest(ZulipTestCase):
open_graph_image = assert_is_not_none(bs.select_one('meta[property="og:image"]')).get(
"content"
)
self.assertEqual(open_graph_image, f"{realm.uri}{realm_icon}")
self.assertEqual(open_graph_image, f"{realm.url}{realm_icon}")
def test_login_page_realm_icon_absolute_url(self) -> None:
realm = get_realm("zulip")

View File

@ -774,7 +774,7 @@ class PushBouncerNotificationTest(BouncerTestCase):
"sender_id": hamlet.id,
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_uri": hamlet.realm.uri,
"realm_uri": hamlet.realm.url,
"user_id": self.example_user("othello").id,
}
},
@ -789,7 +789,7 @@ class PushBouncerNotificationTest(BouncerTestCase):
"content_truncated": False,
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_uri": hamlet.realm.uri,
"realm_uri": hamlet.realm.url,
"sender_id": hamlet.id,
"sender_email": hamlet.email,
"sender_full_name": "King Hamlet",
@ -3952,7 +3952,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.uri,
"realm_uri": self.sender.realm.url,
"user_id": user_profile.id,
"time": datetime_to_timestamp(message.date_sent),
},
@ -3996,7 +3996,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.uri,
"realm_uri": self.sender.realm.url,
"user_id": user_profile.id,
"time": datetime_to_timestamp(message.date_sent),
},
@ -4029,7 +4029,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.uri,
"realm_uri": self.sender.realm.url,
"user_id": self.sender.id,
"time": datetime_to_timestamp(message.date_sent),
},
@ -4068,7 +4068,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.uri,
"realm_uri": self.sender.realm.url,
"user_id": user_profile.id,
"time": datetime_to_timestamp(message.date_sent),
},
@ -4106,7 +4106,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.uri,
"realm_uri": self.sender.realm.url,
"user_id": user_profile.id,
"mentioned_user_group_id": user_group.id,
"mentioned_user_group_name": user_group.name,
@ -4145,7 +4145,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.uri,
"realm_uri": self.sender.realm.url,
"user_id": user_profile.id,
"time": datetime_to_timestamp(message.date_sent),
},
@ -4207,7 +4207,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": self.sender.realm.id,
"realm_name": self.sender.realm.name,
"realm_uri": self.sender.realm.uri,
"realm_uri": self.sender.realm.url,
"user_id": user_profile.id,
"time": datetime_to_timestamp(message.date_sent),
},
@ -4257,7 +4257,7 @@ class TestGetAPNsPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_name": hamlet.realm.name,
"realm_uri": hamlet.realm.uri,
"realm_uri": hamlet.realm.url,
"user_id": polonius.id,
"time": datetime_to_timestamp(message.date_sent),
}
@ -4296,7 +4296,7 @@ class TestGetGCMPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_name": hamlet.realm.name,
"realm_uri": hamlet.realm.uri,
"realm_uri": hamlet.realm.url,
"sender_id": hamlet.id,
"sender_email": hamlet.email,
"sender_full_name": "King Hamlet",
@ -4355,7 +4355,7 @@ class TestGetGCMPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_name": hamlet.realm.name,
"realm_uri": hamlet.realm.uri,
"realm_uri": hamlet.realm.url,
"sender_id": hamlet.id,
"sender_email": hamlet.email,
"sender_full_name": "King Hamlet",
@ -4388,7 +4388,7 @@ class TestGetGCMPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_name": hamlet.realm.name,
"realm_uri": hamlet.realm.uri,
"realm_uri": hamlet.realm.url,
"sender_id": hamlet.id,
"sender_email": hamlet.email,
"sender_full_name": "King Hamlet",
@ -4438,7 +4438,7 @@ class TestGetGCMPayload(PushNotificationTest):
"server": settings.EXTERNAL_HOST,
"realm_id": hamlet.realm.id,
"realm_name": hamlet.realm.name,
"realm_uri": hamlet.realm.uri,
"realm_uri": hamlet.realm.url,
"sender_id": hamlet.id,
"sender_email": f"user{hamlet.id}@zulip.testserver",
"sender_full_name": "Unknown user",

View File

@ -322,7 +322,7 @@ class RealmTest(ZulipTestCase):
placeholder_realm = get_realm("zulip")
self.assertTrue(placeholder_realm.deactivated)
self.assertEqual(placeholder_realm.deactivated_redirect, user.realm.uri)
self.assertEqual(placeholder_realm.deactivated_redirect, user.realm.url)
realm_audit_log = RealmAuditLog.objects.filter(
event_type=RealmAuditLog.REALM_SUBDOMAIN_CHANGED, acting_user=iago

View File

@ -177,7 +177,7 @@ class RealmExportTest(ZulipTestCase):
# Test that the export we have is the export we created.
export_dict = response_dict["exports"]
self.assertEqual(export_dict[0]["id"], audit_log_entry.id)
self.assertEqual(export_dict[0]["export_url"], admin.realm.uri + export_path)
self.assertEqual(export_dict[0]["export_url"], admin.realm.url + export_path)
self.assertEqual(export_dict[0]["acting_user_id"], admin.id)
self.assert_length(
export_dict,

View File

@ -795,7 +795,7 @@ class LoginTest(ZulipTestCase):
realm = user_profile.realm
self.assertTrue(email_auth_enabled(realm))
url = f"{realm.uri}/login/?" + urlencode({"is_deactivated": user_profile.delivery_email})
url = f"{realm.url}/login/?" + urlencode({"is_deactivated": user_profile.delivery_email})
result = self.client_get(url)
self.assertEqual(result.status_code, 200)
self.assert_in_response(
@ -2143,7 +2143,7 @@ class UserSignUpTest(ZulipTestCase):
# Verify that we were served a redirect to the app.
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], f"{realm.uri}/")
self.assertEqual(result["Location"], f"{realm.url}/")
# Verify that we successfully logged in.
user_profile = get_user_by_delivery_email(email, realm)
@ -4208,7 +4208,7 @@ class TestLoginPage(ZulipTestCase):
result = self.client_get("/login/", {"next": "/upgrade/"})
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], f"{hamlet.realm.uri}/upgrade/")
self.assertEqual(result["Location"], f"{hamlet.realm.url}/upgrade/")
@patch("django.http.HttpRequest.get_host")
def test_login_page_works_without_subdomains(self, mock_get_host: MagicMock) -> None:
@ -4250,7 +4250,7 @@ class TestLoginPage(ZulipTestCase):
session.save()
result = self.client_get("http://auth.testserver/login/")
self.assertEqual(result.status_code, 302)
self.assertEqual(result["Location"], zulip_realm.uri)
self.assertEqual(result["Location"], zulip_realm.url)
session = self.client.session
session["subdomain"] = "invalid"

View File

@ -72,9 +72,9 @@ class SubdomainsTest(ZulipTestCase):
self.assertTrue(test("/anything"))
self.assertFalse(test("https://zulip.com"))
self.assertFalse(test("http://zulip.com"))
self.assertTrue(test(f"{realm.uri}"))
self.assertTrue(test(f"{realm.url}"))
self.assertFalse(test(f"{realm.uri}@www.google.com"))
self.assertFalse(test(f"{realm.url}@www.google.com"))
# We don't have an existing configuration STATIC_URL with this
# format, but it's worth testing in case that changes.
@ -84,7 +84,7 @@ class SubdomainsTest(ZulipTestCase):
self.assertTrue(test(f"{settings.STATIC_URL}/x"))
self.assertFalse(test(evil_url))
self.assertFalse(test(f"{evil_url}/x"))
self.assertTrue(test(f"{realm.uri}"))
self.assertTrue(test(f"{realm.url}"))
self.assertTrue(test("/static/images/logo/zulip-org-logo.svg"))
self.assertTrue(test("/anything"))

View File

@ -394,7 +394,7 @@ def login_or_register_remote_user(request: HttpRequest, result: ExternalAuthResu
if is_free_trial_offer_enabled(False):
redirect_to = reverse("upgrade_page")
redirect_to = get_safe_redirect_to(redirect_to, user_profile.realm.uri)
redirect_to = get_safe_redirect_to(redirect_to, user_profile.realm.url)
return HttpResponseRedirect(redirect_to)
@ -460,7 +460,7 @@ 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.uri
realm_uri = 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
@ -747,7 +747,7 @@ def log_into_subdomain(request: HttpRequest, token: str) -> HttpResponse:
def redirect_and_log_into_subdomain(result: ExternalAuthResult) -> HttpResponse:
token = result.store_data()
realm = get_realm(result.data_dict["subdomain"])
subdomain_login_uri = realm.uri + reverse(log_into_subdomain, args=[token])
subdomain_login_uri = realm.url + reverse(log_into_subdomain, args=[token])
return redirect(subdomain_login_uri)
@ -809,7 +809,7 @@ class TwoFactorLoginView(BaseTwoFactorLoginView):
update_login_page_context(self.request, context)
realm = get_realm_from_request(self.request)
redirect_to = realm.uri if realm else "/"
redirect_to = realm.url if realm else "/"
context["next"] = self.request.POST.get(
"next",
self.request.GET.get("next", redirect_to),
@ -821,9 +821,9 @@ class TwoFactorLoginView(BaseTwoFactorLoginView):
Log in the user and redirect to the desired page.
We need to override this function so that we can redirect to
realm.uri instead of '/'.
realm.url instead of '/'.
"""
realm_uri = self.get_user().realm.uri
realm_uri = 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
@ -852,10 +852,10 @@ def login_page(
is_preview = "preview" in request.GET
if settings.TWO_FACTOR_AUTHENTICATION_ENABLED:
if request.user.is_authenticated and is_2fa_verified(request.user):
redirect_to = get_safe_redirect_to(next, request.user.realm.uri)
redirect_to = get_safe_redirect_to(next, request.user.realm.url)
return HttpResponseRedirect(redirect_to)
elif request.user.is_authenticated and not is_preview:
redirect_to = get_safe_redirect_to(next, request.user.realm.uri)
redirect_to = get_safe_redirect_to(next, request.user.realm.url)
return HttpResponseRedirect(redirect_to)
if is_subdomain_root_or_alias(request) and settings.ROOT_DOMAIN_LANDING_PAGE:
redirect_url = reverse("realm_redirect")
@ -882,7 +882,7 @@ def login_page(
if realm and "new_realm" in request.POST:
# If we're switching realms, redirect to that realm, but
# only if it actually exists.
return HttpResponseRedirect(realm.uri)
return HttpResponseRedirect(realm.url)
if "username" in request.POST:
extra_context["email"] = request.POST["username"]
@ -917,7 +917,7 @@ def social_auth_subdomain_login_page(request: HttpRequest) -> HttpResponse:
if origin_subdomain is not None:
try:
origin_realm = get_realm(origin_subdomain)
return HttpResponseRedirect(origin_realm.uri)
return HttpResponseRedirect(origin_realm.url)
except Realm.DoesNotExist:
pass

View File

@ -83,7 +83,7 @@ def dev_direct_login(
realm = get_realm(subdomain)
if request.POST.get("prefers_web_public_view") == "Anonymous login":
redirect_to = get_safe_redirect_to(next, realm.uri)
redirect_to = get_safe_redirect_to(next, realm.url)
return HttpResponseRedirect(redirect_to)
email = request.POST["direct_email"]
@ -93,7 +93,7 @@ def dev_direct_login(
assert isinstance(user_profile, UserProfile)
do_login(request, user_profile)
redirect_to = get_safe_redirect_to(next, user_profile.realm.uri)
redirect_to = get_safe_redirect_to(next, user_profile.realm.url)
return HttpResponseRedirect(redirect_to)
@ -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.uri)
dict(email=u.delivery_email, realm_uri=u.realm.url)
for u in users
if u.is_realm_admin
],
direct_users=[
dict(email=u.delivery_email, realm_uri=u.realm.uri)
dict(email=u.delivery_email, realm_uri=u.realm.url)
for u in users
if not u.is_realm_admin
],

View File

@ -463,7 +463,7 @@ def update_realm(
raise JsonableError(str(err.message))
do_change_realm_subdomain(realm, string_id, acting_user=user_profile)
data["realm_uri"] = realm.uri
data["realm_uri"] = realm.url
if org_type is not None:
do_change_realm_org_type(realm, org_type, acting_user=user_profile)

View File

@ -757,7 +757,7 @@ def login_and_go_to_home(request: HttpRequest, user_profile: UserProfile) -> Htt
do_login(request, user_profile)
# Using 'mark_sanitized' to work around false positive where Pysa thinks
# that 'user_profile' is user-controlled
return HttpResponseRedirect(mark_sanitized(user_profile.realm.uri) + reverse("home"))
return HttpResponseRedirect(mark_sanitized(user_profile.realm.url) + reverse("home"))
def prepare_activation_url(
@ -1216,7 +1216,7 @@ def realm_redirect(request: HttpRequest, next: str = REQ(default="")) -> HttpRes
if form.is_valid():
subdomain = form.cleaned_data["subdomain"]
realm = get_realm(subdomain)
redirect_to = urljoin(realm.uri, settings.HOME_NOT_LOGGED_IN)
redirect_to = urljoin(realm.url, settings.HOME_NOT_LOGGED_IN)
if next:
redirect_to = append_url_query_string(

View File

@ -168,7 +168,7 @@ def _deactivate_user_profile_backend(
from_address=FromAddress.NOREPLY,
context={
"deactivation_notification_comment": deactivation_notification_comment,
"realm_uri": target.realm.uri,
"realm_uri": target.realm.url,
"realm_name": target.realm.name,
},
)

View File

@ -109,7 +109,7 @@ def complete_zoom_user(
),
) -> HttpResponse:
if get_subdomain(request) != state["realm"]:
return redirect(urljoin(get_realm(state["realm"]).uri, request.get_full_path()))
return redirect(urljoin(get_realm(state["realm"]).url, request.get_full_path()))
return complete_zoom_user_in_realm(request)

View File

@ -578,5 +578,5 @@ def populate_remote_realms(customer_profile: CustomerProfile) -> Dict[str, str]:
return {
"unique_id": customer_profile.unique_id,
"login_url": local_realm.uri + "/self-hosted-billing/",
"login_url": local_realm.url + "/self-hosted-billing/",
}

View File

@ -1620,13 +1620,13 @@ class ZulipRemoteUserBackend(ZulipAuthMixin, RemoteUserBackend, ExternalAuthMeth
def redirect_to_signup(realm: Realm) -> HttpResponseRedirect:
signup_url = reverse("register")
redirect_url = realm.uri + signup_url
redirect_url = realm.url + signup_url
return HttpResponseRedirect(redirect_url)
def redirect_to_login(realm: Realm) -> HttpResponseRedirect:
login_url = reverse("login_page", kwargs={"template_name": "zerver/login.html"})
redirect_url = realm.uri + login_url
redirect_url = realm.url + login_url
return HttpResponseRedirect(redirect_url)
@ -1635,7 +1635,7 @@ def redirect_deactivated_user_to_login(realm: Realm, email: str) -> HttpResponse
# a deactivated account on a test server.
login_url = reverse("login_page", kwargs={"template_name": "zerver/login.html"})
redirect_url = append_url_query_string(
realm.uri + login_url, urlencode({"is_deactivated": email})
realm.url + login_url, urlencode({"is_deactivated": email})
)
return HttpResponseRedirect(redirect_url)