From 8a76094965635eb2afd501038ea3c09f88416ce2 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 11 Apr 2016 18:00:03 +0100 Subject: Add get endpoint for pushers As per https://github.com/matrix-org/matrix-doc/pull/308 --- synapse/rest/client/v1/pusher.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'synapse/rest') diff --git a/synapse/rest/client/v1/pusher.py b/synapse/rest/client/v1/pusher.py index 9881f068c3..5c88a9ba09 100644 --- a/synapse/rest/client/v1/pusher.py +++ b/synapse/rest/client/v1/pusher.py @@ -27,14 +27,47 @@ logger = logging.getLogger(__name__) class PusherRestServlet(ClientV1RestServlet): - PATTERNS = client_path_patterns("/pushers/set$") + PATTERNS = client_path_patterns("/pushers(/set)?$") def __init__(self, hs): super(PusherRestServlet, self).__init__(hs) self.notifier = hs.get_notifier() + @defer.inlineCallbacks + def on_GET(self, request): + if request.postpath != ["pushers"]: + defer.returnValue((405, {})) + + requester = yield self.auth.get_user_by_req(request) + user = requester.user + + pushers = yield self.hs.get_datastore().get_pushers_by_app_user_id( + user.to_string() + ) + + allowed_keys = [ + "app_display_name", + "app_id", + "data", + "device_display_name", + "kind", + "lang", + "profile_tag", + "pushkey", + ] + + for p in pushers: + for k, v in p.items(): + if k not in allowed_keys: + del p[k] + + defer.returnValue((200, {"pushers": pushers})) + @defer.inlineCallbacks def on_POST(self, request): + if request.postpath != ["pushers", "set"]: + defer.returnValue((405, {})) + requester = yield self.auth.get_user_by_req(request) user = requester.user -- cgit 1.4.1 From d937f342bb223111a9cd6b2c4a8f0544e1a810a5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 13:33:30 +0100 Subject: Split into separate servlet classes --- synapse/rest/client/v1/pusher.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'synapse/rest') diff --git a/synapse/rest/client/v1/pusher.py b/synapse/rest/client/v1/pusher.py index 5c88a9ba09..321eadbc24 100644 --- a/synapse/rest/client/v1/pusher.py +++ b/synapse/rest/client/v1/pusher.py @@ -26,18 +26,14 @@ import logging logger = logging.getLogger(__name__) -class PusherRestServlet(ClientV1RestServlet): - PATTERNS = client_path_patterns("/pushers(/set)?$") +class PushersRestServlet(ClientV1RestServlet): + PATTERNS = client_path_patterns("/pushers$") def __init__(self, hs): - super(PusherRestServlet, self).__init__(hs) - self.notifier = hs.get_notifier() + super(PushersRestServlet, self).__init__(hs) @defer.inlineCallbacks def on_GET(self, request): - if request.postpath != ["pushers"]: - defer.returnValue((405, {})) - requester = yield self.auth.get_user_by_req(request) user = requester.user @@ -63,11 +59,19 @@ class PusherRestServlet(ClientV1RestServlet): defer.returnValue((200, {"pushers": pushers})) + def on_OPTIONS(self, _): + return 200, {} + + +class PushersSetRestServlet(ClientV1RestServlet): + PATTERNS = client_path_patterns("/pushers(/set)?$") + + def __init__(self, hs): + super(PushersSetRestServlet, self).__init__(hs) + self.notifier = hs.get_notifier() + @defer.inlineCallbacks def on_POST(self, request): - if request.postpath != ["pushers", "set"]: - defer.returnValue((405, {})) - requester = yield self.auth.get_user_by_req(request) user = requester.user @@ -133,4 +137,5 @@ class PusherRestServlet(ClientV1RestServlet): def register_servlets(hs, http_server): - PusherRestServlet(hs).register(http_server) + PushersRestServlet(hs).register(http_server) + PushersSetRestServlet(hs).register(http_server) -- cgit 1.4.1 From 7b39bcdaae70e3a167d38bb1cdf8e6d4d95f0cca Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 13:35:08 +0100 Subject: Mis-named function --- synapse/rest/client/v1/pusher.py | 2 +- synapse/storage/pusher.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'synapse/rest') diff --git a/synapse/rest/client/v1/pusher.py b/synapse/rest/client/v1/pusher.py index 321eadbc24..d792dac648 100644 --- a/synapse/rest/client/v1/pusher.py +++ b/synapse/rest/client/v1/pusher.py @@ -37,7 +37,7 @@ class PushersRestServlet(ClientV1RestServlet): requester = yield self.auth.get_user_by_req(request) user = requester.user - pushers = yield self.hs.get_datastore().get_pushers_by_app_user_id( + pushers = yield self.hs.get_datastore().get_pushers_by_user_id( user.to_string() ) diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py index 11feab72de..90ec06809a 100644 --- a/synapse/storage/pusher.py +++ b/synapse/storage/pusher.py @@ -76,7 +76,7 @@ class PusherStore(SQLBaseStore): defer.returnValue(rows) @defer.inlineCallbacks - def get_pushers_by_app_user_id(self, user_id): + def get_pushers_by_user_id(self, user_id): def r(txn): sql = ( "SELECT * FROM pushers" -- cgit 1.4.1 From a04c076b7f72bc4a3ba5605abf6b10ac682826be Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 12 Apr 2016 13:54:41 +0100 Subject: Make the /set part mandatory --- synapse/rest/client/v1/pusher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'synapse/rest') diff --git a/synapse/rest/client/v1/pusher.py b/synapse/rest/client/v1/pusher.py index d792dac648..ab928a16da 100644 --- a/synapse/rest/client/v1/pusher.py +++ b/synapse/rest/client/v1/pusher.py @@ -64,7 +64,7 @@ class PushersRestServlet(ClientV1RestServlet): class PushersSetRestServlet(ClientV1RestServlet): - PATTERNS = client_path_patterns("/pushers(/set)?$") + PATTERNS = client_path_patterns("/pushers/set$") def __init__(self, hs): super(PushersSetRestServlet, self).__init__(hs) -- cgit 1.4.1