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

Make power level defaults for new rooms configurable #6660

Closed
benparsons opened this issue Jan 8, 2020 · 7 comments
Closed

Make power level defaults for new rooms configurable #6660

benparsons opened this issue Jan 8, 2020 · 7 comments
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. z-p2 (Deprecated Label)

Comments

@benparsons
Copy link
Member

Description:

Power levels for new rooms are hardcoded (https://github.com/matrix-org/synapse/blob/master/synapse/handlers/room.py#L780), this could be configurable.

@clokep
Copy link
Member

clokep commented Jun 22, 2020

Permalink to the code:

power_level_content = {
"users": {creator_id: 100},
"users_default": 0,
"events": {
EventTypes.Name: 50,
EventTypes.PowerLevels: 100,
EventTypes.RoomHistoryVisibility: 100,
EventTypes.CanonicalAlias: 50,
EventTypes.RoomAvatar: 50,
EventTypes.Tombstone: 100,
EventTypes.ServerACL: 100,
EventTypes.RoomEncryption: 100,
},
"events_default": 0,
"state_default": 50,
"ban": 50,
"kick": 50,
"redact": 50,
"invite": 50,
}

@romain-neil
Copy link

romain-neil commented Jun 22, 2020

In order to achieve that, I think we only have to change few files:

synapse/api/auth.py:
gist

(L 522, after is_server_admin function)

and registration.py (storage/data_stores/main):

is_room_admin

(L 294, after is_server_admin func)

If somebody is interested

@benparsons
Copy link
Member Author

Just been discussing with a user who is really missing this feature.

@anoadragon453
Copy link
Member

Note that this can currently be achieved through use of a pluggable ThirdPartyEventRules module. An example of such a module doing exactly this currently exists here.

The definition of ThirdPartyEventRules is here, and can be configured in Synapse via the homeserver config file.

How this works is that ThirdPartyEventRules modules can implement a method called on_create_room. Passed to this method is a config dict for the room. Setting the power_level_content_override key of this dictionary will set the initial power levels for the room. Simply override on_create_room, set power_level_content_override to whatever you like, and then all new rooms will have those power levels.

You can of course also set different power levels depending on other things set in config, such as the room's preset (config["preset"]) or other events in config["initial_state"].

@reech
Copy link

reech commented Dec 4, 2020

So how would this work with official Synapse Docker image without actually maintaining a custom Synapse image ourselves?

At runtime we can pass either environment variables or a config fragment via command line args #6662 It seems to me that, in regards to power-levels, to hardcode handlers/room.py is easier since we would need to maintain a custom image in either case?

So is there a way to actually map a ThirdPartyEventRules python file into the container? Pass a PYTHONPATH environment var with an extra/merged file location which then can be referenced from homeserver.yaml, for example:

third_party_event_rules:
  module: "ThirdPartyEventRules_VOLUME_MAPPED_FILE.access_rules"

@Mikaela
Copy link
Contributor

Mikaela commented Feb 18, 2022

Is this still planned? Both z-p1 and z-enhancement labels appear to be deprecated.

Changing default power levels without having to maintain a fork of Synapse would be helpful towards staying up-to-date and a couple of Finnish communities were discussing earlier today that if they could set their homeservers to give room creator power level 101 instead of 100 would help with trouble with bridges and similar taking PL100 for themselves.

I don't think there is basis for changing it globally (at least without further testing in practice), but that is one example of a case where changing default power levels in Synapse config would be helpful. Others include e.g. giving managed-server server-wide Mjolnir power level.

@erikjohnston erikjohnston added T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. and removed z-enhancement labels Feb 23, 2022
@anoadragon453
Copy link
Member

anoadragon453 commented Feb 28, 2022

After some discussion in #synapse-dev, we're reluctant to add yet another config option for overriding the default power levels in a room, while doing so is possible via a Synapse module. Modules can also inject any events into a room when it is created, affording further flexibility than only m.room.power_levels events.

In terms of the difficulty of using modules with docker and with debian, making this easier would have a highly positive impact, and help in this instance.

Personally, for convenience, it may be nice to have a generic Synapse module which can be configured to inject any type of event into newly created rooms - perhaps even with rules on what rooms should and shouldn't be modified.


As for how to actually accomplish this with the module system today, you will want to write one (perhaps using our module template, also see the writing a module documentation) that makes use of the on_create_room module callback.

This callback runs when a room is created, is passed a request_content dictionary, to which a power_level_content_override key can be added/modified, with a value containing new power level rules. The content of this dictionary should match that of the power_level_content_override argument to /_matrix/client/v3/createRoom.

An example of a Synapse module that does this already can be found here.

Alternatively, any event(s) can be injected into a newly created room by modifying the initial_state attribute of request_content.


For now though, we're unlikely to implement a config option specifically for default power levels while modules can be used instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. z-p2 (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

8 participants