Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

invite: Unwrap revoke_preregistration_users.

Zixuan James Lid6f509928522
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index db66d74c462..d662606d237 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -529,9 +529,31 @@ def process_new_human_user(
),
)
- revoke_preregistration_users(user_profile, prereg_user, realm_creation)
- if not realm_creation and prereg_user is not None and prereg_user.referred_by is not None:
- notify_invites_changed(user_profile.realm)
+ if prereg_user is None:
+ assert not realm_creation, "realm_creation should only happen with a PreregistrationUser"
+
+ if prereg_user is not None:
+ prereg_user.status = confirmation_settings.STATUS_ACTIVE
+ prereg_user.save(update_fields=["status"])
+
+ # In the special case of realm creation, there can be no additional PreregistrationUser
+ # for us to want to modify - because other realm_creation PreregistrationUsers should be
+ # left usable for creating different realms.
+ if not realm_creation:
+ # Mark any other PreregistrationUsers in the realm that are STATUS_ACTIVE as
+ # inactive so we can keep track of the PreregistrationUser we
+ # actually used for analytics.
+ if prereg_user is not None:
+ PreregistrationUser.objects.filter(
+ email__iexact=user_profile.delivery_email, realm=user_profile.realm
+ ).exclude(id=prereg_user.id).update(status=confirmation_settings.STATUS_REVOKED)
+ else:
+ PreregistrationUser.objects.filter(
+ email__iexact=user_profile.delivery_email, realm=user_profile.realm
+ ).update(status=confirmation_settings.STATUS_REVOKED)
+
+ if prereg_user is not None and prereg_user.referred_by is not None:
+ notify_invites_changed(user_profile.realm)
notify_new_user(user_profile)
# Clear any scheduled invitation emails to prevent them
@@ -547,39 +569,6 @@ def process_new_human_user(
send_initial_pms(user_profile)
-def revoke_preregistration_users(
- created_user_profile: UserProfile,
- used_preregistration_user: Optional[PreregistrationUser],
- realm_creation: bool,
-) -> None:
- if used_preregistration_user is None:
- assert not realm_creation, "realm_creation should only happen with a PreregistrationUser"
-
- if used_preregistration_user is not None:
- used_preregistration_user.status = confirmation_settings.STATUS_ACTIVE
- used_preregistration_user.save(update_fields=["status"])
-
- # In the special case of realm creation, there can be no additional PreregistrationUser
- # for us to want to modify - because other realm_creation PreregistrationUsers should be
- # left usable for creating different realms.
- if realm_creation:
- return
-
- # Mark any other PreregistrationUsers in the realm that are STATUS_ACTIVE as
- # inactive so we can keep track of the PreregistrationUser we
- # actually used for analytics.
- if used_preregistration_user is not None:
- PreregistrationUser.objects.filter(
- email__iexact=created_user_profile.delivery_email, realm=created_user_profile.realm
- ).exclude(id=used_preregistration_user.id).update(
- status=confirmation_settings.STATUS_REVOKED
- )
- else:
- PreregistrationUser.objects.filter(
- email__iexact=created_user_profile.delivery_email, realm=created_user_profile.realm
- ).update(status=confirmation_settings.STATUS_REVOKED)
-
-
def notify_created_user(user_profile: UserProfile) -> None:
user_row = user_profile_to_user_row(user_profile)
person = format_user_row(