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

Commit

Permalink
Merge branch 'develop' into dmr/typing/wip
Browse files Browse the repository at this point in the history
  • Loading branch information
David Robertson committed Oct 7, 2021
2 parents 79fcc8c + 7301019 commit 0e68a4b
Show file tree
Hide file tree
Showing 56 changed files with 613 additions and 182 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Automatically request reviews from the synapse-core team when a pull request comes in.
* @matrix-org/synapse-core
1 change: 1 addition & 0 deletions changelog.d/10894.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a `user_may_send_3pid_invite` spam checker callback for modules to allow or deny 3PID invites.
1 change: 1 addition & 0 deletions changelog.d/10910.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a spam checker callback to allow or deny room joins.
1 change: 1 addition & 0 deletions changelog.d/10985.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use direct references to config flags.
1 change: 1 addition & 0 deletions changelog.d/10990.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add additional content to the Welcome and Overview page of the documentation.
1 change: 1 addition & 0 deletions changelog.d/10994.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a `CODEOWNERS` file to automatically request reviews from the `@matrix-org/synapse-core` team on new pull requests.
1 change: 1 addition & 0 deletions changelog.d/10995.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correct a bugfix introduced in Synapse v1.44.0 that wouldn't catch every error of the connection breaks before a response could be written to it.
1 change: 1 addition & 0 deletions changelog.d/11002.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where local users' per-room nicknames/avatars were visible to anyone who could see you in the user_directory.
1 change: 1 addition & 0 deletions changelog.d/11004.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add further type hints to `synapse.state`.
1 change: 1 addition & 0 deletions changelog.d/11010.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up some of the federation event authentication code for clarity.
1 change: 1 addition & 0 deletions changelog.d/11011.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up some of the federation event authentication code for clarity.
1 change: 1 addition & 0 deletions changelog.d/11019.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that cache config tests do not share state.
2 changes: 1 addition & 1 deletion docs/development/contributing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TBD

# 5. Get in touch.

