registration: Create PreregistrationRealm object when creating realm.

This commit adds code to create PreregistrationRealm object when
creating realm and set it to the content_object field of
Confirmation object.
This commit is contained in:
Sahil Batra
2023-03-03 16:28:00 +05:30
committed by Tim Abbott
parent 80b00933b1
commit 54771cfe94
8 changed files with 324 additions and 79 deletions

View File

@@ -22,6 +22,7 @@ from zerver.lib.types import UnspecifiedValue
from zerver.models import (
EmailChangeStatus,
MultiuseInvite,
PreregistrationRealm,
PreregistrationUser,
Realm,
RealmReactivationStatus,
@@ -56,6 +57,7 @@ def generate_key() -> str:
ConfirmationObjT = Union[
MultiuseInvite,
PreregistrationRealm,
PreregistrationUser,
EmailChangeStatus,
UserProfile,
@@ -114,12 +116,17 @@ def create_confirmation_link(
*,
validity_in_minutes: Union[Optional[int], UnspecifiedValue] = UnspecifiedValue(),
url_args: Mapping[str, str] = {},
realm_creation: bool = False,
) -> str:
# validity_in_minutes is an override for the default values which are
# determined by the confirmation_type - its main purpose is for use
# in tests which may want to have control over the exact expiration time.
key = generate_key()
realm = obj.realm
if realm_creation:
realm = None
else:
assert not isinstance(obj, PreregistrationRealm)
realm = obj.realm
current_time = timezone_now()
expiry_date = None