mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 19:49:25 -05:00
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)
|
super(ApplicationServicesHandler, self).__init__(hs)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def register(self, base_url, token, namespaces):
|
def register(self, app_service):
|
||||||
# check the token is recognised
|
# check the token is recognised
|
||||||
try:
|
try:
|
||||||
app_service = yield self.store.get_app_service(token)
|
stored_service = yield self.store.get_app_service(app_service.token)
|
||||||
if not app_service:
|
if not stored_service:
|
||||||
raise StoreError
|
raise StoreError(404, "Not found")
|
||||||
except StoreError:
|
except StoreError:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
403, "Unrecognised application services token. "
|
403, "Unrecognised application services token. "
|
||||||
"Consult the home server admin."
|
"Consult the home server admin."
|
||||||
)
|
)
|
||||||
|
# TODO store this AS
|
||||||
# store this AS
|
|
||||||
|
|
||||||
defer.returnValue("not_implemented_yet")
|
|
||||||
|
|
||||||
def unregister(self, token):
|
def unregister(self, token):
|
||||||
yield self.store.unregister_app_service(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 base import AppServiceRestServlet, as_path_pattern
|
||||||
from synapse.api.errors import CodeMessageException, SynapseError
|
from synapse.api.errors import CodeMessageException, SynapseError
|
||||||
|
from synapse.storage.appservice import ApplicationService
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@ -58,7 +59,10 @@ class RegisterRestServlet(AppServiceRestServlet):
|
|||||||
self._parse_namespace(namespaces, params["namespaces"], "rooms")
|
self._parse_namespace(namespaces, params["namespaces"], "rooms")
|
||||||
self._parse_namespace(namespaces, params["namespaces"], "aliases")
|
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({
|
defer.returnValue({
|
||||||
"hs_token": hs_token
|
"hs_token": hs_token
|
||||||
@ -97,7 +101,7 @@ class UnregisterRestServlet(AppServiceRestServlet):
|
|||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
raise SynapseError(400, "Missing required key: as_token(str)")
|
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")
|
raise CodeMessageException(500, "Not implemented")
|
||||||
|
|
||||||
|
@ -116,8 +116,7 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
def get_services_for_event(self, event):
|
def get_services_for_event(self, event):
|
||||||
return self.cache.get_services_for_event(event)
|
return self.cache.get_services_for_event(event)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
def get_app_service(self, token, from_cache=True):
|
||||||
def get_app_service(self, as_token, from_cache=True):
|
|
||||||
"""Get the application service with the given token.
|
"""Get the application service with the given token.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -130,21 +129,18 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
|
|
||||||
if from_cache:
|
if from_cache:
|
||||||
for service in self.cache.services:
|
for service in self.cache.services:
|
||||||
if service.token == as_token:
|
if service.token == token:
|
||||||
defer.returnValue(service)
|
return service
|
||||||
return
|
return None
|
||||||
defer.returnValue(None)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: This should be JOINed with the application_services_regex table.
|
# TODO: This should be JOINed with the application_services_regex table.
|
||||||
row = self._simple_select_one(
|
row = self._simple_select_one(
|
||||||
"application_services", {"token": as_token},
|
"application_services", {"token": token},
|
||||||
["url", "token"]
|
["url", "token"]
|
||||||
)
|
)
|
||||||
if not row:
|
if not row:
|
||||||
raise StoreError(400, "Bad application services token supplied.")
|
raise StoreError(400, "Bad application services token supplied.")
|
||||||
defer.returnValue(row)
|
return row
|
||||||
|
|
||||||
def _populate_cache(self):
|
def _populate_cache(self):
|
||||||
"""Populates the ApplicationServiceCache from the database."""
|
"""Populates the ApplicationServiceCache from the database."""
|
||||||
|
Loading…
Reference in New Issue
Block a user