registration: Improve error handling for source_realm_id.

This restores the previous behavior that we store None rather than
throwing an exception in the presence of invalid input.
This commit is contained in:
Tim Abbott
2021-04-19 18:21:29 -07:00
parent 55da3329ef
commit 97b08b77df
2 changed files with 10 additions and 4 deletions

View File

@@ -3748,6 +3748,7 @@ class UserSignUpTest(InviteUserBase):
result = self.submit_reg_form_for_user(
email,
password,
# Subdomain is already used, by construction.
realm_subdomain=realm.string_id,
realm_name=realm_name,
source_realm_id=str(realm.id),

View File

@@ -311,10 +311,15 @@ def accounts_register(request: HttpRequest) -> HttpResponse:
if "timezone" in request.POST and request.POST["timezone"] in pytz.all_timezones_set:
timezone = request.POST["timezone"]
if "source_realm_id" in request.POST and request.POST["source_realm_id"] != "":
source_profile: Optional[UserProfile] = get_source_profile(
email, int(request.POST["source_realm_id"])
)
if "source_realm_id" in request.POST:
# Non-integer realm_id values like "string" are treated
# like the "Do not import" value of "".
try:
source_realm_id = int(request.POST["source_realm_id"])
except ValueError:
source_profile: Optional[UserProfile] = None
else:
source_profile = get_source_profile(email, source_realm_id)
else:
source_profile = None