mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
create_user: Refactor notify_created_user function.
This commit refactors the notify_created_user function to call format_user_row twice with different parameters instead of modifying the person object returned by format_user_row. This change makes the code somewhat more easy to understand than it was before.
This commit is contained in:
@@ -284,35 +284,55 @@ def process_new_human_user(
|
|||||||
|
|
||||||
def notify_created_user(user_profile: UserProfile) -> None:
|
def notify_created_user(user_profile: UserProfile) -> None:
|
||||||
user_row = user_profile_to_user_row(user_profile)
|
user_row = user_profile_to_user_row(user_profile)
|
||||||
person = format_user_row(
|
|
||||||
user_profile.realm,
|
format_user_row_kwargs: Dict[str, Any] = {
|
||||||
user_profile,
|
"realm": user_profile.realm,
|
||||||
user_row,
|
"row": user_row,
|
||||||
# Since we don't know what the client
|
# Since we don't know what the client
|
||||||
# supports at this point in the code, we
|
# supports at this point in the code, we
|
||||||
# just assume client_gravatar and
|
# just assume client_gravatar and
|
||||||
# user_avatar_url_field_optional = False :(
|
# user_avatar_url_field_optional = False :(
|
||||||
client_gravatar=False,
|
"client_gravatar": False,
|
||||||
user_avatar_url_field_optional=False,
|
"user_avatar_url_field_optional": False,
|
||||||
# We assume there's no custom profile
|
# We assume there's no custom profile
|
||||||
# field data for a new user; initial
|
# field data for a new user; initial
|
||||||
# values are expected to be added in a
|
# values are expected to be added in a
|
||||||
# later event.
|
# later event.
|
||||||
custom_profile_field_data={},
|
"custom_profile_field_data": {},
|
||||||
)
|
}
|
||||||
|
|
||||||
active_users = user_profile.realm.get_active_users()
|
active_users = user_profile.realm.get_active_users()
|
||||||
user_ids_with_real_email_access = []
|
user_ids_with_real_email_access = []
|
||||||
user_ids_without_real_email_access = []
|
user_ids_without_real_email_access = []
|
||||||
for user in active_users:
|
|
||||||
if can_access_delivery_email(user, user_profile.id, user_row["email_address_visibility"]):
|
person_for_real_email_access_users = None
|
||||||
user_ids_with_real_email_access.append(user.id)
|
person_for_without_real_email_access_users = None
|
||||||
|
for recipient_user in active_users:
|
||||||
|
if can_access_delivery_email(
|
||||||
|
recipient_user, user_profile.id, user_row["email_address_visibility"]
|
||||||
|
):
|
||||||
|
user_ids_with_real_email_access.append(recipient_user.id)
|
||||||
|
if person_for_real_email_access_users is None:
|
||||||
|
# This caller assumes that "format_user_row" only depends on
|
||||||
|
# specific value of "acting_user" among users in a realm in
|
||||||
|
# email_address_visibility.
|
||||||
|
person_for_real_email_access_users = format_user_row(
|
||||||
|
**format_user_row_kwargs,
|
||||||
|
acting_user=recipient_user,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
user_ids_without_real_email_access.append(user.id)
|
user_ids_without_real_email_access.append(recipient_user.id)
|
||||||
|
if person_for_without_real_email_access_users is None:
|
||||||
|
person_for_without_real_email_access_users = format_user_row(
|
||||||
|
**format_user_row_kwargs,
|
||||||
|
acting_user=recipient_user,
|
||||||
|
)
|
||||||
|
|
||||||
if user_ids_with_real_email_access:
|
if user_ids_with_real_email_access:
|
||||||
person["delivery_email"] = user_profile.delivery_email
|
assert person_for_real_email_access_users is not None
|
||||||
event: Dict[str, Any] = dict(type="realm_user", op="add", person=person)
|
event: Dict[str, Any] = dict(
|
||||||
|
type="realm_user", op="add", person=person_for_real_email_access_users
|
||||||
|
)
|
||||||
transaction.on_commit(
|
transaction.on_commit(
|
||||||
lambda event=event: send_event(
|
lambda event=event: send_event(
|
||||||
user_profile.realm, event, user_ids_with_real_email_access
|
user_profile.realm, event, user_ids_with_real_email_access
|
||||||
@@ -320,8 +340,8 @@ def notify_created_user(user_profile: UserProfile) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if user_ids_without_real_email_access:
|
if user_ids_without_real_email_access:
|
||||||
person["delivery_email"] = None
|
assert person_for_without_real_email_access_users is not None
|
||||||
event = dict(type="realm_user", op="add", person=person)
|
event = dict(type="realm_user", op="add", person=person_for_without_real_email_access_users)
|
||||||
transaction.on_commit(
|
transaction.on_commit(
|
||||||
lambda event=event: send_event(
|
lambda event=event: send_event(
|
||||||
user_profile.realm, event, user_ids_without_real_email_access
|
user_profile.realm, event, user_ids_without_real_email_access
|
||||||
|
|||||||
Reference in New Issue
Block a user