mirror of https://github.com/zulip/zulip.git
do_change_user_delivery_email: Add acting_user kwarg.
This is standard for our do_change_... functions.
This commit is contained in:
parent
5bba9b4018
commit
06fa99e87c
|
@ -109,7 +109,9 @@ def send_delivery_email_update_events(
|
|||
|
||||
|
||||
@transaction.atomic(savepoint=False)
|
||||
def do_change_user_delivery_email(user_profile: UserProfile, new_email: str) -> None:
|
||||
def do_change_user_delivery_email(
|
||||
user_profile: UserProfile, new_email: str, *, acting_user: UserProfile | None
|
||||
) -> None:
|
||||
delete_user_profile_caches([user_profile], user_profile.realm_id)
|
||||
|
||||
user_profile.delivery_email = new_email
|
||||
|
@ -140,7 +142,7 @@ def do_change_user_delivery_email(user_profile: UserProfile, new_email: str) ->
|
|||
event_time = timezone_now()
|
||||
RealmAuditLog.objects.create(
|
||||
realm=user_profile.realm,
|
||||
acting_user=user_profile,
|
||||
acting_user=acting_user,
|
||||
modified_user=user_profile,
|
||||
event_type=AuditLogEventType.USER_EMAIL_CHANGED,
|
||||
event_time=event_time,
|
||||
|
|
|
@ -317,7 +317,7 @@ class ZulipSCIMUser(SCIMUser):
|
|||
check_change_full_name(self.obj, full_name_new_value, acting_user=None)
|
||||
|
||||
if email_new_value:
|
||||
do_change_user_delivery_email(self.obj, email_new_value)
|
||||
do_change_user_delivery_email(self.obj, email_new_value, acting_user=None)
|
||||
|
||||
if role_new_value is not None:
|
||||
do_change_user_role(self.obj, role_new_value, acting_user=None)
|
||||
|
|
|
@ -24,4 +24,4 @@ class Command(ZulipBaseCommand):
|
|||
realm = self.get_realm(options)
|
||||
user_profile = self.get_user(old_email, realm)
|
||||
|
||||
do_change_user_delivery_email(user_profile, new_email)
|
||||
do_change_user_delivery_email(user_profile, new_email, acting_user=None)
|
||||
|
|
|
@ -278,7 +278,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
now = timezone_now()
|
||||
user = self.example_user("hamlet")
|
||||
new_email = "test@example.com"
|
||||
do_change_user_delivery_email(user, new_email)
|
||||
do_change_user_delivery_email(user, new_email, acting_user=user)
|
||||
self.assertEqual(
|
||||
RealmAuditLog.objects.filter(
|
||||
event_type=AuditLogEventType.USER_EMAIL_CHANGED, event_time__gte=now
|
||||
|
|
|
@ -2161,7 +2161,9 @@ class NormalActionsTest(BaseAction):
|
|||
# for email being passed into this next function.
|
||||
self.user_profile.refresh_from_db()
|
||||
with self.verify_action(num_events=2, client_gravatar=False) as events:
|
||||
do_change_user_delivery_email(self.user_profile, "newhamlet@zulip.com")
|
||||
do_change_user_delivery_email(
|
||||
self.user_profile, "newhamlet@zulip.com", acting_user=self.user_profile
|
||||
)
|
||||
|
||||
check_realm_user_update("events[0]", events[0], "delivery_email")
|
||||
check_realm_user_update("events[1]", events[1], "avatar_fields")
|
||||
|
@ -2180,7 +2182,9 @@ class NormalActionsTest(BaseAction):
|
|||
# for email being passed into this next function.
|
||||
self.user_profile.refresh_from_db()
|
||||
with self.verify_action(num_events=3, client_gravatar=False) as events:
|
||||
do_change_user_delivery_email(self.user_profile, "newhamlet@zulip.com")
|
||||
do_change_user_delivery_email(
|
||||
self.user_profile, "newhamlet@zulip.com", acting_user=self.user_profile
|
||||
)
|
||||
|
||||
check_realm_user_update("events[0]", events[0], "delivery_email")
|
||||
check_realm_user_update("events[1]", events[1], "avatar_fields")
|
||||
|
@ -2189,7 +2193,9 @@ class NormalActionsTest(BaseAction):
|
|||
assert isinstance(events[1]["person"]["avatar_url_medium"], str)
|
||||
|
||||
# Reset hamlet's email to original email.
|
||||
do_change_user_delivery_email(self.user_profile, "hamlet@zulip.com")
|
||||
do_change_user_delivery_email(
|
||||
self.user_profile, "hamlet@zulip.com", acting_user=self.user_profile
|
||||
)
|
||||
|
||||
self.set_up_db_for_testing_user_access()
|
||||
cordelia = self.example_user("cordelia")
|
||||
|
@ -2201,7 +2207,7 @@ class NormalActionsTest(BaseAction):
|
|||
)
|
||||
self.user_profile = self.example_user("polonius")
|
||||
with self.verify_action(num_events=0, state_change_expected=False):
|
||||
do_change_user_delivery_email(cordelia, "newcordelia@zulip.com")
|
||||
do_change_user_delivery_email(cordelia, "newcordelia@zulip.com", acting_user=None)
|
||||
|
||||
def test_change_realm_authentication_methods(self) -> None:
|
||||
def fake_backends() -> Any:
|
||||
|
|
|
@ -135,7 +135,7 @@ def generate_all_emails(request: HttpRequest) -> HttpResponse:
|
|||
assert result.status_code == 200
|
||||
|
||||
# Reset the email value so we can run this again
|
||||
do_change_user_delivery_email(user_profile, registered_email)
|
||||
do_change_user_delivery_email(user_profile, registered_email, acting_user=None)
|
||||
|
||||
# Initial email with new account information for normal user
|
||||
send_account_registered_email(user_profile)
|
||||
|
|
|
@ -117,7 +117,7 @@ def confirm_email_change(request: HttpRequest, confirmation_key: str) -> HttpRes
|
|||
return redirect_to_deactivation_notice()
|
||||
|
||||
validate_email_change_request(user_profile, new_email)
|
||||
do_change_user_delivery_email(user_profile, new_email)
|
||||
do_change_user_delivery_email(user_profile, new_email, acting_user=user_profile)
|
||||
|
||||
user_profile = UserProfile.objects.get(id=email_change_object.user_profile_id)
|
||||
context = {"realm_name": user_profile.realm.name, "new_email": new_email}
|
||||
|
|
Loading…
Reference in New Issue