This module allows restricting users, that match given regular expressions, from performing actions such as creating rooms or sending invites.
Note that server administrators are not bound by these rules, as the code within Synapse exempts server administrators from some 'spam checks', including those used in this module (creating rooms and inviting users).
From the virtual environment that you use for Synapse, install this module with:
pip install path/to/synapse-user-restrictions(If you run into issues, you may need to upgrade pip first, e.g. by running
pip install --upgrade pip)
Then alter your homeserver configuration, adding to your modules configuration:
modules:
- module: synapse_user_restrictions.UserRestrictionsModule
config:
# List of rules. Earlier rules have a higher priority than later rules.
rules:
- match: "@admin.*:example.org"
allow: [invite, create_room]
- match: "@assistant.*:example.org"
allow: [invite]
# If no rules match, then these permissions are denied.
# All other permissions are allowed by default.
default_deny: [invite, create_room]In this example:
@adminalice:example.orgcould create rooms and invite users to rooms;@assistantbob:example.orgcould invite users to rooms but NOT create rooms; and@plainoldjoe:example.orgcould neither create rooms nor invite users.
Rules are applied top-to-bottom, with the first matching rule being used.
A rule matches if the regular expression (written in match) fully matches the
user's Matrix ID, and the permission being sought is either in the allow list
or the deny list.
The regular expression must match the full Matrix ID and not just a portion of it.
Valid permissions (as at the time of writing) are:
invite: the user is trying to invite another user to a roomcreate_room: the user is trying to create a room
If no rules match, then default_deny is consulted;
default_deny is useful for only allowing a select few listed user patterns to
be allowed to use certain features.
In a virtual environment with pip ≥ 21.1, run
pip install -e .[dev]To run the unit tests, you can either use:
tox -e pyor
trial testsTo run the linters and mypy type checker, use ./scripts-dev/lint.sh.
The exact steps for releasing will vary; but this is an approach taken by the Synapse developers (assuming a Unix-like shell):
-
Set a shell variable to the version you are releasing (this just makes subsequent steps easier):
version=X.Y.Z
-
Update
setup.cfgso that theversionis correct. -
Stage the changed files and commit.
git add -u git commit -m v$version -n -
Push your changes.
git push
-
When ready, create a signed tag for the release:
git tag -s v$versionBase the tag message on the changelog.
-
Push the tag.
git push origin tag v$version -
If applicable: Create a release, based on the tag you just pushed, on GitHub or GitLab.
-
If applicable: Create a source distribution and upload it to PyPI.