Files
upstream-zulip/zerver/views/development/registration.py
upstream-mirror 64898b2c79
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
2026-09-15 15:05:30 +05:00

105 lines
3.7 KiB
Python

from typing import TYPE_CHECKING, Any, cast
from django.conf import settings
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt
from confirmation.models import Confirmation, create_confirmation_link
from zerver.context_processors import get_realm_from_request
from zerver.lib.response import json_success
from zerver.models import Realm, UserProfile
from zerver.views.auth import (
create_preregistration_realm,
create_preregistration_user,
redirect_and_log_into_subdomain,
)
from zerver.views.registration import accounts_register, create_demo_helper
from zproject.backends import ExternalAuthResult
if TYPE_CHECKING:
from django.http.request import _ImmutableQueryDict
# This is used only by the Puppeteer test in realm-creation.ts.
def confirmation_key(request: HttpRequest) -> HttpResponse:
return json_success(request, data=request.session["confirmation_key"])
def modify_postdata(request: HttpRequest, **kwargs: Any) -> None:
new_post = request.POST.copy()
for key, value in kwargs.items():
new_post[key] = value
new_post._mutable = False
request.POST = cast("_ImmutableQueryDict", new_post)
@csrf_exempt
def register_development_user(request: HttpRequest) -> HttpResponse:
realm = get_realm_from_request(request)
if realm is None: # nocoverage
return HttpResponseRedirect(
f"{settings.EXTERNAL_URI_SCHEME}{settings.REALM_HOSTS['zulip']}/devtools/register_user/",
status=307,
)
count = UserProfile.objects.count()
name = f"user-{count}"
email = f"{name}@zulip.com"
prereg = create_preregistration_user(email, realm, password_required=False)
activation_url = create_confirmation_link(prereg, Confirmation.USER_REGISTRATION)
key = activation_url.split("/")[-1]
# Need to add test data to POST request as it doesn't originally contain the required parameters
modify_postdata(request, key=key, full_name=name, password="test", terms="true")
return accounts_register(request)
@csrf_exempt
def register_development_realm(request: HttpRequest) -> HttpResponse:
count = UserProfile.objects.count()
name = f"user-{count}"
email = f"{name}@zulip.com"
realm_name = f"realm-{count}"
realm_type = Realm.ORG_TYPES["business"]["id"]
realm_default_language = "en"
realm_subdomain = realm_name
prereg_realm = create_preregistration_realm(
email, realm_name, realm_subdomain, realm_type, realm_default_language
)
activation_url = create_confirmation_link(
prereg_realm, Confirmation.NEW_REALM_USER_REGISTRATION, no_associated_realm_object=True
)
key = activation_url.split("/")[-1]
# Need to add test data to POST request as it doesn't originally contain the required parameters
modify_postdata(
request,
key=key,
realm_name=realm_name,
realm_type=realm_type,
realm_default_language=realm_default_language,
full_name=name,
password="test",
realm_subdomain=realm_subdomain,
terms="true",
how_realm_creator_found_zulip="ad",
how_realm_creator_found_zulip_extra_context="test",
)
return accounts_register(request)
@csrf_exempt
def register_demo_development_realm(request: HttpRequest) -> HttpResponse:
user_profile = create_demo_helper(
request,
realm_type=Realm.ORG_TYPES["education"]["id"],
realm_default_language="en",
how_realm_creator_found_zulip="existing_user",
how_realm_creator_found_zulip_extra_context="test",
timezone="US/Pacific",
)
return redirect_and_log_into_subdomain(
ExternalAuthResult(user_profile=user_profile, data_dict={"is_realm_creation": True})
)