2016-06-26 18:49:35 +02:00
|
|
|
# Settings system
|
2016-06-16 08:44:01 +02:00
|
|
|
|
|
|
|
The page documents the Zulip settings system, and hopefully should
|
|
|
|
help you decide how to correctly implement new settings you're adding
|
2017-09-29 02:01:36 +02:00
|
|
|
to Zulip.
|
|
|
|
|
|
|
|
We have two types of administrative settings in Zulip:
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- **Server settings** are set via configuration files, and apply to
|
2017-09-29 02:01:36 +02:00
|
|
|
the whole Zulip installation.
|
2021-08-20 21:45:39 +02:00
|
|
|
- **Realm settings** (or **organization settings**) are usually
|
2017-09-29 02:01:36 +02:00
|
|
|
set via the /#organization page in the Zulip web application, and
|
|
|
|
apply to a single Zulip realm/organization. (Which, for most Zulip
|
|
|
|
servers, is the only realm on the server).
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2016-07-25 20:40:50 +02:00
|
|
|
Philosophically, the goals of the settings system are to make it
|
|
|
|
convenient for:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Zulip server administrators to configure
|
2021-09-08 21:21:46 +02:00
|
|
|
Zulip's feature set for their server without needing to patch Zulip
|
2021-08-20 21:45:39 +02:00
|
|
|
- Realm administrators to configure settings for their organization
|
2021-08-20 22:54:08 +02:00
|
|
|
independently without needing to talk with the server administrator.
|
2021-08-20 21:45:39 +02:00
|
|
|
- Secrets (passwords, API keys, etc.) to be stored in a separate place
|
2021-08-20 22:54:08 +02:00
|
|
|
from shareable configuration.
|
2016-07-25 20:40:50 +02:00
|
|
|
|
2016-06-16 08:44:01 +02:00
|
|
|
## Server settings
|
|
|
|
|
|
|
|
Zulip uses the [Django settings
|
2021-11-05 20:09:57 +01:00
|
|
|
system](https://docs.djangoproject.com/en/3.2/topics/settings/), which
|
2016-06-16 08:44:01 +02:00
|
|
|
means that the settings files are Python programs that set a lot of
|
2021-08-20 21:53:28 +02:00
|
|
|
variables with all-capital names like `EMAIL_GATEWAY_PATTERN`. You can
|
2016-06-16 08:44:01 +02:00
|
|
|
access these anywhere in the Zulip Django code using e.g.:
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```python
|
2016-06-16 08:44:01 +02:00
|
|
|
from django.conf import settings
|
|
|
|
print(settings.EMAIL_GATEWAY_PATTERN)
|
|
|
|
```
|
|
|
|
|
|
|
|
Additionally, if you need to access a Django setting in a shell
|
|
|
|
script (or just on the command line for debugging), you can use e.g.:
|
|
|
|
|
2021-08-20 07:09:04 +02:00
|
|
|
```console
|
2016-06-16 08:44:01 +02:00
|
|
|
$ ./scripts/get-django-setting EMAIL_GATEWAY_PATTERN
|
|
|
|
%s@localhost:9991
|
|
|
|
```
|
|
|
|
|
|
|
|
Zulip has separated those settings that we expect a system
|
|
|
|
administrator to change (with nice documentation) from the ~1000 lines
|
2021-08-20 21:53:28 +02:00
|
|
|
of settings needed by the Zulip Django app. As a result, there are a
|
2017-04-07 21:39:58 +02:00
|
|
|
few files involved in the Zulip settings for server administrators.
|
2016-06-17 20:47:47 +02:00
|
|
|
In a production environment, we have:
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `/etc/zulip/settings.py` (the template is in the Zulip repo at
|
2016-07-20 05:45:50 +02:00
|
|
|
`zproject/prod_settings_template.py`) is the main system
|
2021-08-20 21:53:28 +02:00
|
|
|
administrator-facing settings file for Zulip. It contains all the
|
2016-06-16 08:44:01 +02:00
|
|
|
server-specific settings, such as how to send outgoing email, the
|
2020-10-26 22:27:53 +01:00
|
|
|
hostname of the PostgreSQL database, etc., but does not contain any
|
2016-06-16 08:44:01 +02:00
|
|
|
secrets (e.g. passwords, secret API keys, cryptographic keys, etc.).
|
2016-06-17 20:47:47 +02:00
|
|
|
The way we generally do settings that can be controlled with shell
|
|
|
|
access to a Zulip server is to put a default in
|
2021-08-20 21:53:28 +02:00
|
|
|
`zproject/default_settings.py`, and then override it here. As this
|
2021-04-22 00:04:09 +02:00
|
|
|
is the main documentation for Zulip settings, we recommend that
|
|
|
|
production installations [carefully update `/etc/zulip/settings.py`
|
|
|
|
every major
|
|
|
|
release](../production/upgrade-or-modify.html#updating-settings-py-inline-documentation)
|
|
|
|
to pick up new inline documentation.
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `/etc/zulip/zulip-secrets.conf` (generated by
|
2016-10-06 02:47:05 +02:00
|
|
|
`scripts/setup/generate_secrets.py` as part of installation)
|
2021-08-20 21:53:28 +02:00
|
|
|
contains secrets used by the Zulip installation. These are read
|
2021-12-02 23:42:36 +01:00
|
|
|
using the [standard Python
|
|
|
|
`RawConfigParser`](https://docs.python.org/3/library/configparser.html#configparser.RawConfigParser),
|
|
|
|
and accessed in `zproject/computed_settings.py` by the `get_secret`
|
|
|
|
function. All secrets/API keys/etc. used by the Zulip Django
|
|
|
|
application should be stored here, and read using the `get_secret`
|
|
|
|
function in `zproject/config.py`.
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/settings.py` is the main Django settings file for Zulip.
|
2020-06-08 03:58:37 +02:00
|
|
|
It imports everything from `zproject/configured_settings.py` and
|
|
|
|
`zproject/computed_settings.py`.
|
2020-06-08 03:44:48 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/configured_settings.py` imports everything from
|
2020-06-08 03:44:48 +02:00
|
|
|
`zproject/default_settings.py`, then in a prod environment imports
|
|
|
|
`/etc/zulip/settings.py` via a symlink.
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/default_settings.py` has the default values for the settings the
|
2019-11-13 01:22:15 +01:00
|
|
|
user would set in `/etc/zulip/settings.py`.
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/computed_settings.py` contains all the settings that are
|
2020-06-08 03:58:37 +02:00
|
|
|
constant for all Zulip installations or computed as a function of
|
|
|
|
`zproject/configured_settings.py` (e.g. configuration for logging,
|
|
|
|
static assets, middleware, etc.).
|
|
|
|
|
2016-06-17 20:47:47 +02:00
|
|
|
In a development environment, we have `zproject/settings.py`, and
|
|
|
|
additionally:
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/dev_settings.py` has the custom settings for the Zulip development
|
2021-04-07 06:18:46 +02:00
|
|
|
environment; these are set after importing `prod_settings_template.py`.
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/dev-secrets.conf` replaces
|
2021-08-20 21:53:28 +02:00
|
|
|
`/etc/zulip/zulip-secrets.conf`, and is not tracked by Git. This
|
2021-04-07 06:18:46 +02:00
|
|
|
allows you to configure your development environment to support
|
|
|
|
features like [authentication
|
|
|
|
options](../development/authentication.md) that require secrets to
|
2021-08-20 21:53:28 +02:00
|
|
|
work. It is also used to set certain settings that in production
|
2021-04-07 06:18:46 +02:00
|
|
|
belong in `/etc/zulip/settings.py`, e.g. `SOCIAL_AUTH_GITHUB_KEY`.
|
|
|
|
You can see a full list with `git grep development_only=True`, or
|
|
|
|
add additional settings of this form if needed.
|
2016-06-17 20:47:47 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/test_settings.py` imports everything from
|
2020-06-08 05:56:03 +02:00
|
|
|
`zproject/settings.py` and `zproject/test_extra_settings.py`.
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/test_extra_settings.py` has the (default) settings used
|
2020-08-31 00:10:57 +02:00
|
|
|
for the Zulip tests (both backend and Puppeteer), which are applied on
|
2020-06-08 05:56:03 +02:00
|
|
|
top of the development environment settings.
|
2016-06-16 08:44:01 +02:00
|
|
|
|
|
|
|
When adding a new server setting to Zulip, you will typically add it
|
|
|
|
in two or three places:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `zproject/default_settings.py`, with a default value
|
2019-11-13 01:22:15 +01:00
|
|
|
for production environments.
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- If the settings has a secret key,
|
2020-08-19 21:55:28 +02:00
|
|
|
you'll add a `get_secret` call in `zproject/computed_settings.py` (and the
|
2016-07-25 20:36:28 +02:00
|
|
|
user will add the value when they configure the feature).
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- In an appropriate section of `zproject/prod_settings_template.py`,
|
2017-09-29 02:01:36 +02:00
|
|
|
with documentation in the comments explaining the setting's
|
2016-06-16 08:44:01 +02:00
|
|
|
purpose and effect.
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- Possibly also `zproject/dev_settings.py` and/or
|
2017-09-29 02:01:36 +02:00
|
|
|
`zproject/test_settings.py`, if the desired value of the setting for
|
|
|
|
Zulip development and/or test environments is different from the
|
|
|
|
default for production.
|
2016-06-16 08:44:01 +02:00
|
|
|
|
|
|
|
Most settings should be enabled in the development environment, to
|
|
|
|
maximize convenience of testing all of Zulip's features; they should
|
|
|
|
be enabled by default in production if we expect most Zulip sites to
|
|
|
|
want those settings.
|
|
|
|
|
2017-11-02 21:05:21 +01:00
|
|
|
### Testing non-default settings
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2021-09-08 00:23:24 +02:00
|
|
|
You can write tests for settings using e.g.
|
2021-08-20 21:53:28 +02:00
|
|
|
`with self.settings(TERMS_OF_SERVICE=None)`. However, this only works
|
2021-09-08 00:23:24 +02:00
|
|
|
for settings which are checked at runtime, not settings which are only
|
2016-06-16 08:44:01 +02:00
|
|
|
accessed in initialization of Django (or Zulip) internals
|
2021-08-20 21:53:28 +02:00
|
|
|
(e.g. `DATABASES`). See the [Django docs on overriding settings in
|
2016-06-16 08:44:01 +02:00
|
|
|
tests][django-test-settings] for more details.
|
|
|
|
|
2021-11-05 20:09:57 +01:00
|
|
|
[django-test-settings]: https://docs.djangoproject.com/en/3.2/topics/testing/tools/#overriding-settings
|
2016-06-16 08:44:01 +02:00
|
|
|
|
|
|
|
## Realm settings
|
|
|
|
|
|
|
|
Realm settings are preferred for any configuration that is a matter of
|
|
|
|
organizational policy (as opposed to technical capabilities of the
|
2021-08-20 21:53:28 +02:00
|
|
|
server). As a result, configuration options for user-facing
|
2016-06-16 08:44:01 +02:00
|
|
|
functionality is almost always added as a new realm setting, not a
|
2021-08-20 21:53:28 +02:00
|
|
|
server setting. The [new feature tutorial][doc-newfeat] documents the
|
2016-06-16 08:44:01 +02:00
|
|
|
process for adding a new realm setting to Zulip.
|
|
|
|
|
|
|
|
So for example, the following server settings will eventually be
|
|
|
|
replaced with realm settings:
|
|
|
|
|
2021-08-20 21:45:39 +02:00
|
|
|
- `NAME_CHANGES_DISABLED`
|
|
|
|
- `INLINE_IMAGE_PREVIEW`
|
|
|
|
- `ENABLE_GRAVATAR`
|
|
|
|
- Which authentication methods are allowed should probably appear in
|
2016-06-16 08:44:01 +02:00
|
|
|
both places; in server settings indicating the capabilities of the
|
|
|
|
server, and in the realm settings indicating which methods the realm
|
2020-08-11 02:20:10 +02:00
|
|
|
administrator wants to allow users to log in with.
|
2016-06-16 08:44:01 +02:00
|
|
|
|
2019-09-30 19:37:56 +02:00
|
|
|
[doc-newfeat]: ../tutorials/new-feature-tutorial.md
|