mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Implement restricted namespace checks. Begin fleshing out the main hook for notifying application services.
This commit is contained in:
parent
a060b47b13
commit
f2c039bfb9
@ -17,6 +17,7 @@ from twisted.internet import defer
|
|||||||
|
|
||||||
from ._base import BaseHandler
|
from ._base import BaseHandler
|
||||||
from synapse.api.errors import Codes, StoreError, SynapseError
|
from synapse.api.errors import Codes, StoreError, SynapseError
|
||||||
|
from synapse.storage.appservice import ApplicationService
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -88,8 +89,26 @@ class ApplicationServicesHandler(BaseHandler):
|
|||||||
|
|
||||||
# Do we know this user exists? If not, poke the user query API for
|
# Do we know this user exists? If not, poke the user query API for
|
||||||
# all services which match that user regex.
|
# all services which match that user regex.
|
||||||
|
unknown_user = False # TODO check
|
||||||
|
if unknown_user:
|
||||||
|
user_query_services = self.get_services_for_event(
|
||||||
|
event=event,
|
||||||
|
restrict_to=ApplicationService.NS_USERS
|
||||||
|
)
|
||||||
|
for user_service in user_query_services:
|
||||||
|
pass # TODO poke User Query API
|
||||||
|
|
||||||
# Do we know this room alias exists? If not, poke the room alias query
|
# Do we know this room alias exists? If not, poke the room alias query
|
||||||
# API for all services which match that room alias regex.
|
# API for all services which match that room alias regex.
|
||||||
|
unknown_room_alias = False # TODO check
|
||||||
|
if unknown_room_alias:
|
||||||
|
alias_query_services = self.get_services_for_event(
|
||||||
|
event=event,
|
||||||
|
restrict_to=ApplicationService.NS_ALIASES
|
||||||
|
)
|
||||||
|
for alias_service in alias_query_services:
|
||||||
|
pass # TODO poke Room Alias Query API
|
||||||
|
|
||||||
# Fork off pushes to these services - XXX First cut, best effort
|
# Fork off pushes to these services - XXX First cut, best effort
|
||||||
|
for service in services:
|
||||||
|
pass # TODO push event to service
|
||||||
|
@ -33,6 +33,9 @@ class ApplicationService(object):
|
|||||||
NS_USERS = "users"
|
NS_USERS = "users"
|
||||||
NS_ALIASES = "aliases"
|
NS_ALIASES = "aliases"
|
||||||
NS_ROOMS = "rooms"
|
NS_ROOMS = "rooms"
|
||||||
|
# The ordering here is important as it is used to map database values (which
|
||||||
|
# are stored as ints representing the position in this list) to namespace
|
||||||
|
# values.
|
||||||
NS_LIST = [NS_USERS, NS_ALIASES, NS_ROOMS]
|
NS_LIST = [NS_USERS, NS_ALIASES, NS_ROOMS]
|
||||||
|
|
||||||
def __init__(self, token, url=None, namespaces=None):
|
def __init__(self, token, url=None, namespaces=None):
|
||||||
@ -103,13 +106,21 @@ class ApplicationService(object):
|
|||||||
"""
|
"""
|
||||||
if aliases_for_event is None:
|
if aliases_for_event is None:
|
||||||
aliases_for_event = []
|
aliases_for_event = []
|
||||||
if restrict_to not in ApplicationService.NS_LIST:
|
if restrict_to and restrict_to not in ApplicationService.NS_LIST:
|
||||||
# this is a programming error, so raise a general exception
|
# this is a programming error, so fail early and raise a general
|
||||||
|
# exception
|
||||||
raise Exception("Unexpected restrict_to value: %s". restrict_to)
|
raise Exception("Unexpected restrict_to value: %s". restrict_to)
|
||||||
|
|
||||||
|
if not restrict_to:
|
||||||
return (self._matches_user(event)
|
return (self._matches_user(event)
|
||||||
or self._matches_aliases(event, aliases_for_event)
|
or self._matches_aliases(event, aliases_for_event)
|
||||||
or self._matches_room_id(event))
|
or self._matches_room_id(event))
|
||||||
|
elif restrict_to == ApplicationService.NS_ALIASES:
|
||||||
|
return self._matches_aliases(event, aliases_for_event)
|
||||||
|
elif restrict_to == ApplicationService.NS_ROOMS:
|
||||||
|
return self._matches_room_id(event)
|
||||||
|
elif restrict_to == ApplicationService.NS_USERS:
|
||||||
|
return self._matches_user(event)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "ApplicationService: %s" % (self.__dict__,)
|
return "ApplicationService: %s" % (self.__dict__,)
|
||||||
|
Loading…
Reference in New Issue
Block a user