mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 02:17:19 +00:00
Factor out subscription retrieval code into another function.
(imported from commit 6a66a4feb03990e11c98cd8666d1a7bb97299987)
This commit is contained in:
@@ -1099,16 +1099,22 @@ def json_stream_exists(request, user_profile, stream=POST):
|
||||
active=True).exists()
|
||||
return json_success(result)
|
||||
|
||||
def set_stream_color(user_profile, stream_name, color):
|
||||
def get_subscription_or_die(stream_name, user_profile):
|
||||
stream = get_stream(stream_name, user_profile.realm)
|
||||
if not stream:
|
||||
raise JsonableError("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)
|
||||
|
||||
if not subscription.exists():
|
||||
raise JsonableError("Not subscribed to stream %s" % (stream_name,))
|
||||
|
||||
return subscription
|
||||
|
||||
def set_stream_color(user_profile, stream_name, color):
|
||||
subscription = get_subscription_or_die(stream_name, user_profile)
|
||||
|
||||
stream_color, _ = StreamColor.objects.get_or_create(subscription=subscription[0])
|
||||
# TODO: sanitize color.
|
||||
stream_color.color = color
|
||||
|
||||
Reference in New Issue
Block a user