From bfaa834f29fff1a16ec355ff64f0bdc6d02c39e3 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 14 Oct 2026 13:34:52 +0200 Subject: [PATCH] fix(web-app-nextcloud): write onlyoffice's server URL last and recheck it The role writes onlyoffice's settings with one occ call per key, DocumentServerUrl first and jwt_secret fourth. Nextcloud loads app config once per process, so a cron.php that starts inside that batch runs onlyoffice's EditorsCheck job, registered when the app was enabled, with the document server URL but without the secret. The document server answers "Invalid token", EditorsCheck stores it in settings_error, and onlyoffice stops loading its Files integration; EditorsCheck itself skips every later run while that error is set. Seen in run 38455782184 (Nextcloud#4, swarm): cron.php started at 06:50:00 inside the batch that ran from 06:49:59 to 06:50:04, logged "Invalid token" at 06:50:22, and both Playwright passes found .docx files offered for download only. DocumentServerUrl is now written last, so a process that cached the config before the batch ended sees no URL and EditorsCheck returns early. After the batch, `occ onlyoffice:documentserver --check` sets settings_error from a fresh check: a redeploy clears an error latched earlier, and a document server that stays unreachable fails the deploy. A unit test keeps the URL last. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../meta/addons/onlyoffice.yml | 6 ++--- .../tasks/addons/onlyoffice.yml | 8 +++++++ .../test_onlyoffice_configuration_order.py | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tests/unit/python/roles/web-app-nextcloud/test_onlyoffice_configuration_order.py diff --git a/roles/web-app-nextcloud/meta/addons/onlyoffice.yml b/roles/web-app-nextcloud/meta/addons/onlyoffice.yml index e1ee56880b..ba5d4aa6b6 100644 --- a/roles/web-app-nextcloud/meta/addons/onlyoffice.yml +++ b/roles/web-app-nextcloud/meta/addons/onlyoffice.yml @@ -16,9 +16,6 @@ config: - richdocuments - fileslibreofficeedit plugin_configuration: - - appid: "onlyoffice" - configkey: "DocumentServerUrl" - configvalue: "{{ NEXTCLOUD_ONLYOFFICE_URL }}" - appid: "onlyoffice" configkey: "DocumentServerInternalUrl" configvalue: "{{ NEXTCLOUD_ONLYOFFICE_URL }}" @@ -34,3 +31,6 @@ config: - appid: "onlyoffice" configkey: "verify_peer_off" configvalue: "false" + - appid: "onlyoffice" + configkey: "DocumentServerUrl" + configvalue: "{{ NEXTCLOUD_ONLYOFFICE_URL }}" diff --git a/roles/web-app-nextcloud/tasks/addons/onlyoffice.yml b/roles/web-app-nextcloud/tasks/addons/onlyoffice.yml index ed97d539c0..54763fb5c3 100644 --- a/roles/web-app-nextcloud/tasks/addons/onlyoffice.yml +++ b/roles/web-app-nextcloud/tasks/addons/onlyoffice.yml @@ -1 +1,9 @@ --- +- name: "🔎 Check the document server round trip and reset onlyoffice's settings_error" + shell: > + {{ NEXTCLOUD_DOCKER_EXEC_OCC }} onlyoffice:documentserver --check + register: nextcloud_onlyoffice_check + until: nextcloud_onlyoffice_check.rc == 0 + retries: 30 + delay: 10 + changed_when: false diff --git a/tests/unit/python/roles/web-app-nextcloud/test_onlyoffice_configuration_order.py b/tests/unit/python/roles/web-app-nextcloud/test_onlyoffice_configuration_order.py new file mode 100644 index 0000000000..46842ce58f --- /dev/null +++ b/tests/unit/python/roles/web-app-nextcloud/test_onlyoffice_configuration_order.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +import unittest + +from utils.cache.files import PROJECT_ROOT, read_text +from utils.cache.yaml import load_yaml_str + +ADDON = PROJECT_ROOT / "roles/web-app-nextcloud/meta/addons/onlyoffice.yml" + + +class TestOnlyofficeConfigurationOrder(unittest.TestCase): + def test_the_document_server_url_is_written_last(self) -> None: + config = load_yaml_str(read_text(str(ADDON)))["config"]["plugin_configuration"] + self.assertEqual( + config[-1]["configkey"], + "DocumentServerUrl", + "a cron.php that caches app config before the last write must see no " + "DocumentServerUrl, or onlyoffice's EditorsCheck runs without jwt_secret " + "and latches settings_error", + ) + + +if __name__ == "__main__": + unittest.main()