forked from MirrorHub/synapse
Run lint fix
This commit is contained in:
parent
ce02e755c1
commit
a77a254b31
3 changed files with 40 additions and 17 deletions
|
@ -50,11 +50,11 @@ from synapse.api.errors import (
|
||||||
)
|
)
|
||||||
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion, RoomVersions
|
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion, RoomVersions
|
||||||
from synapse.crypto.event_signing import compute_event_signature
|
from synapse.crypto.event_signing import compute_event_signature
|
||||||
from synapse.federation.federation_base import FederationBase, event_from_pdu_json
|
|
||||||
from synapse.event_auth import auth_types_for_event
|
from synapse.event_auth import auth_types_for_event
|
||||||
from synapse.events import EventBase
|
from synapse.events import EventBase
|
||||||
from synapse.events.snapshot import EventContext
|
from synapse.events.snapshot import EventContext
|
||||||
from synapse.events.validator import EventValidator
|
from synapse.events.validator import EventValidator
|
||||||
|
from synapse.federation.federation_base import FederationBase, event_from_pdu_json
|
||||||
from synapse.handlers._base import BaseHandler
|
from synapse.handlers._base import BaseHandler
|
||||||
from synapse.logging.context import (
|
from synapse.logging.context import (
|
||||||
make_deferred_yieldable,
|
make_deferred_yieldable,
|
||||||
|
@ -680,7 +680,9 @@ class FederationHandler(BaseHandler, FederationBase):
|
||||||
|
|
||||||
_forwarded_key = "net.maunium.msc2730.forwarded"
|
_forwarded_key = "net.maunium.msc2730.forwarded"
|
||||||
|
|
||||||
async def _validate_forwarded_event(self, event: EventBase) -> Tuple[bool, Optional[str]]:
|
async def _validate_forwarded_event(
|
||||||
|
self, event: EventBase
|
||||||
|
) -> Tuple[bool, Optional[str]]:
|
||||||
try:
|
try:
|
||||||
source_evt_dict = {**event.content[self._forwarded_key]}
|
source_evt_dict = {**event.content[self._forwarded_key]}
|
||||||
room_version_identifier = source_evt_dict["unsigned"]["room_version"]
|
room_version_identifier = source_evt_dict["unsigned"]["room_version"]
|
||||||
|
@ -734,7 +736,11 @@ class FederationHandler(BaseHandler, FederationBase):
|
||||||
|
|
||||||
logger.debug("[%s %s] Processing event: %s", room_id, event_id, event)
|
logger.debug("[%s %s] Processing event: %s", room_id, event_id, event)
|
||||||
|
|
||||||
if not event.is_state() and not event.redacts and self._forwarded_key in event.content:
|
if (
|
||||||
|
not event.is_state()
|
||||||
|
and not event.redacts
|
||||||
|
and self._forwarded_key in event.content
|
||||||
|
):
|
||||||
valid, event_id = await self._validate_forwarded_event(event)
|
valid, event_id = await self._validate_forwarded_event(event)
|
||||||
event.unsigned[self._forwarded_key] = {
|
event.unsigned[self._forwarded_key] = {
|
||||||
"valid": valid,
|
"valid": valid,
|
||||||
|
|
|
@ -37,6 +37,7 @@ from synapse.rest.client.v2_alpha import (
|
||||||
capabilities,
|
capabilities,
|
||||||
devices,
|
devices,
|
||||||
filter,
|
filter,
|
||||||
|
forward_event,
|
||||||
groups,
|
groups,
|
||||||
keys,
|
keys,
|
||||||
notifications,
|
notifications,
|
||||||
|
@ -47,7 +48,6 @@ from synapse.rest.client.v2_alpha import (
|
||||||
register,
|
register,
|
||||||
relations,
|
relations,
|
||||||
report_event,
|
report_event,
|
||||||
forward_event,
|
|
||||||
room_keys,
|
room_keys,
|
||||||
room_upgrade_rest_servlet,
|
room_upgrade_rest_servlet,
|
||||||
sendtodevice,
|
sendtodevice,
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from synapse.api.errors import Codes, SynapseError, AuthError
|
from synapse.api.errors import AuthError, Codes, SynapseError
|
||||||
from synapse.http.servlet import RestServlet, parse_integer
|
from synapse.http.servlet import RestServlet, parse_integer
|
||||||
from synapse.logging.opentracing import set_tag
|
from synapse.logging.opentracing import set_tag
|
||||||
|
|
||||||
|
@ -31,8 +31,10 @@ class RoomEventForwardServlet(RestServlet):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PATTERNS = client_patterns(
|
PATTERNS = client_patterns(
|
||||||
("/net.maunium.msc2730/rooms/(?P<room_id>[^/]*)/event/(?P<event_id>[^/]*)"
|
(
|
||||||
"/forward/(?P<target_room_id>[^/]*)/(?P<txn_id>.*)"),
|
"/net.maunium.msc2730/rooms/(?P<room_id>[^/]*)/event/(?P<event_id>[^/]*)"
|
||||||
|
"/forward/(?P<target_room_id>[^/]*)/(?P<txn_id>.*)"
|
||||||
|
),
|
||||||
releases=(), # This is an unstable feature
|
releases=(), # This is an unstable feature
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,14 +61,23 @@ class RoomEventForwardServlet(RestServlet):
|
||||||
raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND)
|
raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND)
|
||||||
|
|
||||||
if event.is_state():
|
if event.is_state():
|
||||||
raise SynapseError(401, "State events cannot be forwarded.",
|
raise SynapseError(
|
||||||
errcode=self._err_not_forwardable)
|
401,
|
||||||
|
"State events cannot be forwarded.",
|
||||||
|
errcode=self._err_not_forwardable,
|
||||||
|
)
|
||||||
elif event.redacts:
|
elif event.redacts:
|
||||||
raise SynapseError(401, "Redaction events cannot be forwarded.",
|
raise SynapseError(
|
||||||
errcode=self._err_not_forwardable)
|
401,
|
||||||
|
"Redaction events cannot be forwarded.",
|
||||||
|
errcode=self._err_not_forwardable,
|
||||||
|
)
|
||||||
elif event.internal_metadata.is_redacted():
|
elif event.internal_metadata.is_redacted():
|
||||||
raise SynapseError(401, "Redacted events cannot be forwarded.",
|
raise SynapseError(
|
||||||
errcode=self._err_not_forwardable)
|
401,
|
||||||
|
"Redacted events cannot be forwarded.",
|
||||||
|
errcode=self._err_not_forwardable,
|
||||||
|
)
|
||||||
|
|
||||||
event_id = event.event_id
|
event_id = event.event_id
|
||||||
event_dict = event.get_dict()
|
event_dict = event.get_dict()
|
||||||
|
@ -81,8 +92,11 @@ class RoomEventForwardServlet(RestServlet):
|
||||||
is_valid_forward = False
|
is_valid_forward = False
|
||||||
|
|
||||||
if has_forward_meta and not is_valid_forward:
|
if has_forward_meta and not is_valid_forward:
|
||||||
raise SynapseError(401, "Event contains invalid forward metadata.",
|
raise SynapseError(
|
||||||
errcode=self._err_not_forwardable)
|
401,
|
||||||
|
"Event contains invalid forward metadata.",
|
||||||
|
errcode=self._err_not_forwardable,
|
||||||
|
)
|
||||||
elif not has_forward_meta:
|
elif not has_forward_meta:
|
||||||
content[self._data_key] = event_dict
|
content[self._data_key] = event_dict
|
||||||
room_version = await self.store.get_room_version(event.room_id)
|
room_version = await self.store.get_room_version(event.room_id)
|
||||||
|
@ -101,13 +115,16 @@ class RoomEventForwardServlet(RestServlet):
|
||||||
"valid": True,
|
"valid": True,
|
||||||
"event_id": event_id,
|
"event_id": event_id,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if b"ts" in request.args and requester.app_service:
|
if b"ts" in request.args and requester.app_service:
|
||||||
forwarded_event_dict["origin_server_ts"] = parse_integer(request, "ts", 0)
|
forwarded_event_dict["origin_server_ts"] = parse_integer(request, "ts", 0)
|
||||||
|
|
||||||
forwarded_event, _ = await self.event_creation_handler.create_and_send_nonmember_event(
|
(
|
||||||
|
forwarded_event,
|
||||||
|
_,
|
||||||
|
) = await self.event_creation_handler.create_and_send_nonmember_event(
|
||||||
requester, forwarded_event_dict, txn_id=txn_id
|
requester, forwarded_event_dict, txn_id=txn_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue