summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2022-04-23 15:25:13 +0100
committerMatthew Hodgson <matthew@matrix.org>2022-04-23 15:25:25 +0100
commit0a6f1d1ac2ed65f66814ce91e7d21e2aeb480057 (patch)
treed3b4d65ff0eeb4b304b4a3ee0b15fb4ff6457c4a
parentUpdate `delay_cancellation` to accept any awaitable (#12468) (diff)
downloadsynapse-0a6f1d1ac2ed65f66814ce91e7d21e2aeb480057.tar.xz
add default_power_level_content_override config option.
Lets you 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.
-rw-r--r--synapse/config/room.py29
-rw-r--r--synapse/handlers/room.py12
2 files changed, 41 insertions, 0 deletions
diff --git a/synapse/config/room.py b/synapse/config/room.py
index e18a87ea37..0ca0cfe93b 100644
--- a/synapse/config/room.py
+++ b/synapse/config/room.py
@@ -63,6 +63,19 @@ class RoomConfig(Config):
                 "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 ##
@@ -83,4 +96,20 @@ class RoomConfig(Config):
         # 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
+        #   trusted_private_chat: null
+        #   public_chat: null
         """
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index b31f00b517..87dcb14acb 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -1046,6 +1046,18 @@ class RoomCreationHandler:
             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)
+                )
+
             last_sent_stream_id = await send(
                 etype=EventTypes.PowerLevels, content=power_level_content
             )