mirror of
https://github.com/zulip/zulip.git
synced 2026-07-15 21:03:26 +08:00
Make subscription properties less free-form
(imported from commit eda607c2abfa51d2dadddc7b9ecba3e2d0b5be4d)
This commit is contained in:
parent
da8fa73a92
commit
a2010871e3
@ -478,11 +478,12 @@ def do_remove_subscription(user_profile, stream, no_log=False):
|
||||
|
||||
return did_remove
|
||||
|
||||
def log_subscription_property_change(user_email, property, property_dict):
|
||||
def log_subscription_property_change(user_email, stream_name, property, value):
|
||||
event = {'type': 'subscription_property',
|
||||
'property': property,
|
||||
'user': user_email}
|
||||
event.update(property_dict)
|
||||
'user': user_email,
|
||||
'stream_name': stream_name,
|
||||
'value': value}
|
||||
log_event(event)
|
||||
|
||||
def do_activate_user(user_profile, log=True, join_date=timezone.now()):
|
||||
|
||||
@ -554,9 +554,10 @@ def restore_saved_messages():
|
||||
continue
|
||||
elif message_type == "subscription_property":
|
||||
property_name = old_message.get("property")
|
||||
if property_name == "stream_color":
|
||||
if property_name == "stream_color" or property_name == "color":
|
||||
color = old_message.get("color", old_message["value"])
|
||||
pending_colors[(old_message["user"],
|
||||
old_message["stream_name"].lower())] = old_message["color"]
|
||||
old_message["stream_name"].lower())] = color
|
||||
else:
|
||||
raise RuntimeError("Unknown property %s" % (property_name,))
|
||||
continue
|
||||
|
||||
@ -186,7 +186,7 @@ function stream_home_view_clicked(e) {
|
||||
data: {
|
||||
"property": "in_home_view",
|
||||
"stream_name": stream,
|
||||
"in_home_view": in_home_view
|
||||
"value": in_home_view
|
||||
},
|
||||
timeout: 10*1000
|
||||
});
|
||||
@ -200,9 +200,9 @@ function set_color(stream_name, color) {
|
||||
url: '/json/subscriptions/property',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
"property": "stream_colors",
|
||||
"property": "color",
|
||||
"stream_name": stream_name,
|
||||
"color": color
|
||||
"value": color
|
||||
},
|
||||
timeout: 10*1000
|
||||
});
|
||||
|
||||
@ -606,16 +606,16 @@ class MessagePOSTTest(AuthedTestCase):
|
||||
class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
fixtures = ['messages.json']
|
||||
|
||||
def test_get_stream_colors(self):
|
||||
def test_get_stream_color(self):
|
||||
"""
|
||||
A GET request to
|
||||
/json/subscriptions/property?property=stream_colors returns a
|
||||
/json/subscriptions/property?property=color returns a
|
||||
list of (stream, color) pairs, both of which are strings.
|
||||
"""
|
||||
test_email = "hamlet@humbughq.com"
|
||||
self.login(test_email)
|
||||
result = self.client.get("/json/subscriptions/property",
|
||||
{"property": "stream_colors"})
|
||||
{"property": "color"})
|
||||
|
||||
self.assert_json_success(result)
|
||||
json = simplejson.loads(result.content)
|
||||
@ -644,9 +644,9 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
invite_only = sub['invite_only']
|
||||
new_color = "#ffffff" # TODO: ensure that this is different from old_color
|
||||
result = self.client.post("/json/subscriptions/property",
|
||||
{"property": "stream_colors",
|
||||
{"property": "color",
|
||||
"stream_name": stream_name,
|
||||
"color": "#ffffff"})
|
||||
"value": "#ffffff"})
|
||||
|
||||
self.assert_json_success(result)
|
||||
|
||||
@ -659,27 +659,27 @@ class SubscriptionPropertiesTest(AuthedTestCase):
|
||||
|
||||
def test_set_color_missing_stream_name(self):
|
||||
"""
|
||||
Updating the stream_colors property requires a stream_name.
|
||||
Updating the color property requires a stream_name.
|
||||
"""
|
||||
test_email = "hamlet@humbughq.com"
|
||||
self.login(test_email)
|
||||
result = self.client.post("/json/subscriptions/property",
|
||||
{"property": "stream_colors",
|
||||
"color": "#ffffff"})
|
||||
{"property": "color",
|
||||
"value": "#ffffff"})
|
||||
|
||||
self.assert_json_error(result, "Missing 'stream_name' argument")
|
||||
|
||||
def test_set_color_missing_color(self):
|
||||
"""
|
||||
Updating the stream_colors property requires a color.
|
||||
Updating the color property requires a color.
|
||||
"""
|
||||
test_email = "hamlet@humbughq.com"
|
||||
self.login(test_email)
|
||||
result = self.client.post("/json/subscriptions/property",
|
||||
{"property": "stream_colors",
|
||||
{"property": "color",
|
||||
"stream_name": "test"})
|
||||
|
||||
self.assert_json_error(result, "Missing 'color' argument")
|
||||
self.assert_json_error(result, "Missing 'value' argument")
|
||||
|
||||
def test_set_invalid_property(self):
|
||||
"""
|
||||
|
||||
@ -1171,21 +1171,21 @@ class SubscriptionProperties(object):
|
||||
except KeyError:
|
||||
raise RequestVariableMissingError(property)
|
||||
|
||||
def get_stream_colors(self, request, user_profile):
|
||||
def get_color(self, request, user_profile):
|
||||
return json_success({"stream_colors": get_stream_colors(user_profile)})
|
||||
|
||||
def post_stream_colors(self, request, user_profile):
|
||||
def post_color(self, request, user_profile):
|
||||
stream_name = self.request_property(request.POST, "stream_name")
|
||||
color = self.request_property(request.POST, "color")
|
||||
color = self.request_property(request.POST, "value")
|
||||
|
||||
set_stream_color(user_profile, stream_name, color)
|
||||
log_subscription_property_change(user_profile.email, "stream_color",
|
||||
{"stream_name": stream_name, "color": color})
|
||||
log_subscription_property_change(user_profile.email, stream_name,
|
||||
"color", color)
|
||||
return json_success()
|
||||
|
||||
def post_in_home_view(self, request, user_profile):
|
||||
stream_name = self.request_property(request.POST, "stream_name")
|
||||
value = self.request_property(request.POST, "in_home_view").lower()
|
||||
value = self.request_property(request.POST, "value").lower()
|
||||
|
||||
if value == "true":
|
||||
value = True
|
||||
|
||||
Loading…
Reference in New Issue
Block a user