Join our developer community on Matrix: #synapse-dev:matrix.org !
Join our developer community on Matrix: [#synapse-dev:matrix.org](https://matrix.to/#/#synapse-dev:matrix.org)!


# 6. Pick an issue.
Expand Down
50 changes: 50 additions & 0 deletions docs/modules/spam_checker_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ either a `bool` to indicate whether the event must be rejected because of spam,
to indicate the event must be rejected because of spam and to give a rejection reason to
forward to clients.

### `user_may_join_room`

```python
async def user_may_join_room(user: str, room: str, is_invited: bool) -> bool
```

Called when a user is trying to join a room. The module must return a `bool` to indicate
whether the user can join the room. The user is represented by their Matrix user ID (e.g.
`@alice:example.com`) and the room is represented by its Matrix ID (e.g.
`!room:example.com`). The module is also given a boolean to indicate whether the user
currently has a pending invite in the room.

This callback isn't called if the join is performed by a server administrator, or in the
context of a room creation.

### `user_may_invite`

```python
Expand All @@ -29,6 +44,41 @@ Called when processing an invitation. The module must return a `bool` indicating
the inviter can invite the invitee to the given room. Both inviter and invitee are
represented by their Matrix user ID (e.g. `@alice:example.com`).

### `user_may_send_3pid_invite`

```python
async def user_may_send_3pid_invite(
inviter: str,
medium: str,
address: str,
room_id: str,
) -> bool
```

Called when processing an invitation using a third-party identifier (also called a 3PID,
e.g. an email address or a phone number). The module must return a `bool` indicating
whether the inviter can invite the invitee to the given room.

The inviter is represented by their Matrix user ID (e.g. `@alice:example.com`), and the
invitee is represented by its medium (e.g. "email") and its address
(e.g. `alice@example.com`). See [the Matrix specification](https://matrix.org/docs/spec/appendices#pid-types)
for more information regarding third-party identifiers.

For example, a call to this callback to send an invitation to the email address
`alice@example.com` would look like this:

```python
await user_may_send_3pid_invite(
"@bob:example.com", # The inviter's user ID
"email", # The medium of the 3PID to invite
"alice@example.com", # The address of the 3PID to invite
"!some_room:example.com", # The ID of the room to send the invite into
)
```

**Note**: If the third-party identifier is already associated with a matrix user ID,
[`user_may_invite`](#user_may_invite) will be used instead.

### `user_may_create_room`

```python
Expand Down
74 changes: 74 additions & 0 deletions docs/welcome_and_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,77 @@
Welcome to the documentation repository for Synapse, a
[Matrix](https://matrix.org) homeserver implementation developed by the matrix.org core
team.

## Installing and using Synapse

This documentation covers topics for **installation**, **configuration** and
**maintainence** of your Synapse process:

* Learn how to [install](setup/installation.md) and
[configure](usage/configuration/index.html) your own instance, perhaps with [Single
Sign-On](usage/configuration/user_authentication/index.html).

* See how to [upgrade](upgrade.md) between Synapse versions.

* Administer your instance using the [Admin
API](usage/administration/admin_api/index.html), installing [pluggable
modules](modules/index.html), or by accessing the [manhole](manhole.md).

* Learn how to [read log lines](usage/administration/request_log.md), configure
[logging](usage/configuration/logging_sample_config.md) or set up [structured
logging](structured_logging.md).

* Scale Synapse through additional [worker processes](workers.md).

* Set up [monitoring and metrics](metrics-howto.md) to keep an eye on your
Synapse instance's performance.

## Developing on Synapse

Contributions are welcome! Synapse is primarily written in
[Python](https://python.org). As a developer, you may be interested in the
following documentation:

* Read the [Contributing Guide](development/contributing_guide.md). It is meant
to walk new contributors through the process of developing and submitting a
change to the Synapse codebase (which is [hosted on
GitHub](https://github.com/matrix-org/synapse)).

* Set up your [development
environment](development/contributing_guide.md#2-what-do-i-need), then learn
how to [lint](development/contributing_guide.md#run-the-linters) and
[test](development/contributing_guide.md#8-test-test-test) your code.

* Look at [the issue tracker](https://github.com/matrix-org/synapse/issues) for
bugs to fix or features to add. If you're new, it may be best to start with
those labeled [good first
issue](https://github.com/matrix-org/synapse/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).

* Understand [how Synapse is
built](development/internal_documentation/index.html), how to [migrate
database schemas](development/database_schema.md), learn about
[federation](federate.md) and how to [set up a local
federation](federate.md#running-a-demo-federation-of-synapses) for development.

* We like to keep our `git` history clean. [Learn](development/git.md) how to
do so!

* And finally, contribute to this documentation! The source for which is
[located here](https://github.com/matrix-org/synapse/tree/develop/docs).

## Donating to Synapse development

Want to help keep Synapse going but don't know how to code? Synapse is a
[Matrix.org Foundation](https://matrix.org) project. Consider becoming a
supportor on [Liberapay](https://liberapay.com/matrixdotorg),
[Patreon](https://patreon.com/matrixdotorg) or through
[PayPal](https://paypal.me/matrixdotorg) via a one-time donation.

If you are an organisation or enterprise and would like to sponsor development,
reach out to us over email at: support (at) matrix.org

## Reporting a security vulnerability

If you've found a security issue in Synapse or any other Matrix.org Foundation
project, please report it to us in accordance with our [Security Disclosure
Policy](https://www.matrix.org/security-disclosure-policy/). Thank you!
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ disallow_untyped_defs = True
[mypy-synapse.rest.*]
disallow_untyped_defs = True

[mypy-synapse.state.*]
disallow_untyped_defs = True

[mypy-synapse.util.batching_queue]
disallow_untyped_defs = True

Expand Down
4 changes: 2 additions & 2 deletions scripts/synapse_port_db
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class MockHomeserver:
def __init__(self, config):
self.clock = Clock(reactor)
self.config = config
self.hostname = config.server_name
self.hostname = config.server.server_name
self.version_string = "Synapse/" + get_version_string(synapse)

def get_clock(self):
Expand Down Expand Up @@ -583,7 +583,7 @@ class Porter(object):
return

self.postgres_store = self.build_db_store(
self.hs_config.get_single_database()
self.hs_config.database.get_single_database()
)

await self.run_background_updates_on_postgres()
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_synapse_database
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MockHomeserver(HomeServer):

def __init__(self, config, **kwargs):
super(MockHomeserver, self).__init__(
config.server_name, reactor=reactor, config=config, **kwargs
config.server.server_name, reactor=reactor, config=config, **kwargs
)

self.version_string = "Synapse/" + get_version_string(synapse)
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def refresh_certificate(hs):
if not hs.config.server.has_tls_listener():
return

hs.config.read_certificate_from_disk()
hs.config.tls.read_certificate_from_disk()
hs.tls_server_context_factory = context_factory.ServerContextFactory(hs.config)

if hs._listening_services:
Expand Down
4 changes: 2 additions & 2 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ def start(config_options):
# Explicitly disable background processes
config.server.update_user_directory = False
config.worker.run_background_tasks = False
config.start_pushers = False
config.worker.start_pushers = False
config.pusher_shard_config.instances = []
config.send_federation = False
config.worker.send_federation = False
config.federation_shard_config.instances = []

synapse.events.USE_FROZEN_DICTS = config.server.use_frozen_dicts
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _configure_named_resource(self, name, compress=False):
)

if name in ["media", "federation", "client"]:
if self.config.media.enable_media_repo:
if self.config.server.enable_media_repo:
media_repo = self.get_media_repository_resource()
resources.update(
{MEDIA_PREFIX: media_repo, LEGACY_MEDIA_PREFIX: media_repo}
Expand Down
64 changes: 8 additions & 56 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ def __init__(self, root_config=None):
"synapse", "res/templates"
)

def __getattr__(self, item: str) -> Any:
"""
Try and fetch a configuration option that does not exist on this class.
This is so that existing configs that rely on `self.value`, where value
is actually from a different config section, continue to work.
"""
if item in ["generate_config_section", "read_config"]:
raise AttributeError(item)

if self.root is None:
raise AttributeError(item)
else:
return self.root._get_unclassed_config(self.section, item)

@staticmethod
def parse_size(value):
if isinstance(value, int):
Expand Down Expand Up @@ -289,7 +274,9 @@ def read_templates(
env.filters.update(
{
"format_ts": _format_ts_filter,
"mxc_to_http": _create_mxc_to_http_filter(self.public_baseurl),
"mxc_to_http": _create_mxc_to_http_filter(
self.root.server.public_baseurl
),
}
)

Expand All @@ -311,8 +298,6 @@ class RootConfig:
config_classes = []

def __init__(self):
self._configs = OrderedDict()

for config_class in self.config_classes:
if config_class.section is None:
raise ValueError("%r requires a section name" % (config_class,))
Expand All @@ -321,42 +306,7 @@ def __init__(self):
conf = config_class(self)
except Exception as e:
raise Exception("Failed making %s: %r" % (config_class.section, e))
self._configs[config_class.section] = conf

def __getattr__(self, item: str) -> Any:
"""
Redirect lookups on this object either to config objects, or values on
config objects, so that `config.tls.blah` works, as well as legacy uses
of things like `config.server.server_name`. It will first look up the config
section name, and then values on those config classes.
"""
if item in self._configs.keys():
return self._configs[item]

return self._get_unclassed_config(None, item)

def _get_unclassed_config(self, asking_section: Optional[str], item: str):
"""
Fetch a config value from one of the instantiated config classes that
has not been fetched directly.
Args:
asking_section: If this check is coming from a Config child, which
one? This section will not be asked if it has the value.
item: The configuration value key.
Raises:
AttributeError if no config classes have the config key. The body
will contain what sections were checked.
"""
for key, val in self._configs.items():
if key == asking_section:
continue

if item in dir(val):
return getattr(val, item)

raise AttributeError(item, "not found in %s" % (list(self._configs.keys()),))
setattr(self, config_class.section, conf)

def invoke_all(self, func_name: str, *args, **kwargs) -> MutableMapping[str, Any]:
"""
Expand All @@ -373,9 +323,11 @@ def invoke_all(self, func_name: str, *args, **kwargs) -> MutableMapping[str, Any
"""
res = OrderedDict()

for name, config in self._configs.items():
for config_class in self.config_classes:
config = getattr(self, config_class.section)

if hasattr(config, func_name):
res[name] = getattr(config, func_name)(*args, **kwargs)
res[config_class.section] = getattr(config, func_name)(*args, **kwargs)

return res

Expand Down
2 changes: 1 addition & 1 deletion synapse/config/account_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def read_config(self, config, **kwargs):
)

if self.account_validity_renew_by_email_enabled:
if not self.public_baseurl:
if not self.root.server.public_baseurl:
raise ConfigError("Can't send renewal emails without 'public_baseurl'")

# Load account validity templates.
Expand Down
2 changes: 1 addition & 1 deletion synapse/config/cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read_config(self, config, **kwargs):

# The public baseurl is required because it is used by the redirect
# template.
public_baseurl = self.public_baseurl
public_baseurl = self.root.server.public_baseurl
if not public_baseurl:
raise ConfigError("cas_config requires a public_baseurl to be set")

Expand Down
Loading

0 comments on commit 0e68a4b

Please sign in to comment.