When redacting, keep event fields around that maintain the historical event structure intact (MSC2716) (#10538)

* Keep event fields that maintain the historical event structure intact

Fix https://github.com/matrix-org/synapse/issues/10521

* Add changelog

* Bump room version

* Better changelog text

* Fix up room version after develop merge
This commit is contained in:
Eric Eastwood 2021-08-09 20:23:31 -05:00 committed by GitHub
parent 6b61debf5c
commit 7afb615839
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 15 deletions

View file

@ -0,0 +1 @@
Add support for new redaction rules for historical events specified in [MSC2716](https://github.com/matrix-org/matrix-doc/pull/2716).

View file

@ -76,6 +76,8 @@ class RoomVersion:
# MSC2716: Adds m.room.power_levels -> content.historical field to control # MSC2716: Adds m.room.power_levels -> content.historical field to control
# whether "insertion", "chunk", "marker" events can be sent # whether "insertion", "chunk", "marker" events can be sent
msc2716_historical = attr.ib(type=bool) msc2716_historical = attr.ib(type=bool)
# MSC2716: Adds support for redacting "insertion", "chunk", and "marker" events
msc2716_redactions = attr.ib(type=bool)
class RoomVersions: class RoomVersions:
@ -92,6 +94,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=False, msc2403_knocking=False,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
) )
V2 = RoomVersion( V2 = RoomVersion(
"2", "2",
@ -106,6 +109,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=False, msc2403_knocking=False,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
) )
V3 = RoomVersion( V3 = RoomVersion(
"3", "3",
@ -120,6 +124,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=False, msc2403_knocking=False,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
) )
V4 = RoomVersion( V4 = RoomVersion(
"4", "4",
@ -134,6 +139,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=False, msc2403_knocking=False,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
) )
V5 = RoomVersion( V5 = RoomVersion(
"5", "5",
@ -148,6 +154,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=False, msc2403_knocking=False,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
) )
V6 = RoomVersion( V6 = RoomVersion(
"6", "6",
@ -162,6 +169,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=False, msc2403_knocking=False,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
) )
MSC2176 = RoomVersion( MSC2176 = RoomVersion(
"org.matrix.msc2176", "org.matrix.msc2176",
@ -176,6 +184,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=False, msc2403_knocking=False,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
) )
V7 = RoomVersion( V7 = RoomVersion(
"7", "7",
@ -190,20 +199,7 @@ class RoomVersions:
msc3083_join_rules=False, msc3083_join_rules=False,
msc2403_knocking=True, msc2403_knocking=True,
msc2716_historical=False, msc2716_historical=False,
) msc2716_redactions=False,
MSC2716 = RoomVersion(
"org.matrix.msc2716",
RoomDisposition.UNSTABLE,
EventFormatVersions.V3,
StateResolutionVersions.V2,
enforce_key_validity=True,
special_case_aliases_auth=False,
strict_canonicaljson=True,
limit_notifications_power_levels=True,
msc2176_redaction_rules=False,
msc3083_join_rules=False,
msc2403_knocking=True,
msc2716_historical=True,
) )
V8 = RoomVersion( V8 = RoomVersion(
"8", "8",
@ -218,6 +214,37 @@ class RoomVersions:
msc3083_join_rules=True, msc3083_join_rules=True,
msc2403_knocking=True, msc2403_knocking=True,
msc2716_historical=False, msc2716_historical=False,
msc2716_redactions=False,
)
MSC2716 = RoomVersion(
"org.matrix.msc2716",
RoomDisposition.UNSTABLE,
EventFormatVersions.V3,
StateResolutionVersions.V2,
enforce_key_validity=True,
special_case_aliases_auth=False,
strict_canonicaljson=True,
limit_notifications_power_levels=True,
msc2176_redaction_rules=False,
msc3083_join_rules=False,
msc2403_knocking=True,
msc2716_historical=True,
msc2716_redactions=False,
)
MSC2716v2 = RoomVersion(
"org.matrix.msc2716v2",
RoomDisposition.UNSTABLE,
EventFormatVersions.V3,
StateResolutionVersions.V2,
enforce_key_validity=True,
special_case_aliases_auth=False,
strict_canonicaljson=True,
limit_notifications_power_levels=True,
msc2176_redaction_rules=False,
msc3083_join_rules=False,
msc2403_knocking=True,
msc2716_historical=True,
msc2716_redactions=True,
) )

View file

@ -17,7 +17,7 @@ from typing import Any, Mapping, Union
from frozendict import frozendict from frozendict import frozendict
from synapse.api.constants import EventTypes, RelationTypes from synapse.api.constants import EventContentFields, EventTypes, RelationTypes
from synapse.api.errors import Codes, SynapseError from synapse.api.errors import Codes, SynapseError
from synapse.api.room_versions import RoomVersion from synapse.api.room_versions import RoomVersion
from synapse.util.async_helpers import yieldable_gather_results from synapse.util.async_helpers import yieldable_gather_results
@ -135,6 +135,12 @@ def prune_event_dict(room_version: RoomVersion, event_dict: dict) -> dict:
add_fields("history_visibility") add_fields("history_visibility")
elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules: elif event_type == EventTypes.Redaction and room_version.msc2176_redaction_rules:
add_fields("redacts") add_fields("redacts")
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_INSERTION:
add_fields(EventContentFields.MSC2716_NEXT_CHUNK_ID)
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_CHUNK:
add_fields(EventContentFields.MSC2716_CHUNK_ID)
elif room_version.msc2716_redactions and event_type == EventTypes.MSC2716_MARKER:
add_fields(EventContentFields.MSC2716_MARKER_INSERTION)
allowed_fields = {k: v for k, v in event_dict.items() if k in allowed_keys} allowed_fields = {k: v for k, v in event_dict.items() if k in allowed_keys}