Settings system

The page documents the Zulip settings system, and hopefully should help you decide how to correctly implement new settings you're adding to Zulip.

We have two types of administrative settings in Zulip: * Server settings are set via configuration files, and apply to the whole Zulip installation. * Realm settings (or organization settings) are usually 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).

Philosophically, the goals of the settings system are to make it convenient for:

Server settings

Zulip uses the Django settings system, which means that the settings files are Python programs that set a lot of variables with all-capital names like EMAIL_GATEWAY_PATTERN. You can access these anywhere in the Zulip Django code using e.g.:

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.:

$ ./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 of settings needed by the Zulip Django app. As a result, there are a few files involved in the Zulip settings for server administrators. In a production environment, we have:

In a development environment, we have zproject/settings.py, and additionally:

When adding a new server setting to Zulip, you will typically add it in two or three places:

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.

Testing non-default settings

You can write tests for settings using e.g. with self.settings(TERMS_OF_SERVICE=None). However, this only works for settings which are checked at runtime, not settings which are only accessed in initialization of Django (or Zulip) internals (e.g. DATABASES). See the Django docs on overriding settings in tests for more details.

Realm settings

Realm settings are preferred for any configuration that is a matter of organizational policy (as opposed to technical capabilities of the server). As a result, configuration options for user-facing functionality is almost always added as a new realm setting, not a server setting. The new feature tutorial documents the process for adding a new realm setting to Zulip.

So for example, the following server settings will eventually be replaced with realm settings: