mirror of https://github.com/zulip/zulip.git
Decrease code duplication in create_mirrored_message_users.
(imported from commit d299124aa1eaa9afac62278c6b98208a14d2cdb1)
This commit is contained in:
parent
411a7f6b4f
commit
5faf18754e
|
@ -476,30 +476,23 @@ def extract_recipients(request):
|
||||||
def create_mirrored_message_users(request, user_profile):
|
def create_mirrored_message_users(request, user_profile):
|
||||||
if "sender" not in request.POST:
|
if "sender" not in request.POST:
|
||||||
return (False, None)
|
return (False, None)
|
||||||
|
|
||||||
sender_email = request.POST["sender"].strip().lower()
|
sender_email = request.POST["sender"].strip().lower()
|
||||||
|
referenced_users = set([sender_email])
|
||||||
# First, check that the sender is in our realm:
|
|
||||||
if not same_realm_email(user_profile, sender_email):
|
|
||||||
return (False, None)
|
|
||||||
|
|
||||||
pm_recipients = []
|
|
||||||
if request.POST['type'] == 'private':
|
if request.POST['type'] == 'private':
|
||||||
if "to" not in request.POST:
|
for email in extract_recipients(request):
|
||||||
return (False, None)
|
referenced_users.add(email)
|
||||||
pm_recipients = extract_recipients(request)
|
|
||||||
|
|
||||||
# Then, check that all private message recipients are in our realm:
|
# Check that all referenced users are in our realm:
|
||||||
for recipient in pm_recipients:
|
for email in referenced_users:
|
||||||
if not same_realm_email(user_profile, recipient):
|
if not same_realm_email(user_profile, email):
|
||||||
return (False, None)
|
return (False, None)
|
||||||
|
|
||||||
# Create a user for the sender, if needed
|
# Create users for the referenced users, if needed.
|
||||||
sender = create_mit_user_if_needed(user_profile.realm, sender_email)
|
for email in referenced_users:
|
||||||
|
|
||||||
# Create users for private message recipients, if needed.
|
|
||||||
for email in pm_recipients:
|
|
||||||
create_mit_user_if_needed(user_profile.realm, email)
|
create_mit_user_if_needed(user_profile.realm, email)
|
||||||
|
|
||||||
|
sender = UserProfile.objects.get(user__email=sender_email)
|
||||||
return (True, sender)
|
return (True, sender)
|
||||||
|
|
||||||
# We do not @require_login for send_message_backend, since it is used
|
# We do not @require_login for send_message_backend, since it is used
|
||||||
|
|
Loading…
Reference in New Issue