From a2010871e31fdec3750dfac8c9fa1cd1c5c74239 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Mon, 8 Apr 2013 12:01:01 -0400 Subject: [PATCH] Make subscription properties less free-form (imported from commit eda607c2abfa51d2dadddc7b9ecba3e2d0b5be4d) --- zephyr/lib/actions.py | 7 ++++--- zephyr/management/commands/populate_db.py | 5 +++-- zephyr/static/js/subs.js | 6 +++--- zephyr/tests.py | 22 +++++++++++----------- zephyr/views.py | 12 ++++++------ 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/zephyr/lib/actions.py b/zephyr/lib/actions.py index 4132add9f2..c1f4e54755 100644 --- a/zephyr/lib/actions.py +++ b/zephyr/lib/actions.py @@ -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()): diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index f1a6a4c5eb..877cfdb28d 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -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 diff --git a/zephyr/static/js/subs.js b/zephyr/static/js/subs.js index 2202eabe16..fe87e7560d 100644 --- a/zephyr/static/js/subs.js +++ b/zephyr/static/js/subs.js @@ -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 }); diff --git a/zephyr/tests.py b/zephyr/tests.py index 916e366b53..3348c1bee2 100644 --- a/zephyr/tests.py +++ b/zephyr/tests.py @@ -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): """ diff --git a/zephyr/views.py b/zephyr/views.py index 733005f4c9..97102c8189 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -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