Replace settings.OG_ZULIPER_EMAILS with database lookups

Also renames the OG_ZULIPER_EMAILS to CROSS_REALM_BOT_EMAILS

(imported from commit a9e0ccebbd6b37376e535600670ad493dc8de7e1)
This commit is contained in:
acrefoot
2015-08-20 01:15:41 -07:00
parent 53c2b3f6f4
commit 0a6bb975c3
3 changed files with 12 additions and 8 deletions

View File

@@ -597,8 +597,13 @@ def recipient_for_emails(emails, not_forged_mirror_message,
# Prevent cross realm private messages unless it is between only two realms
# and one of users is a zuliper
if len(realm_domains) == 2 and not (normalized_emails & settings.OG_ZULIPER_EMAILS):
raise ValidationError("You can't send private messages outside of your organization.")
if len(realm_domains) == 2:
# I'm assuming that cross-realm PMs with the "admin realm" are rare, and therefore can be slower
admin_realm = Realm.objects.get(domain=settings.ADMIN_DOMAIN)
admin_realm_admin_emails = [u.email for u in admin_realm.get_admin_users()]
# We allow settings.CROSS_REALM_BOT_EMAILS for the hardcoded emails for the feedback and notification bots
if not (normalized_emails & admin_realm_admin_emails or normalized_emails & settings.CROSS_REALM_BOT_EMAILS):
raise ValidationError("You can't send private messages outside of your organization.")
if len(realm_domains) > 2:
raise ValidationError("You can't send private messages outside of your organization.")