users: Always pass delivery_email in user's own object.

This commit changes the code to always pass delivery_email
field in the user's own object in 'realm_users'.

This commit also fixes the events sent by notify_created_user.
In the "realm_user/add" event sent when creating the user,
the delivery_email field was set according to the access
for the created user itself as the created user was passed as
acting_user to format_user_row. But now since we have changed
the code to always allow the user themselves to have access
to the email, this bug was caught in tests and we fix the person
object in the event to have delivery_email field based on whether
the user receiving the event has access to email or not.
This commit is contained in:
Sahil Batra
2021-12-11 12:47:57 +05:30
committed by Tim Abbott
parent aa98b39429
commit 9a6886f630
7 changed files with 62 additions and 21 deletions

View File

@@ -394,7 +394,12 @@ def validate_user_custom_profile_data(
raise JsonableError(error.message)
def can_access_delivery_email(user_profile: UserProfile, email_address_visibility: int) -> bool:
def can_access_delivery_email(
user_profile: UserProfile, target_user_id: int, email_address_visibility: int
) -> bool:
if target_user_id == user_profile.id:
return True
if email_address_visibility == Realm.EMAIL_ADDRESS_VISIBILITY_ADMINS:
return user_profile.is_realm_admin
@@ -477,7 +482,7 @@ def format_user_row(
)
if acting_user is not None and can_access_delivery_email(
acting_user, realm.email_address_visibility
acting_user, row["id"], realm.email_address_visibility
):
result["delivery_email"] = row["delivery_email"]