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. #12618

Merged
merged 36 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0a6f1d1
add default_power_level_content_override config option.
ara4n Apr 23, 2022
8cb9abe
changelog
ara4n Apr 23, 2022
ba33466
update sample config
ara4n Apr 23, 2022
f415534
Merge branch 'develop' into matthew/configurable_default_pl
andybalaam May 3, 2022
c3a8159
Apply default_power_level_content_override before power_level_content…
andybalaam May 3, 2022
20e2a51
Provide an example of a default_power_level_content_override
andybalaam May 3, 2022
f7eed3a
Generate docs
andybalaam May 3, 2022
7531942
Add a config manual entry for default_power_level_content_override
andybalaam May 3, 2022
50b0b1e
Re-order room permissions config
andybalaam May 3, 2022
9da3abc
Move changelog file to correct name for this PR
andybalaam May 4, 2022
45da8d0
Tests for power level overrides
andybalaam May 4, 2022
bbea127
Merge branch 'develop' into configurable_default_pl
andybalaam May 4, 2022
0cb64bf
Update test config to match documentation
andybalaam May 4, 2022
f863ad9
Document the way power level overrides overwrite per key
andybalaam May 4, 2022
eba1ed4
Reformat changelog for default_power_level_content_override
andybalaam May 6, 2022
9d70d83
Explicitly mention that the config will be overlaid
andybalaam May 9, 2022
e860ec6
Expand 12618 changelog entry
andybalaam May 9, 2022
4309993
Delete extranous sentence about MSC3779 and MSC3761
andybalaam May 9, 2022
3aed63a
More realistic example for default_power_level_content_override
andybalaam May 9, 2022
9c99926
Fix indent of example config
andybalaam May 10, 2022
52197b0
Fix case of create in default power level tests
andybalaam May 10, 2022
55e1ecc
Spread out multi-line docstring
andybalaam May 10, 2022
21459d8
Use Python native string literal concatenation
andybalaam May 10, 2022
08b00e1
Reduce the user of Cucumber-style Given/And comments to be more readable
andybalaam May 10, 2022
9adeaa7
Document allowed keys inside default_power_level_content_override
andybalaam May 10, 2022
4dda230
Move default_power_level_content_override into a member
andybalaam May 10, 2022
ae9421c
Remove assumptions about default power levels from tests
andybalaam May 10, 2022
aa43bb1
Generate sample config
andybalaam May 10, 2022
d84ba9a
Code formatting
andybalaam May 10, 2022
990b7fa
Tidy default override if, and check against None instead of falsey
andybalaam May 12, 2022
8122c1b
Fix typo use->used
andybalaam May 12, 2022
a91a043
Remove extraneous null presets in example config
andybalaam May 12, 2022
383e021
Regenerate sample config
andybalaam May 12, 2022
b2ae9c9
Add wording "per room preset"
andybalaam May 12, 2022
e1a913d
Quotes for config key example
andybalaam May 12, 2022
8a639df
Make config example valid yaml
andybalaam May 12, 2022
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/12618.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add default_power_level_content_override config option.
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2455,6 +2455,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: { "events": { "com.example.foo" : 0 } }
# trusted_private_chat: null
# public_chat: null


# Uncomment to allow non-server-admin users to create groups on this server
#
Expand Down
26 changes: 26 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,32 @@ room_list_publication_rules:
room_id: "*"
action: allow
```

---
Config option: `default_power_level_content_override`

The `default_power_level_content_override` option controls the default power
levels for rooms.

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.

Note that each key provided inside a preset (for example `events` in the example
below) will overwrite all existing defaults inside that key. So in the example
below, newly-created private_chat rooms will have no rules for any event types
except `com.example.foo`.

Example configuration:
```yaml
default_power_level_content_override:
private_chat: { "events": { "com.example.foo" : 0 } }
trusted_private_chat: null
public_chat: null
```

---
## Opentracing ##
Configuration options related to Opentracing support.
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.
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
#
# This is something of a workaround in the absence of MSC3779 or MSC3761.
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
#
#default_power_level_content_override:
# private_chat: { "events": { "com.example.foo" : 0 } }
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
# trusted_private_chat: null
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
# public_chat: null
"""
18 changes: 17 additions & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,25 @@ async def send(etype: str, content: JsonDict, **kwargs: Any) -> int:
for invitee in invite_list:
power_level_content["users"][invitee] = 100

# Power levels overrides are defined per chat preset
# If the user supplied a preset name e.g. "private_chat",
# we apply that preset
power_level_content.update(config["power_level_content_override"])

# If the server config contains default_power_level_content_override,
# and that contains information for this room preset, apply it.
default_power_level_content_override = (
self.config.room.default_power_level_content_override
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
)
if (
default_power_level_content_override
and default_power_level_content_override.get(preset_config)
andybalaam marked this conversation as resolved.
Show resolved Hide resolved
):
power_level_content.update(
default_power_level_content_override.get(preset_config)
)

# Finally, if the user supplied specific permissions for this room,
# apply those.
if power_level_content_override:
power_level_content.update(power_level_content_override)

Expand Down
Loading