mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
registration: Modify PreregistrationRealm objects after registration.
This commit is contained in:
@@ -6,6 +6,7 @@ from django.conf import settings
|
||||
from django.db import transaction
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from confirmation import settings as confirmation_settings
|
||||
from zerver.actions.message_send import internal_send_stream_message
|
||||
from zerver.actions.realm_settings import (
|
||||
do_add_deactivated_redirect,
|
||||
@@ -18,6 +19,7 @@ from zerver.lib.streams import ensure_stream, get_signups_stream
|
||||
from zerver.lib.user_groups import create_system_user_groups_for_realm
|
||||
from zerver.models import (
|
||||
DefaultStream,
|
||||
PreregistrationRealm,
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
RealmUserDefault,
|
||||
@@ -146,6 +148,7 @@ def do_create_realm(
|
||||
is_demo_organization: bool = False,
|
||||
enable_read_receipts: Optional[bool] = None,
|
||||
enable_spectator_access: Optional[bool] = None,
|
||||
prereg_realm: Optional[PreregistrationRealm] = None,
|
||||
) -> Realm:
|
||||
if string_id == settings.SOCIAL_AUTH_SUBDOMAIN:
|
||||
raise AssertionError("Creating a realm on SOCIAL_AUTH_SUBDOMAIN is not allowed!")
|
||||
@@ -257,6 +260,11 @@ def do_create_realm(
|
||||
# We use acting_user=None for setting the initial plan type.
|
||||
do_change_realm_plan_type(realm, Realm.PLAN_TYPE_LIMITED, acting_user=None)
|
||||
|
||||
if prereg_realm is not None:
|
||||
prereg_realm.status = confirmation_settings.STATUS_USED
|
||||
prereg_realm.created_realm = realm
|
||||
prereg_realm.save(update_fields=["status", "created_realm"])
|
||||
|
||||
# Send a notification to the admin realm when a new organization registers.
|
||||
if settings.CORPORATE_ENABLED:
|
||||
admin_realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
|
||||
@@ -34,6 +34,7 @@ from zerver.lib.users import (
|
||||
from zerver.models import (
|
||||
DefaultStreamGroup,
|
||||
Message,
|
||||
PreregistrationRealm,
|
||||
PreregistrationUser,
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
@@ -382,6 +383,7 @@ def do_create_user(
|
||||
default_events_register_stream: Optional[Stream] = None,
|
||||
default_all_public_streams: Optional[bool] = None,
|
||||
prereg_user: Optional[PreregistrationUser] = None,
|
||||
prereg_realm: Optional[PreregistrationRealm] = None,
|
||||
default_stream_groups: Sequence[DefaultStreamGroup] = [],
|
||||
source_profile: Optional[UserProfile] = None,
|
||||
realm_creation: bool = False,
|
||||
@@ -471,6 +473,10 @@ def do_create_user(
|
||||
"add_members", full_members_system_group, [user_profile.id]
|
||||
)
|
||||
|
||||
if prereg_realm is not None:
|
||||
prereg_realm.created_user = user_profile
|
||||
prereg_realm.save(update_fields=["created_user"])
|
||||
|
||||
if bot_type is None:
|
||||
process_new_human_user(
|
||||
user_profile,
|
||||
|
||||
@@ -17,6 +17,7 @@ from django.test import Client, override_settings
|
||||
from django.utils import translation
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from confirmation import settings as confirmation_settings
|
||||
from confirmation.models import (
|
||||
Confirmation,
|
||||
one_click_unsubscribe_link,
|
||||
@@ -76,6 +77,7 @@ from zerver.models import (
|
||||
CustomProfileFieldValue,
|
||||
DefaultStream,
|
||||
Message,
|
||||
PreregistrationRealm,
|
||||
PreregistrationUser,
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
@@ -1311,6 +1313,12 @@ class RealmCreationTest(ZulipTestCase):
|
||||
self.assertEqual(realm.emails_restricted_to_domains, False)
|
||||
self.assertEqual(realm.invite_required, True)
|
||||
|
||||
prereg_realm = PreregistrationRealm.objects.get(email=email)
|
||||
# Check created_realm and created_user field of PreregistrationRealm object
|
||||
self.assertEqual(prereg_realm.created_realm, realm)
|
||||
self.assertEqual(prereg_realm.created_user, user)
|
||||
self.assertEqual(prereg_realm.status, confirmation_settings.STATUS_USED)
|
||||
|
||||
# Check welcome messages
|
||||
for stream_name, text, message_count in [
|
||||
(Realm.DEFAULT_NOTIFICATION_STREAM_NAME, "with the topic", 3),
|
||||
@@ -1768,7 +1776,7 @@ class RealmCreationTest(ZulipTestCase):
|
||||
@override_settings(OPEN_REALM_CREATION=True)
|
||||
def test_create_two_realms(self) -> None:
|
||||
"""
|
||||
Verify correct behavior and PreregistrationUser handling when using
|
||||
Verify correct behavior and PreregistrationRealm handling when using
|
||||
two pre-generated realm creation links to create two different realms.
|
||||
"""
|
||||
password = "test"
|
||||
@@ -1803,7 +1811,7 @@ class RealmCreationTest(ZulipTestCase):
|
||||
result = self.client_get(result["Location"])
|
||||
self.assert_in_response("Check your email", result)
|
||||
first_confirmation_url = self.get_confirmation_url_from_outbox(email)
|
||||
self.assertEqual(PreregistrationUser.objects.filter(email=email, status=0).count(), 1)
|
||||
self.assertEqual(PreregistrationRealm.objects.filter(email=email, status=0).count(), 1)
|
||||
|
||||
# Get a second realm creation link.
|
||||
result = self.client_post(
|
||||
@@ -1826,7 +1834,7 @@ class RealmCreationTest(ZulipTestCase):
|
||||
second_confirmation_url = self.get_confirmation_url_from_outbox(email)
|
||||
|
||||
self.assertNotEqual(first_confirmation_url, second_confirmation_url)
|
||||
self.assertEqual(PreregistrationUser.objects.filter(email=email, status=0).count(), 2)
|
||||
self.assertEqual(PreregistrationRealm.objects.filter(email=email, status=0).count(), 2)
|
||||
|
||||
# Create and verify the first realm
|
||||
result = self.client_get(first_confirmation_url)
|
||||
@@ -1844,8 +1852,8 @@ class RealmCreationTest(ZulipTestCase):
|
||||
self.assertEqual(realm.string_id, first_string_id)
|
||||
self.assertEqual(realm.name, first_realm_name)
|
||||
|
||||
# One of the PreregistrationUsers should have been used up:
|
||||
self.assertEqual(PreregistrationUser.objects.filter(email=email, status=0).count(), 1)
|
||||
# One of the PreregistrationRealm should have been used up:
|
||||
self.assertEqual(PreregistrationRealm.objects.filter(email=email, status=0).count(), 1)
|
||||
|
||||
# Create and verify the second realm
|
||||
result = self.client_get(second_confirmation_url)
|
||||
@@ -1863,8 +1871,8 @@ class RealmCreationTest(ZulipTestCase):
|
||||
self.assertEqual(realm.string_id, second_string_id)
|
||||
self.assertEqual(realm.name, second_realm_name)
|
||||
|
||||
# The remaining PreregistrationUser should have been used up:
|
||||
self.assertEqual(PreregistrationUser.objects.filter(email=email, status=0).count(), 0)
|
||||
# The remaining PreregistrationRealm should have been used up:
|
||||
self.assertEqual(PreregistrationRealm.objects.filter(email=email, status=0).count(), 0)
|
||||
|
||||
@override_settings(OPEN_REALM_CREATION=True)
|
||||
def test_invalid_email_signup(self) -> None:
|
||||
|
||||
@@ -406,7 +406,11 @@ def registration_helper(
|
||||
realm_type = form.cleaned_data["realm_type"]
|
||||
is_demo_org = form.cleaned_data["is_demo_organization"]
|
||||
realm = do_create_realm(
|
||||
string_id, realm_name, org_type=realm_type, is_demo_organization=is_demo_org
|
||||
string_id,
|
||||
realm_name,
|
||||
org_type=realm_type,
|
||||
is_demo_organization=is_demo_org,
|
||||
prereg_realm=prereg_realm,
|
||||
)
|
||||
assert realm is not None
|
||||
|
||||
@@ -518,6 +522,7 @@ def registration_helper(
|
||||
realm,
|
||||
full_name,
|
||||
prereg_user=prereg_user,
|
||||
prereg_realm=prereg_realm,
|
||||
role=role,
|
||||
tos_version=settings.TERMS_OF_SERVICE_VERSION,
|
||||
timezone=timezone,
|
||||
|
||||
Reference in New Issue
Block a user