mirror of
https://github.com/element-hq/synapse.git
synced 2026-10-24 08:34:12 +00:00
Rename SerializeEventConfig.only_event_fields -> event_field_allowlist
The previous name was ambiguous — it sounds like a list of field names to include *or* exclude. "allowlist" makes the direction explicit. Updates the Rust struct field, the Python-facing getter, and all call sites. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
e6f7bf5bc3
commit
a3c430256d
5 files changed
+17
-17
No files matched your search
@@ -102,7 +102,7 @@ pub struct SerializeEventConfig {
|
||||
as_client_event: bool,
|
||||
event_format: EventFormat,
|
||||
requester: Option<Requester>,
|
||||
only_event_fields: Option<Vec<String>>,
|
||||
event_field_allowlist: Option<Vec<String>>,
|
||||
include_stripped_room_state: bool,
|
||||
include_admin_metadata: bool,
|
||||
msc4354_enabled: bool,
|
||||
@@ -117,7 +117,7 @@ impl SerializeEventConfig {
|
||||
as_client_event = true,
|
||||
event_format = EventFormat::ClientV1,
|
||||
requester = None,
|
||||
only_event_fields = None,
|
||||
event_field_allowlist = None,
|
||||
include_stripped_room_state = false,
|
||||
include_admin_metadata = false,
|
||||
msc4354_enabled = false,
|
||||
@@ -126,7 +126,7 @@ impl SerializeEventConfig {
|
||||
as_client_event: bool,
|
||||
event_format: EventFormat,
|
||||
requester: Option<Bound<'_, Requester>>,
|
||||
only_event_fields: Option<Vec<String>>,
|
||||
event_field_allowlist: Option<Vec<String>>,
|
||||
include_stripped_room_state: bool,
|
||||
include_admin_metadata: bool,
|
||||
msc4354_enabled: bool,
|
||||
@@ -137,7 +137,7 @@ impl SerializeEventConfig {
|
||||
as_client_event,
|
||||
event_format,
|
||||
requester,
|
||||
only_event_fields,
|
||||
event_field_allowlist,
|
||||
include_stripped_room_state,
|
||||
include_admin_metadata,
|
||||
msc4354_enabled,
|
||||
@@ -163,8 +163,8 @@ impl SerializeEventConfig {
|
||||
}
|
||||
|
||||
#[getter]
|
||||
fn only_event_fields(&self) -> Option<Vec<String>> {
|
||||
self.only_event_fields.clone()
|
||||
fn event_field_allowlist(&self) -> Option<Vec<String>> {
|
||||
self.event_field_allowlist.clone()
|
||||
}
|
||||
|
||||
#[getter]
|
||||
@@ -310,7 +310,7 @@ fn serialize_core_inner(
|
||||
}
|
||||
|
||||
// Only include fields that the client has requested.
|
||||
if let Some(fields) = &config.only_event_fields {
|
||||
if let Some(fields) = &config.event_field_allowlist {
|
||||
if !fields.is_empty() {
|
||||
serialized = only_fields(&serialized, fields);
|
||||
}
|
||||
@@ -643,7 +643,7 @@ fn object_entry_mut<'a>(map: &'a mut Map<String, Value>, key: &str) -> &'a mut M
|
||||
}
|
||||
|
||||
/// Return a new map containing only the given (possibly dotted) field paths,
|
||||
/// implementing the `only_event_fields` client filter.
|
||||
/// implementing the `event_field_allowlist` client filter.
|
||||
fn only_fields(dictionary: &Map<String, Value>, fields: &[String]) -> Map<String, Value> {
|
||||
let mut output = Map::new();
|
||||
for field in fields {
|
||||
|
||||
@@ -61,7 +61,7 @@ class EventRestServlet(RestServlet):
|
||||
as_client_event=False,
|
||||
event_format=EventFormat.Raw,
|
||||
requester=requester,
|
||||
only_event_fields=None,
|
||||
event_field_allowlist=None,
|
||||
include_stripped_room_state=True,
|
||||
include_admin_metadata=True,
|
||||
)
|
||||
|
||||
@@ -312,7 +312,7 @@ class SyncRestServlet(RestServlet):
|
||||
serialize_options = SerializeEventConfig(
|
||||
event_format=event_formatter,
|
||||
requester=requester,
|
||||
only_event_fields=filter.event_fields,
|
||||
event_field_allowlist=filter.event_fields,
|
||||
)
|
||||
stripped_serialize_options = SerializeEventConfig(
|
||||
event_format=event_formatter,
|
||||
|
||||
@@ -367,7 +367,7 @@ class SerializeEventConfig:
|
||||
as_client_event: bool = True,
|
||||
event_format: EventFormat = ...,
|
||||
requester: Requester | None = None,
|
||||
only_event_fields: list[str] | None = None,
|
||||
event_field_allowlist: list[str] | None = None,
|
||||
include_stripped_room_state: bool = False,
|
||||
include_admin_metadata: bool = False,
|
||||
msc4354_enabled: bool = False,
|
||||
@@ -379,7 +379,7 @@ class SerializeEventConfig:
|
||||
@property
|
||||
def requester(self) -> Requester | None: ...
|
||||
@property
|
||||
def only_event_fields(self) -> list[str] | None: ...
|
||||
def event_field_allowlist(self) -> list[str] | None: ...
|
||||
@property
|
||||
def include_stripped_room_state(self) -> bool: ...
|
||||
@property
|
||||
|
||||
@@ -663,7 +663,7 @@ class SerializeEventTestCase(HomeserverTestCase):
|
||||
FilteredEvent(event=ev, membership=None),
|
||||
1479807801915,
|
||||
config=SerializeEventConfig(
|
||||
only_event_fields=fields,
|
||||
event_field_allowlist=fields,
|
||||
include_admin_metadata=include_admin_metadata,
|
||||
),
|
||||
redaction_map=redaction_map,
|
||||
@@ -786,7 +786,7 @@ class SerializeEventTestCase(HomeserverTestCase):
|
||||
def test_event_fields_fail_if_fields_not_str(self) -> None:
|
||||
with self.assertRaises(TypeError):
|
||||
SerializeEventConfig(
|
||||
only_event_fields=["room_id", 4], # type: ignore[list-item]
|
||||
event_field_allowlist=["room_id", 4], # type: ignore[list-item]
|
||||
)
|
||||
|
||||
def test_default_serialize_config_excludes_admin_metadata(self) -> None:
|
||||
@@ -878,7 +878,7 @@ class SerializeEventTestCase(HomeserverTestCase):
|
||||
as_client_event=False, # default True
|
||||
event_format=EventFormat.Raw, # default EventFormat.ClientV1
|
||||
requester=create_requester("@example:example.org"), # default None
|
||||
only_event_fields=["foo"], # default None
|
||||
event_field_allowlist=["foo"], # default None
|
||||
include_stripped_room_state=True, # default False
|
||||
)
|
||||
admin_config = make_config_for_admin(non_default_config)
|
||||
@@ -888,7 +888,7 @@ class SerializeEventTestCase(HomeserverTestCase):
|
||||
self.assertEqual(admin_config.event_format, non_default_config.event_format)
|
||||
self.assertEqual(admin_config.requester, non_default_config.requester)
|
||||
self.assertEqual(
|
||||
admin_config.only_event_fields, non_default_config.only_event_fields
|
||||
admin_config.event_field_allowlist, non_default_config.event_field_allowlist
|
||||
)
|
||||
self.assertEqual(
|
||||
admin_config.include_stripped_room_state,
|
||||
@@ -899,7 +899,7 @@ class SerializeEventTestCase(HomeserverTestCase):
|
||||
def test_redacted_because_is_filtered_out(self) -> None:
|
||||
"""If an event's unsigned dict has a `redacted_by` field, then the
|
||||
`redacted_because` should be filtered out if not specified in
|
||||
`only_event_fields`."""
|
||||
`event_field_allowlist`."""
|
||||
|
||||
redaction_id = "$redaction_event_id"
|
||||
|
||||
|
||||
Reference in new issue
Block a user