Use ApplicationService when registering.
This commit is contained in:
parent
92171f9dd1
commit
ec3719b583
|
@ -30,21 +30,18 @@ class ApplicationServicesHandler(BaseHandler):
|
|||
super(ApplicationServicesHandler, self).__init__(hs)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def register(self, base_url, token, namespaces):
|
||||
def register(self, app_service):
|
||||
# check the token is recognised
|
||||
try:
|
||||
app_service = yield self.store.get_app_service(token)
|
||||
if not app_service:
|
||||
raise StoreError
|
||||
stored_service = yield self.store.get_app_service(app_service.token)
|
||||
if not stored_service:
|
||||
raise StoreError(404, "Not found")
|
||||
except StoreError:
|
||||
raise SynapseError(
|
||||
403, "Unrecognised application services token. "
|
||||
"Consult the home server admin."
|
||||
)
|
||||
|
||||
# store this AS
|
||||
|
||||
defer.returnValue("not_implemented_yet")
|
||||
# TODO store this AS
|
||||
|
||||
def unregister(self, token):
|
||||
yield self.store.unregister_app_service(token)
|
||||
|
|
|
@ -18,6 +18,7 @@ from twisted.internet import defer
|
|||
|
||||
from base import AppServiceRestServlet, as_path_pattern
|
||||
from synapse.api.errors import CodeMessageException, SynapseError
|
||||
from synapse.storage.appservice import ApplicationService
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
@ -58,7 +59,10 @@ class RegisterRestServlet(AppServiceRestServlet):
|
|||
self._parse_namespace(namespaces, params["namespaces"], "rooms")
|
||||
self._parse_namespace(namespaces, params["namespaces"], "aliases")
|
||||
|
||||
hs_token = yield self.handler.register(as_url, as_token, namespaces)
|
||||
app_service = ApplicationService(as_token, as_url, namespaces)
|
||||
|
||||
yield self.handler.register(app_service)
|
||||
hs_token = "_not_implemented_yet" # TODO: Pull this from self.hs?
|
||||
|
||||
defer.returnValue({
|
||||
"hs_token": hs_token
|
||||
|
@ -97,7 +101,7 @@ class UnregisterRestServlet(AppServiceRestServlet):
|
|||
except (KeyError, ValueError):
|
||||
raise SynapseError(400, "Missing required key: as_token(str)")
|
||||
|
||||
# TODO: pass to the appservice handler
|
||||
yield self.handler.unregister(as_token)
|
||||
|
||||
raise CodeMessageException(500, "Not implemented")
|
||||
|
||||
|
|
|
@ -116,8 +116,7 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||
def get_services_for_event(self, event):
|
||||
return self.cache.get_services_for_event(event)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_app_service(self, as_token, from_cache=True):
|
||||
def get_app_service(self, token, from_cache=True):
|
||||
"""Get the application service with the given token.
|
||||
|
||||
Args:
|
||||
|
@ -130,21 +129,18 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||
|
||||
if from_cache:
|
||||
for service in self.cache.services:
|
||||
if service.token == as_token:
|
||||
defer.returnValue(service)
|
||||
return
|
||||
defer.returnValue(None)
|
||||
return
|
||||
|
||||
if service.token == token:
|
||||
return service
|
||||
return None
|
||||
|
||||
# TODO: This should be JOINed with the application_services_regex table.
|
||||
row = self._simple_select_one(
|
||||
"application_services", {"token": as_token},
|
||||
"application_services", {"token": token},
|
||||
["url", "token"]
|
||||
)
|
||||
if not row:
|
||||
raise StoreError(400, "Bad application services token supplied.")
|
||||
defer.returnValue(row)
|
||||
return row
|
||||
|
||||
def _populate_cache(self):
|
||||
"""Populates the ApplicationServiceCache from the database."""
|
||||
|
|
Loading…
Reference in New Issue