Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add default_power_level_content_override config option. #12535

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/12535.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add default_power_level_content_override config option.
16 changes: 16 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,22 @@ push:
#
#encryption_enabled_by_default_for_room_type: invite

# Override the default power levels for rooms created on this server, per
# room creation preset.
#
# Useful if you know that your users need special permissions in rooms
# that they create (e.g. to send particular types of state events without
# needing an elevated power level). This takes the same shape as the
# `power_level_content_override` parameter in the /createRoom API, but
# is applied before that parameter.
#
# This is something of a workaround in the absence of MSC3779 or MSC3761.
#
#default_power_level_content_override:
# private_chat: null
# trusted_private_chat: null
# public_chat: null


# Uncomment to allow non-server-admin users to create groups on this server
#
Expand Down
29 changes: 29 additions & 0 deletions synapse/config/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
"Invalid value for encryption_enabled_by_default_for_room_type"
)

self.default_power_level_content_override = config.get(
"default_power_level_content_override",
None,
)
if self.default_power_level_content_override is not None:
for preset in self.default_power_level_content_override:
if preset not in vars(RoomCreationPreset).values():
raise ConfigError(
"Unrecognised room preset %s in default_power_level_content_override"
% preset
)
# We validate the actual overrides when we try to apply them.

def generate_config_section(self, **kwargs: Any) -> str:
return """\
## Rooms ##
Expand All @@ -83,4 +96,20 @@ def generate_config_section(self, **kwargs: Any) -> str:
# will also not affect rooms created by other servers.
#
#encryption_enabled_by_default_for_room_type: invite

# Override the default power levels for rooms created on this server, per
# room creation preset.
#
# Useful if you know that your users need special permissions in rooms
# that they create (e.g. to send particular types of state events without
# needing an elevated power level). This takes the same shape as the
# `power_level_content_override` parameter in the /createRoom API, but
# is applied before that parameter.
#
# This is something of a workaround in the absence of MSC3779 or MSC3761.
#
#default_power_level_content_override:
# private_chat: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some example non-null content might help admins understand what goes here:

Suggested change
# private_chat: null
# private_chat: { "events": { "com.example.foo" : 0 } }

# trusted_private_chat: null
# public_chat: null
"""
12 changes: 12 additions & 0 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,18 @@ async def send(etype: str, content: JsonDict, **kwargs: Any) -> int:
if power_level_content_override:
power_level_content.update(power_level_content_override)

# override default_power_level_content_override for this room preset, if any
default_power_level_content_override = (
self.config.room.default_power_level_content_override
)
if (
default_power_level_content_override
and default_power_level_content_override.get(preset_config)
):
power_level_content.update(
default_power_level_content_override.get(preset_config)
)
Comment on lines +1057 to +1059
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an admin were to configure an override like: private_chat: { "events": { "com.example.foo" : 0 } }, the entire default "events": {"m.room.name": ..., ...} content from above will be replaced. Is this intended behaviour?

kind of related to matrix-org/matrix-spec#492


Comment on lines 1046 to +1060
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for default_power_level_content_override says that it's applied before power_level_content_override, but here it is the other way around?

last_sent_stream_id = await send(
etype=EventTypes.PowerLevels, content=power_level_content
)
Expand Down