Oops: second part of commit dc938606

This commit is contained in:
David Baker 2015-01-22 17:38:53 +00:00
parent dc93860619
commit ede491b4e0
6 changed files with 45 additions and 7 deletions

View File

@ -21,6 +21,7 @@ logger = logging.getLogger(__name__)
class Codes(object): class Codes(object):
UNRECOGNIZED = "M_UNRECOGNIZED"
UNAUTHORIZED = "M_UNAUTHORIZED" UNAUTHORIZED = "M_UNAUTHORIZED"
FORBIDDEN = "M_FORBIDDEN" FORBIDDEN = "M_FORBIDDEN"
BAD_JSON = "M_BAD_JSON" BAD_JSON = "M_BAD_JSON"
@ -82,6 +83,17 @@ class RegistrationError(SynapseError):
pass pass
class UnrecognizedRequestError(SynapseError):
"""An error indicating we don't understand the request you're trying to make"""
def __init__(self, *args, **kwargs):
if "errcode" not in kwargs:
kwargs["errcode"] = Codes.NOT_FOUND
super(UnrecognizedRequestError, self).__init__(
400,
"Unrecognized request",
**kwargs
)
class AuthError(SynapseError): class AuthError(SynapseError):
"""An error raised when there was a problem authorising an event.""" """An error raised when there was a problem authorising an event."""

View File

@ -16,7 +16,7 @@
from synapse.http.agent_name import AGENT_NAME from synapse.http.agent_name import AGENT_NAME
from synapse.api.errors import ( from synapse.api.errors import (
cs_exception, SynapseError, CodeMessageException cs_exception, SynapseError, CodeMessageException, UnrecognizedRequestError
) )
from synapse.util.logcontext import LoggingContext from synapse.util.logcontext import LoggingContext
@ -139,11 +139,7 @@ class JsonResource(HttpServer, resource.Resource):
return return
# Huh. No one wanted to handle that? Fiiiiiine. Send 400. # Huh. No one wanted to handle that? Fiiiiiine. Send 400.
self._send_response( raise UnrecognizedRequestError()
request,
400,
{"error": "Unrecognized request"}
)
except CodeMessageException as e: except CodeMessageException as e:
if isinstance(e, SynapseError): if isinstance(e, SynapseError):
logger.info("%s SynapseError: %s - %s", request, e.code, e.msg) logger.info("%s SynapseError: %s - %s", request, e.code, e.msg)

View File

@ -16,7 +16,7 @@
from . import ( from . import (
room, events, register, login, profile, presence, initial_sync, directory, room, events, register, login, profile, presence, initial_sync, directory,
voip, admin, pusher, voip, admin, pusher, push_rule
) )
@ -46,3 +46,4 @@ class RestServletFactory(object):
voip.register_servlets(hs, client_resource) voip.register_servlets(hs, client_resource)
admin.register_servlets(hs, client_resource) admin.register_servlets(hs, client_resource)
pusher.register_servlets(hs, client_resource) pusher.register_servlets(hs, client_resource)
push_rule.register_servlets(hs, client_resource)

View File

@ -30,6 +30,7 @@ from .transactions import TransactionStore
from .keys import KeyStore from .keys import KeyStore
from .event_federation import EventFederationStore from .event_federation import EventFederationStore
from .pusher import PusherStore from .pusher import PusherStore
from .push_rule import PushRuleStore
from .media_repository import MediaRepositoryStore from .media_repository import MediaRepositoryStore
from .state import StateStore from .state import StateStore
@ -62,6 +63,7 @@ SCHEMAS = [
"event_edges", "event_edges",
"event_signatures", "event_signatures",
"pusher", "pusher",
"push_rules",
"media_repository", "media_repository",
] ]
@ -85,6 +87,7 @@ class DataStore(RoomMemberStore, RoomStore,
EventFederationStore, EventFederationStore,
MediaRepositoryStore, MediaRepositoryStore,
PusherStore, PusherStore,
PushRuleStore
): ):
def __init__(self, hs): def __init__(self, hs):

View File

@ -31,3 +31,16 @@ CREATE TABLE IF NOT EXISTS pushers (
FOREIGN KEY(user_name) REFERENCES users(name), FOREIGN KEY(user_name) REFERENCES users(name),
UNIQUE (app_id, pushkey) UNIQUE (app_id, pushkey)
); );
CREATE TABLE IF NOT EXISTS push_rules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_name TEXT NOT NULL,
rule_id TEXT NOT NULL,
priority_class TINYINT NOT NULL,
priority INTEGER NOT NULL DEFAULT 0,
conditions TEXT NOT NULL,
actions TEXT NOT NULL,
UNIQUE(user_name, rule_id)
);
CREATE INDEX IF NOT EXISTS push_rules_user_name on push_rules (user_name);

View File

@ -31,3 +31,16 @@ CREATE TABLE IF NOT EXISTS pushers (
FOREIGN KEY(user_name) REFERENCES users(name), FOREIGN KEY(user_name) REFERENCES users(name),
UNIQUE (app_id, pushkey) UNIQUE (app_id, pushkey)
); );
CREATE TABLE IF NOT EXISTS push_rules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_name TEXT NOT NULL,
rule_id TEXT NOT NULL,
priority_class TINYINT NOT NULL,
priority INTEGER NOT NULL DEFAULT 0,
conditions TEXT NOT NULL,
actions TEXT NOT NULL,
UNIQUE(user_name, rule_id)
);
CREATE INDEX IF NOT EXISTS push_rules_user_name on push_rules (user_name);