Fix use of case-sensitive comparisons on email addresses.

(imported from commit d420169640a9f9c034b3d9ded207e583691f6652)
This commit is contained in:
Tim Abbott
2013-02-28 16:30:46 -05:00
parent 096df2d3da
commit 1e9a85ff05
7 changed files with 19 additions and 19 deletions

View File

@@ -61,7 +61,7 @@ def get_tornado_user_profile(user_id):
@cache_with_key(lambda email: 'tornado_user_profile_email:%s' % (email,))
def get_tornado_user_profile_by_email(email):
return UserProfile.objects.select_related().get(user__email=email)
return UserProfile.objects.select_related().get(user__email__iexact=email)
# authenticated_api_view will add the authenticated user's user_profile to
# the view function's arguments list, since we have to look it up
@@ -80,7 +80,7 @@ def authenticated_api_view(view_func):
# any mutable fields (just ids plus the realm.domain)
user_profile = get_tornado_user_profile_by_email(email)
else:
user_profile = UserProfile.objects.select_related().get(user__email=email)
user_profile = UserProfile.objects.select_related().get(user__email__iexact=email)
except UserProfile.DoesNotExist:
return json_error("Invalid user: %s" % (email,))
if api_key != user_profile.api_key:

View File

@@ -87,7 +87,7 @@ def compute_mit_user_fullname(email):
@transaction.commit_on_success
def create_mit_user_if_needed(realm, email):
try:
return UserProfile.objects.get(user__email=email)
return UserProfile.objects.get(user__email__iexact=email)
except UserProfile.DoesNotExist:
try:
# Forge a user for this person
@@ -98,7 +98,7 @@ def create_mit_user_if_needed(realm, email):
# Unless we raced with another thread doing the same
# thing, in which case we should get the user they made
transaction.commit()
return UserProfile.objects.get(user__email=email)
return UserProfile.objects.get(user__email__iexact=email)
def log_message(message):
if not message.sending_client.name.startswith("test:"):
@@ -175,13 +175,13 @@ def internal_send_message(sender_email, recipient_type, recipient,
if len(content) > MAX_MESSAGE_LENGTH:
content = content[0:3900] + "\n\n[message was too long and has been truncated]"
message = Message()
message.sender = UserProfile.objects.get(user__email=sender_email)
message.sender = UserProfile.objects.get(user__email__iexact=sender_email)
if recipient_type == Recipient.STREAM:
stream, _ = create_stream_if_needed(message.sender.realm, recipient)
type_id = stream.id
else:
type_id = UserProfile.objects.get(user__email=recipient).id
type_id = UserProfile.objects.get(user__email__iexact=recipient).id
message.recipient = Recipient.objects.get(type_id=type_id, type=recipient_type)
@@ -273,7 +273,7 @@ def do_create_realm(domain, replay=False):
# Sent a notification message
message = Message()
message.sender = UserProfile.objects.get(user__email="humbug+signups@humbughq.com")
message.sender = UserProfile.objects.get(user__email__iexact="humbug+signups@humbughq.com")
stream, _ = create_stream_if_needed(message.sender.realm, "signups")
message.recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
message.subject = domain

View File

@@ -15,7 +15,7 @@ def dump():
def restore(change):
for (email, client_name, query, count, timestamp) in simplejson.loads(file("dumped-activity").read()):
user_profile = UserProfile.objects.get(user__email=email)
user_profile = UserProfile.objects.get(user__email__iexact=email)
client = get_client(client_name)
last_visit = timestamp_to_datetime(timestamp)
print "%s: activity for %s,%s" % (email, client_name, query)

View File

@@ -535,13 +535,13 @@ def restore_saved_messages():
continue
elif message_type == "user_change_full_name":
# Just handle these the slow way
user_profile = UserProfile.objects.get(user__email=old_message["user"])
user_profile = UserProfile.objects.get(user__email__iexact=old_message["user"])
user_profile.full_name = old_message["full_name"]
user_profile.save()
continue
elif message_type == "enable_desktop_notifications_changed":
# Just handle these the slow way
user_profile = UserProfile.objects.get(user__email=old_message["user"])
user_profile = UserProfile.objects.get(user__email__iexact=old_message["user"])
user_profile.enable_desktop_notifications = (old_message["enable_desktop_notifications"] != "false")
user_profile.save()
continue

View File

@@ -44,7 +44,7 @@ def should_expunge_from_log(msg, now):
user_email = msg['sender_email']
domain = domain_cache.get(user_email)
if not domain:
domain = UserProfile.objects.get(user__email=user_email).realm.domain
domain = UserProfile.objects.get(user__email__iexact=user_email).realm.domain
domain_cache[user_email] = domain
if domain not in max_age:

View File

@@ -78,7 +78,7 @@ class AuthedTestCase(TestCase):
User that has that email.
"""
# Usernames are unique, even across Realms.
return UserProfile.objects.get(user__email=email)
return UserProfile.objects.get(user__email__iexact=email)
def send_message(self, sender_name, recipient_name, message_type):
sender = self.get_user_profile(sender_name)
@@ -720,7 +720,7 @@ class SubscriptionAPITest(AuthedTestCase):
them.
"""
other_email = "iago@humbughq.com"
other_profile = UserProfile.objects.get(user__email=other_email)
other_profile = UserProfile.objects.get(user__email__iexact=other_email)
self.assertIsInstance(other_profile, UserProfile)
current_streams = self.get_streams(other_email)
self.assertNotEqual(len(current_streams), 0) # necessary for full test coverage
@@ -738,7 +738,7 @@ class SubscriptionAPITest(AuthedTestCase):
msg = Message.objects.latest('id')
self.assertEqual(msg.recipient.type, msg.recipient.PERSONAL)
self.assertEqual(msg.sender_id, UserProfile.objects.get(
user__email="humbug+notifications@humbughq.com").id)
user__email__iexact="humbug+notifications@humbughq.com").id)
expected_msg = ("Hi there! We thought you'd like to know that %s just "
"subscribed you to the stream '%s'"
% (self.user_profile.full_name, add_streams[0]))
@@ -755,7 +755,7 @@ class SubscriptionAPITest(AuthedTestCase):
invalid_principal = "rosencrantz-and-guildenstern@humbughq.com"
# verify that invalid_principal actually doesn't exist
with self.assertRaises(UserProfile.DoesNotExist):
UserProfile.objects.get(user__email=invalid_principal)
UserProfile.objects.get(user__email__iexact=invalid_principal)
result = self.client.post("/json/subscriptions/add",
{"subscriptions": simplejson.dumps(self.streams),
"principals": simplejson.dumps([invalid_principal])})
@@ -768,7 +768,7 @@ class SubscriptionAPITest(AuthedTestCase):
realm should return a JSON error.
"""
principal = "starnine@mit.edu"
profile = UserProfile.objects.get(user__email=principal)
profile = UserProfile.objects.get(user__email__iexact=principal)
# verify that principal exists (thus, the reason for the error is the cross-realming)
self.assertIsInstance(profile, UserProfile)
result = self.client.post("/json/subscriptions/add",

View File

@@ -130,7 +130,7 @@ class PrincipalError(JsonableError):
def principal_to_user_profile(agent, principal):
principal_doesnt_exist = False
try:
principal_user_profile = UserProfile.objects.get(user__email=principal)
principal_user_profile = UserProfile.objects.get(user__email__iexact=principal)
except UserProfile.DoesNotExist:
principal_doesnt_exist = True
@@ -533,7 +533,7 @@ class NarrowBuilder(object):
# Personals with other user; include both directions.
try:
narrow_profile = UserProfile.objects.get(user__email=operand)
narrow_profile = UserProfile.objects.get(user__email__iexact=operand)
except UserProfile.DoesNotExist:
raise BadNarrowOperator('unknown user ' + operand)
@@ -738,7 +738,7 @@ def create_mirrored_message_users(request, user_profile, recipients):
for email in referenced_users:
create_mit_user_if_needed(user_profile.realm, email)
sender = UserProfile.objects.get(user__email=sender_email)
sender = UserProfile.objects.get(user__email__iexact=sender_email)
return (True, sender)
def recipient_for_emails(emails, not_forged_zephyr_mirror, user_profile, sender):