From 1badf5c3451775def0c616adb11b3b6bd6b05bc7 Mon Sep 17 00:00:00 2001 From: uhensler <urs.hensler@frentix.com> Date: Tue, 23 Apr 2019 11:42:48 +0200 Subject: [PATCH] OO-4009: Configuration of API URL --- .../onlyoffice/OnlyOfficeModule.java | 36 +++++++++++++------ .../ui/OnlyOfficeAdminController.java | 16 ++++----- .../ui/_i18n/LocalStrings_de.properties | 3 +- .../ui/_i18n/LocalStrings_en.properties | 3 +- .../resources/serviceconfig/olat.properties | 3 +- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/OnlyOfficeModule.java b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/OnlyOfficeModule.java index 0edd872c943..707d581b35e 100644 --- a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/OnlyOfficeModule.java +++ b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/OnlyOfficeModule.java @@ -43,14 +43,17 @@ import io.jsonwebtoken.security.Keys; public class OnlyOfficeModule extends AbstractSpringModule implements ConfigOnOff { private static final OLog log = Tracing.createLoggerFor(OnlyOfficeModule.class); - + private static final String ONLYOFFICE_ENABLED = "onlyoffice.enabled"; - private static final String ONLYOFFICE_API_URL = "onlyoffice.apiUrl"; + private static final String ONLYOFFICE_BASE_URL = "onlyoffice.baseUrl"; private static final String ONLYOFFICE_JWT_SECRET = "onlyoffice.jwt.secret"; @Value("${onlyoffice.enabled:false}") private boolean enabled; - @Value("${onlyoffice.apiUrl}") + @Value("${onlyoffice.baseUrl}") + private String baseUrl; + @Value("${onlyoffice.api.path}") + private String apiPath; private String apiUrl; private String jwtSecret; private Key jwtSignKey; @@ -76,9 +79,10 @@ public class OnlyOfficeModule extends AbstractSpringModule implements ConfigOnOf enabled = "true".equals(enabledObj); } - String apiUrlObj = getStringPropertyValue(ONLYOFFICE_API_URL, true); - if(StringHelper.containsNonWhitespace(apiUrlObj)) { - apiUrl = apiUrlObj; + String baseUrlObj = getStringPropertyValue(ONLYOFFICE_BASE_URL, true); + if(StringHelper.containsNonWhitespace(baseUrlObj)) { + baseUrl = baseUrlObj; + resetApiUrl(); } String jwtSecretObj = getStringPropertyValue(ONLYOFFICE_JWT_SECRET, true); @@ -97,21 +101,31 @@ public class OnlyOfficeModule extends AbstractSpringModule implements ConfigOnOf setStringProperty(ONLYOFFICE_ENABLED, Boolean.toString(enabled), true); } + public String getBaseUrl() { + return baseUrl; + } + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + setStringProperty(ONLYOFFICE_BASE_URL, baseUrl, true); + resetApiUrl(); + } + public String getApiUrl() { return apiUrl; } - - public void setApiUrl(String apiUrl) { - this.apiUrl = apiUrl; - setStringProperty(ONLYOFFICE_API_URL, apiUrl, true); + + private void resetApiUrl() { + this.apiUrl = baseUrl + apiPath; } - + public String getJwtSecret() { return jwtSecret; } public void setJwtSecret(String jwtSecret) { this.jwtSecret = jwtSecret; + this.jwtSignKey = null; setStringProperty(ONLYOFFICE_JWT_SECRET, jwtSecret, true); } diff --git a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/OnlyOfficeAdminController.java b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/OnlyOfficeAdminController.java index e786a40f5fe..354a871c7a4 100644 --- a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/OnlyOfficeAdminController.java +++ b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/OnlyOfficeAdminController.java @@ -45,7 +45,7 @@ public class OnlyOfficeAdminController extends FormBasicController { private static final String[] ENABLED_KEYS = new String[]{"on"}; private MultipleSelectionElement enabledEl; - private TextElement apiUrlEl; + private TextElement baseUrlEl; private TextElement jwtSecretEl; @Autowired @@ -66,10 +66,9 @@ public class OnlyOfficeAdminController extends FormBasicController { enabledEl = uifactory.addCheckboxesHorizontal("admin.enabled", formLayout, ENABLED_KEYS, translateAll(getTranslator(), ENABLED_KEYS)); enabledEl.select(ENABLED_KEYS[0], onlyOfficeModule.isEnabled()); - String url = onlyOfficeModule.getApiUrl(); - apiUrlEl = uifactory.addTextElement("admin.api.url", 128, url, formLayout); - apiUrlEl.setExampleKey("admin.api.url.example", null); - apiUrlEl.setMandatory(true); + String url = onlyOfficeModule.getBaseUrl(); + baseUrlEl = uifactory.addTextElement("admin.base.url", 128, url, formLayout); + baseUrlEl.setMandatory(true); String secret = onlyOfficeModule.getJwtSecret(); jwtSecretEl = uifactory.addTextElement("admin.jwt.secret", 128, secret, formLayout); @@ -85,7 +84,7 @@ public class OnlyOfficeAdminController extends FormBasicController { boolean allOk = true; if (enabledEl.isAtLeastSelected(1)) { - allOk &= validateIsMandatory(apiUrlEl); + allOk &= validateIsMandatory(baseUrlEl); boolean jwtSecretOk = validateIsMandatory(jwtSecretEl); if (jwtSecretOk && !onlyOfficeSecurityService.isValidSecret(jwtSecretEl.getValue())) { @@ -103,8 +102,9 @@ public class OnlyOfficeAdminController extends FormBasicController { boolean enabled = enabledEl.isAtLeastSelected(1); onlyOfficeModule.setEnabled(enabled); - String url = apiUrlEl.getValue(); - onlyOfficeModule.setApiUrl(url); + String url = baseUrlEl.getValue(); + url = url.endsWith("/")? url: url + "/"; + onlyOfficeModule.setBaseUrl(url); String jwtSecret = jwtSecretEl.getValue(); onlyOfficeModule.setJwtSecret(jwtSecret); diff --git a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_de.properties index a07740fd311..22f2e8fce01 100644 --- a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_de.properties @@ -1,5 +1,4 @@ -admin.api.url=API URL -admin.api.url.example=https://onlyoffice.example.org/web-apps/apps/api/documents/api.js +admin.base.url=URL admin.desc=OnlyOffice ist eine Software zur einzelnen oder gemeinsamen Bearbeitung von Dokumenten. Es unterst\u00FCtzt alle g\u00E4ngigen Dateiformate zur Textverarbeitung, Tabellenkalkulation und Pr\u00E4sentationen. Weitere Informationen sind auf der <a href\="http\://www.onlyoffice.com/" target\=_blank>Webseite</a> von OnlyOffice zu finden. admin.enabled=Modul "OnlyOffice" admin.jwt.secret=Secret diff --git a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_en.properties index 449d9eb9fc2..c51bc4467c1 100644 --- a/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/core/commons/services/doceditor/onlyoffice/ui/_i18n/LocalStrings_en.properties @@ -1,5 +1,4 @@ -admin.api.url=API URL -admin.api.url.example=https://onlyoffice.example.org/web-apps/apps/api/documents/api.js +admin.base.url=URL admin.desc=OnylOffice is a software to edit documents online. It supports all major document, spreadsheet and presentation file formats. Key features are collaborative editing and excellent office file format support. Further information is available on the <a href\="https\://www.onlyoffice.com/" target\=_blank>website</a> of OnlyOffice admin.enabled=Module "OnylOffice" admin.jwt.secret=Secret diff --git a/src/main/resources/serviceconfig/olat.properties b/src/main/resources/serviceconfig/olat.properties index 83eefb19be8..ddb685524f8 100644 --- a/src/main/resources/serviceconfig/olat.properties +++ b/src/main/resources/serviceconfig/olat.properties @@ -1503,7 +1503,8 @@ collabora.baseUrl=https://collabora.example.org/ # Options for OnlyOffice ######################################## onlyoffice.enabled=false -onlyoffice.apiUrl=https://onlyoffice.example.org/web-apps/apps/api/documents/api.js +onlyoffice.baseUrl=https://onlyoffice.example.org/ +onlyoffice.api.path=web-apps/apps/api/documents/api.js ######################################## -- GitLab