mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Impl: /rooms/roomid/state/eventtype/state_key - Renamed RoomTopicRestServlet to RoomStateEventRestServlet. Support generic state event sending.
This commit is contained in:
parent
47a4bff139
commit
f690b7b827
@ -44,15 +44,15 @@ class Auth(object):
|
|||||||
be raised only if raises=True.
|
be raised only if raises=True.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if event.type in [RoomTopicEvent.TYPE, MessageEvent.TYPE,
|
if hasattr(event, "room_id"):
|
||||||
FeedbackEvent.TYPE]:
|
if event.type == RoomMemberEvent.TYPE:
|
||||||
yield self.check_joined_room(event.room_id, event.user_id)
|
|
||||||
defer.returnValue(True)
|
|
||||||
elif event.type == RoomMemberEvent.TYPE:
|
|
||||||
allowed = yield self.is_membership_change_allowed(event)
|
allowed = yield self.is_membership_change_allowed(event)
|
||||||
defer.returnValue(allowed)
|
defer.returnValue(allowed)
|
||||||
else:
|
else:
|
||||||
raise AuthError(500, "Unknown event type %s" % event.type)
|
yield self.check_joined_room(event.room_id, event.user_id)
|
||||||
|
defer.returnValue(True)
|
||||||
|
else:
|
||||||
|
raise AuthError(500, "Unknown event: %s" % event)
|
||||||
except AuthError as e:
|
except AuthError as e:
|
||||||
logger.info("Event auth check failed on event %s with msg: %s",
|
logger.info("Event auth check failed on event %s with msg: %s",
|
||||||
event, e.msg)
|
event, e.msg)
|
||||||
|
@ -95,39 +95,62 @@ class RoomCreateRestServlet(RestServlet):
|
|||||||
return (200, {})
|
return (200, {})
|
||||||
|
|
||||||
|
|
||||||
class RoomTopicRestServlet(RestServlet):
|
class RoomStateEventRestServlet(RestServlet):
|
||||||
PATTERN = client_path_pattern("/rooms/(?P<room_id>[^/]*)/topic$")
|
def register(self, http_server):
|
||||||
|
# /room/$roomid/state/$eventtype
|
||||||
|
no_state_key = "/rooms/(?P<room_id>[^/]*)/state/(?P<event_type>[^/]*)$"
|
||||||
|
|
||||||
def get_event_type(self):
|
# /room/$roomid/state/$eventtype/$statekey
|
||||||
return RoomTopicEvent.TYPE
|
state_key = ("/rooms/(?P<room_id>[^/]*)/state/" +
|
||||||
|
"(?P<event_type>[^/]*)/(?P<state_key>[^/]*)$")
|
||||||
|
|
||||||
|
http_server.register_path("GET",
|
||||||
|
client_path_pattern(state_key),
|
||||||
|
self.on_GET)
|
||||||
|
http_server.register_path("PUT",
|
||||||
|
client_path_pattern(state_key),
|
||||||
|
self.on_PUT)
|
||||||
|
http_server.register_path("GET",
|
||||||
|
client_path_pattern(no_state_key),
|
||||||
|
self.on_GET_no_state_key)
|
||||||
|
http_server.register_path("PUT",
|
||||||
|
client_path_pattern(no_state_key),
|
||||||
|
self.on_PUT_no_state_key)
|
||||||
|
|
||||||
|
def on_GET_no_state_key(self, request, room_id, event_type):
|
||||||
|
return self.on_GET(request, room_id, event_type, "")
|
||||||
|
|
||||||
|
def on_PUT_no_state_key(self, request, room_id, event_type):
|
||||||
|
return self.on_PUT(request, room_id, event_type, "")
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_GET(self, request, room_id):
|
def on_GET(self, request, room_id, event_type, state_key):
|
||||||
user = yield self.auth.get_user_by_req(request)
|
user = yield self.auth.get_user_by_req(request)
|
||||||
|
|
||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
data = yield msg_handler.get_room_data(
|
data = yield msg_handler.get_room_data(
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
room_id=urllib.unquote(room_id),
|
room_id=urllib.unquote(room_id),
|
||||||
event_type=RoomTopicEvent.TYPE,
|
event_type=event_type,
|
||||||
state_key="",
|
state_key=state_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
raise SynapseError(404, "Topic not found.", errcode=Codes.NOT_FOUND)
|
raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND)
|
||||||
defer.returnValue((200, data.content))
|
defer.returnValue((200, data[0].get_dict()["content"]))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, request, room_id):
|
def on_PUT(self, request, room_id, event_type, state_key):
|
||||||
user = yield self.auth.get_user_by_req(request)
|
user = yield self.auth.get_user_by_req(request)
|
||||||
|
|
||||||
content = _parse_json(request)
|
content = _parse_json(request)
|
||||||
|
|
||||||
event = self.event_factory.create_event(
|
event = self.event_factory.create_event(
|
||||||
etype=self.get_event_type(),
|
etype=event_type,
|
||||||
content=content,
|
content=content,
|
||||||
room_id=urllib.unquote(room_id),
|
room_id=urllib.unquote(room_id),
|
||||||
user_id=user.to_string(),
|
user_id=user.to_string(),
|
||||||
|
state_key=state_key
|
||||||
)
|
)
|
||||||
|
|
||||||
msg_handler = self.handlers.message_handler
|
msg_handler = self.handlers.message_handler
|
||||||
@ -412,7 +435,7 @@ def _parse_json(request):
|
|||||||
|
|
||||||
|
|
||||||
def register_servlets(hs, http_server):
|
def register_servlets(hs, http_server):
|
||||||
RoomTopicRestServlet(hs).register(http_server)
|
RoomStateEventRestServlet(hs).register(http_server)
|
||||||
RoomMemberRestServlet(hs).register(http_server)
|
RoomMemberRestServlet(hs).register(http_server)
|
||||||
MessageRestServlet(hs).register(http_server)
|
MessageRestServlet(hs).register(http_server)
|
||||||
FeedbackRestServlet(hs).register(http_server)
|
FeedbackRestServlet(hs).register(http_server)
|
||||||
|
Loading…
Reference in New Issue
Block a user