Add error handling to subscription color requests.

(imported from commit b2f65feeb44abe37397de88c616fa1aa01cf8277)
This commit is contained in:
Jessica McKellar 2012-12-02 20:02:38 -05:00
parent 55e68fc89a
commit dbcd6684a2
1 changed files with 6 additions and 0 deletions

View File

@ -840,6 +840,8 @@ def json_stream_exists(request, user_profile, stream=POST):
def set_stream_color(user_profile, stream_name, color):
stream = get_stream(stream_name, user_profile.realm)
if not stream:
return json_error("Invalid stream %s" % (stream.name,))
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
subscription = Subscription.objects.filter(user_profile=user_profile,
recipient=recipient, active=True)
@ -881,7 +883,11 @@ class SubscriptionProperties(object):
def post_stream_colors(self, request, user_profile):
stream_name = self.request_property(request.POST, "stream_name")
if not stream_name:
return json_error("Missing stream_name")
color = self.request_property(request.POST, "color")
if not color:
return json_error("Missing color")
set_stream_color(user_profile, stream_name, color)
log_subscription_property_change(user_profile.user.email, "stream_color",