mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
Add exception handling around database lookups based on user data.
(imported from commit 4ddab2ed130ef57c967cc9364f8890a4c5b5e347)
This commit is contained in:
@@ -267,13 +267,19 @@ def get_old_messages_backend(request, anchor = POST(converter=to_non_negative_in
|
|||||||
if 'recipient_id' in narrow:
|
if 'recipient_id' in narrow:
|
||||||
query = query.filter(recipient_id = narrow['recipient_id'])
|
query = query.filter(recipient_id = narrow['recipient_id'])
|
||||||
if 'stream' in narrow:
|
if 'stream' in narrow:
|
||||||
stream = Stream.objects.get(realm=user_profile.realm, name__iexact=narrow['stream'])
|
try:
|
||||||
|
stream = Stream.objects.get(realm=user_profile.realm, name__iexact=narrow['stream'])
|
||||||
|
except Stream.DoesNotExist:
|
||||||
|
return json_error("Invalid stream %s" % (narrow['stream'],))
|
||||||
recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
|
recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
|
||||||
query = query.filter(recipient_id = recipient.id)
|
query = query.filter(recipient_id = recipient.id)
|
||||||
|
|
||||||
if 'one_on_one_email' in narrow:
|
if 'one_on_one_email' in narrow:
|
||||||
query = query.filter(recipient__type=Recipient.PERSONAL)
|
query = query.filter(recipient__type=Recipient.PERSONAL)
|
||||||
recipient_user = UserProfile.objects.get(user__email = narrow['one_on_one_email'])
|
try:
|
||||||
|
recipient_user = UserProfile.objects.get(user__email = narrow['one_on_one_email'])
|
||||||
|
except UserProfile.DoesNotExist:
|
||||||
|
return json_error("Invalid one_on_one_email %s" % (narrow['one_on_one_email'],))
|
||||||
recipient = Recipient.objects.get(type=Recipient.PERSONAL, type_id=recipient_user.id)
|
recipient = Recipient.objects.get(type=Recipient.PERSONAL, type_id=recipient_user.id)
|
||||||
# If we are narrowed to personals with ourself, we want to search for personals where the user
|
# If we are narrowed to personals with ourself, we want to search for personals where the user
|
||||||
# with address "one_on_one_email" is the sender *and* the recipient, not personals where the user
|
# with address "one_on_one_email" is the sender *and* the recipient, not personals where the user
|
||||||
|
|||||||
Reference in New Issue
Block a user