Files
wekan/docs/DeveloperDocs/Adding-new-Snap-settings-to-code.md
T
Lauri Ojansivu 11babe27f2 Docs: snap keys, setting guide and Docker examples that match this WeKan.
- Three snap set lines named keys the snap does not have, which snapd
  stores without a word: MONGO_OPLOG_URL (the key is mongo-oplog-url),
  oauth-enabled (oauth2-enabled) and "snap set wekan set disable-mongodb".
  tests/docsSnapKeysExist.test.cjs checks every snap set in the docs
  against the KEY_ names in snap-src/bin/config.
- Adding-new-Snap-settings-to-code.md used setting names that do not
  exist (LDAP_ENABLED, LDAP_SEARCH_FILTER, a wrong KEY_ line), the edge
  branch and Travis CI. It now follows the real config and wekan-help
  entries, says that a login setting goes through the Admin Panel catalog
  and authEnv(), and lists the other platform files a setting belongs in.
- The LDAP and Traefik Docker examples ran MongoDB 3.2/4.0 with
  --smallfiles, which MongoDB 4.2 removed, and WeKan images from 2018. They
  use mongo:7 and ghcr.io/wekan/wekan:latest; Traefik stays at v1.7, since
  that guide's labels and traefik.toml are v1 syntax.
- The Windows page no longer sets RICHER_CARD_EDITOR, which WeKan does not
  read, and points to build.bat for building from source.

Thanks to xet7 !
2026-10-16 23:52:46 +03:00

97 lines
3.3 KiB
Markdown

# Adding a new Snap setting to code
A WeKan setting is an environment variable. The snap turns `snap set wekan
<key>='<value>'` into that variable, so a new setting needs the server code,
the snap's `config` and `wekan-help`, and the other platforms' settings files.
Also see [Snap Developer Docs](https://github.com/wekan/wekan-snap/wiki/Snap-Developer-Docs).
## 1) Server code
A plain setting is read from the environment:
```js
process.env.YOURSETTING
```
Example: [server/policy.js](https://github.com/wekan/wekan/blob/main/server/policy.js).
A **login** setting (LDAP, OAuth2, CAS, SAML, the OAuth providers, header
login) can be overridden in Admin Panel / People, so it is not read from
`process.env` directly. List it in `models/lib/authConfigCatalog.js` and read it
with `authEnv('YOURSETTING')` from `server/lib/authConfig.js`, which takes the
Admin Panel value first and the environment second.
`tests/authConfigCatalog.test.cjs` fails when code reads a login variable the
catalog does not list, or reads a catalog variable straight from `process.env`.
## 2) [snap-src/bin/config](https://github.com/wekan/wekan/blob/main/snap-src/bin/config)
Add the variable's name to the end of the `keys="..."` line near the top:
```
keys="... YOURSETTING"
```
Then add its three lines at the bottom. The `KEY_` value is the lowercase,
dash-separated name used with `snap set`.
Example 1: a feature that is off by default.
```
DESCRIPTION_LDAP_ENABLE="Enable or not the connection by the LDAP"
DEFAULT_LDAP_ENABLE="false"
KEY_LDAP_ENABLE="ldap-enable"
```
Example 2: a value that is different for every server stays empty.
```
DESCRIPTION_OAUTH2_TOKEN_ENDPOINT="OAuth2 token endpoint. Example: /oauth/token"
DEFAULT_OAUTH2_TOKEN_ENDPOINT=""
KEY_OAUTH2_TOKEN_ENDPOINT="oauth2-token-endpoint"
```
Example 3: a value that is the same for most servers gets it as the default.
```
DESCRIPTION_WAIT_SPINNER="Default wait spinner to use"
DEFAULT_WAIT_SPINNER="Bounce"
KEY_WAIT_SPINNER="wait-spinner"
```
## 3) [snap-src/bin/wekan-help](https://github.com/wekan/wekan/blob/main/snap-src/bin/wekan-help)
Add how to set and unset it, above the line
`# parse config file for supported settings keys`:
```
echo -e "OAuth2 Token Endpoint."
echo -e "To enable the OAuth2 Token Endpoint of Wekan:"
echo -e "\t$ snap set $SNAP_INSTANCE_NAME oauth2-token-endpoint='/oauth/token'"
echo -e "\t-Disable the OAuth2 Token Endpoint of Wekan:"
echo -e "\t$ snap unset $SNAP_INSTANCE_NAME oauth2-token-endpoint"
echo -e "\n"
```
Use the lowercase `KEY_` name, and put the value inside single quotes. The
value may contain double quotes and spaces, but not single quotes:
```
snap set wekan ldap-user-search-filter='(&(objectCategory=person)(objectClass=user)(!(cn=andy)))'
```
## 4) The other platforms
Add the variable, commented out with an example, where the other platforms
take their settings from: `Dockerfile`, `docker-compose.yml` (and the other
`docker-compose-*.yml` files), `start-wekan.sh` and `start-wekan.bat`. For a
login setting, `tests/authConfigCatalog.test.cjs` checks that every one of them
lists it.
## 5) Check
Run the node suites (`node tests/run-node-suites.cjs`, or
the node-suite option of `./build.sh`) before committing. A contributor opens a
pull request against the `main` branch of
[wekan/wekan](https://github.com/wekan/wekan).