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