diff options
author | David Baker <dave@matrix.org> | 2016-04-11 18:00:03 +0100 |
---|---|---|
committer | David Baker <dave@matrix.org> | 2016-04-11 18:00:03 +0100 |
commit | 8a76094965635eb2afd501038ea3c09f88416ce2 (patch) | |
tree | 3db97ac123d3251fe98b63be29c37509a5f8b04d | |
parent | Fix the rule_id for .m.rule.invite_for_me (#715) (diff) | |
download | synapse-8a76094965635eb2afd501038ea3c09f88416ce2.tar.xz |
Add get endpoint for pushers
As per https://github.com/matrix-org/matrix-doc/pull/308
-rw-r--r-- | synapse/rest/client/v1/pusher.py | 35 | ||||
-rw-r--r-- | synapse/storage/pusher.py | 19 |
2 files changed, 53 insertions, 1 deletions
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 diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py index 19888a8e76..11feab72de 100644 --- a/synapse/storage/pusher.py +++ b/synapse/storage/pusher.py @@ -76,6 +76,25 @@ class PusherStore(SQLBaseStore): defer.returnValue(rows) @defer.inlineCallbacks + def get_pushers_by_app_user_id(self, user_id): + def r(txn): + sql = ( + "SELECT * FROM pushers" + " WHERE user_name = ?" + ) + + txn.execute(sql, (user_id,)) + rows = self.cursor_to_dict(txn) + + return self._decode_pushers_rows(rows) + + result = yield self.runInteraction( + "get_pushers_by_user_id", r + ) + + defer.returnValue(result) + + @defer.inlineCallbacks def get_all_pushers(self): def get_pushers(txn): txn.execute("SELECT * FROM pushers") |