Add get_emails_from_user_ids() action.

(imported from commit 887090de16f685373bd2f3548bd1ec94a7ad4a9e)
This commit is contained in:
Steve Howell
2013-10-20 15:10:03 -04:00
parent 4a53a6680e
commit 58acef4098
3 changed files with 18 additions and 1 deletions

View File

@@ -2034,6 +2034,10 @@ def do_set_muted_topics(user_profile, muted_topics):
users=[user_profile.id]) users=[user_profile.id])
tornado_callbacks.send_notification(notice) tornado_callbacks.send_notification(notice)
def get_emails_from_user_ids(user_ids):
# We may eventually use memcached to speed this up, but the DB is fast.
return UserProfile.emails_from_ids(user_ids)
@uses_mandrill @uses_mandrill
def clear_followup_emails_queue(email, from_email=None, mail_client=None): def clear_followup_emails_queue(email, from_email=None, mail_client=None):
""" """

View File

@@ -251,6 +251,11 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
def __str__(self): def __str__(self):
return self.__repr__() return self.__repr__()
@staticmethod
def emails_from_ids(user_ids):
rows = UserProfile.objects.filter(id__in=user_ids).values('id', 'email')
return {row['id']: row['email'] for row in rows}
# Make sure we flush the UserProfile object from our memcached # Make sure we flush the UserProfile object from our memcached
# whenever we save it. # whenever we save it.
post_save.connect(update_user_profile_cache, sender=UserProfile) post_save.connect(update_user_profile_cache, sender=UserProfile)

View File

@@ -19,7 +19,7 @@ from zerver.lib.initial_password import initial_password
from zerver.lib.actions import check_send_message, gather_subscriptions, \ from zerver.lib.actions import check_send_message, gather_subscriptions, \
create_stream_if_needed, do_add_subscription, compute_mit_user_fullname, \ create_stream_if_needed, do_add_subscription, compute_mit_user_fullname, \
do_add_realm_emoji, do_remove_realm_emoji, check_message, do_create_user, \ do_add_realm_emoji, do_remove_realm_emoji, check_message, do_create_user, \
set_default_streams set_default_streams, get_emails_from_user_ids
from zerver.lib.rate_limiter import add_ratelimit_rule, remove_ratelimit_rule from zerver.lib.rate_limiter import add_ratelimit_rule, remove_ratelimit_rule
from zerver.lib import bugdown from zerver.lib import bugdown
from zerver.lib import cache from zerver.lib import cache
@@ -407,6 +407,14 @@ class ActivityTest(AuthedTestCase):
# We have 8 tabs, and one query per tab. # We have 8 tabs, and one query per tab.
self.assertEqual(len(queries), 8) self.assertEqual(len(queries), 8)
class UserProfileTest(TestCase):
def test_get_emails_from_user_ids(self):
hamlet = get_user_profile_by_email('hamlet@zulip.com')
othello = get_user_profile_by_email('othello@zulip.com')
dct = get_emails_from_user_ids([hamlet.id, othello.id])
self.assertEqual(dct[hamlet.id], 'hamlet@zulip.com')
self.assertEqual(dct[othello.id], 'othello@zulip.com')
class PublicURLTest(TestCase): class PublicURLTest(TestCase):
""" """
Account creation URLs are accessible even when not logged in. Authenticated Account creation URLs are accessible even when not logged in. Authenticated