Add unstable room version to support new historical PL
parent
04a29fed47
commit
258fa57d7e
|
@ -73,6 +73,9 @@ class RoomVersion:
|
||||||
# MSC2403: Allows join_rules to be set to 'knock', changes auth rules to allow sending
|
# MSC2403: Allows join_rules to be set to 'knock', changes auth rules to allow sending
|
||||||
# m.room.membership event with membership 'knock'.
|
# m.room.membership event with membership 'knock'.
|
||||||
msc2403_knocking = attr.ib(type=bool)
|
msc2403_knocking = attr.ib(type=bool)
|
||||||
|
# MSC2716: Adds m.room.power_levels -> content.historical field to control
|
||||||
|
# whether "insertion", "chunk", "marker" events can be sent
|
||||||
|
msc2716_historical = attr.ib(type=bool)
|
||||||
|
|
||||||
|
|
||||||
class RoomVersions:
|
class RoomVersions:
|
||||||
|
@ -88,6 +91,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
V2 = RoomVersion(
|
V2 = RoomVersion(
|
||||||
"2",
|
"2",
|
||||||
|
@ -101,6 +105,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
V3 = RoomVersion(
|
V3 = RoomVersion(
|
||||||
"3",
|
"3",
|
||||||
|
@ -114,6 +119,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
V4 = RoomVersion(
|
V4 = RoomVersion(
|
||||||
"4",
|
"4",
|
||||||
|
@ -127,6 +133,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
V5 = RoomVersion(
|
V5 = RoomVersion(
|
||||||
"5",
|
"5",
|
||||||
|
@ -140,6 +147,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
V6 = RoomVersion(
|
V6 = RoomVersion(
|
||||||
"6",
|
"6",
|
||||||
|
@ -153,6 +161,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
MSC2176 = RoomVersion(
|
MSC2176 = RoomVersion(
|
||||||
"org.matrix.msc2176",
|
"org.matrix.msc2176",
|
||||||
|
@ -166,6 +175,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=True,
|
msc2176_redaction_rules=True,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
MSC3083 = RoomVersion(
|
MSC3083 = RoomVersion(
|
||||||
"org.matrix.msc3083",
|
"org.matrix.msc3083",
|
||||||
|
@ -179,6 +189,7 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=True,
|
msc3083_join_rules=True,
|
||||||
msc2403_knocking=False,
|
msc2403_knocking=False,
|
||||||
|
msc2716_historical=False,
|
||||||
)
|
)
|
||||||
V7 = RoomVersion(
|
V7 = RoomVersion(
|
||||||
"7",
|
"7",
|
||||||
|
@ -192,6 +203,21 @@ class RoomVersions:
|
||||||
msc2176_redaction_rules=False,
|
msc2176_redaction_rules=False,
|
||||||
msc3083_join_rules=False,
|
msc3083_join_rules=False,
|
||||||
msc2403_knocking=True,
|
msc2403_knocking=True,
|
||||||
|
msc2716_historical=False,
|
||||||
|
)
|
||||||
|
MSC2716 = RoomVersion(
|
||||||
|
"org.matrix.msc2716",
|
||||||
|
RoomDisposition.STABLE,
|
||||||
|
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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,6 +233,7 @@ KNOWN_ROOM_VERSIONS = {
|
||||||
RoomVersions.MSC2176,
|
RoomVersions.MSC2176,
|
||||||
RoomVersions.MSC3083,
|
RoomVersions.MSC3083,
|
||||||
RoomVersions.V7,
|
RoomVersions.V7,
|
||||||
|
RoomVersions.MSC2716,
|
||||||
)
|
)
|
||||||
# Note that we do not include MSC2043 here unless it is enabled in the config.
|
# Note that we do not include MSC2043 here unless it is enabled in the config.
|
||||||
} # type: Dict[str, RoomVersion]
|
} # type: Dict[str, RoomVersion]
|
||||||
|
|
|
@ -190,6 +190,13 @@ def check(
|
||||||
if event.type == EventTypes.Redaction:
|
if event.type == EventTypes.Redaction:
|
||||||
check_redaction(room_version_obj, event, auth_events)
|
check_redaction(room_version_obj, event, auth_events)
|
||||||
|
|
||||||
|
if (
|
||||||
|
event.type == EventTypes.MSC2716_INSERTION
|
||||||
|
or event.type == EventTypes.MSC2716_CHUNK
|
||||||
|
or event.type == EventTypes.MSC2716_MARKER
|
||||||
|
):
|
||||||
|
check_historical(room_version_obj, event, auth_events)
|
||||||
|
|
||||||
logger.debug("Allowing! %s", event)
|
logger.debug("Allowing! %s", event)
|
||||||
|
|
||||||
|
|
||||||
|
@ -501,6 +508,38 @@ def check_redaction(
|
||||||
raise AuthError(403, "You don't have permission to redact events")
|
raise AuthError(403, "You don't have permission to redact events")
|
||||||
|
|
||||||
|
|
||||||
|
def check_historical(
|
||||||
|
room_version_obj: RoomVersion,
|
||||||
|
event: EventBase,
|
||||||
|
auth_events: StateMap[EventBase],
|
||||||
|
) -> None:
|
||||||
|
"""Check whether the event sender is allowed to send historical related
|
||||||
|
events like "insertion", "chunk", and "marker".
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
AuthError if the event sender is not allowed to send historical related events
|
||||||
|
("insertion", "chunk", and "marker").
|
||||||
|
"""
|
||||||
|
if not room_version_obj.msc2716_historical:
|
||||||
|
raise AuthError(
|
||||||
|
403,
|
||||||
|
"Historical events not supported with your room version",
|
||||||
|
)
|
||||||
|
|
||||||
|
user_level = get_user_power_level(event.user_id, auth_events)
|
||||||
|
|
||||||
|
historical_level = _get_named_level(auth_events, "historical", 100)
|
||||||
|
|
||||||
|
if user_level < historical_level:
|
||||||
|
raise AuthError(
|
||||||
|
403,
|
||||||
|
'You don\'t have permission to send send historical related events ("insertion", "chunk", and "marker")',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _check_power_levels(
|
def _check_power_levels(
|
||||||
room_version_obj: RoomVersion,
|
room_version_obj: RoomVersion,
|
||||||
event: EventBase,
|
event: EventBase,
|
||||||
|
|
|
@ -124,6 +124,9 @@ def prune_event_dict(room_version: RoomVersion, event_dict: dict) -> dict:
|
||||||
if room_version.msc2176_redaction_rules:
|
if room_version.msc2176_redaction_rules:
|
||||||
add_fields("invite")
|
add_fields("invite")
|
||||||
|
|
||||||
|
if room_version.msc2716_historical:
|
||||||
|
add_fields("historical")
|
||||||
|
|
||||||
elif event_type == EventTypes.Aliases and room_version.special_case_aliases_auth:
|
elif event_type == EventTypes.Aliases and room_version.special_case_aliases_auth:
|
||||||
add_fields("aliases")
|
add_fields("aliases")
|
||||||
elif event_type == EventTypes.RoomHistoryVisibility:
|
elif event_type == EventTypes.RoomHistoryVisibility:
|
||||||
|
|
|
@ -955,6 +955,7 @@ class RoomCreationHandler(BaseHandler):
|
||||||
"kick": 50,
|
"kick": 50,
|
||||||
"redact": 50,
|
"redact": 50,
|
||||||
"invite": 50,
|
"invite": 50,
|
||||||
|
"historical": 100,
|
||||||
} # type: JsonDict
|
} # type: JsonDict
|
||||||
|
|
||||||
if config["original_invitees_have_ops"]:
|
if config["original_invitees_have_ops"]:
|
||||||
|
|
Loading…
Reference in New Issue