From: zipeng-wu-sonarsource <68143726+zipeng-wu-sonarsource@users.noreply.github.com> Date: Thu, 27 Oct 2022 15:39:54 +0000 (+0200) Subject: SONAR-17515 new Properties for Login Message in the General Settings panel (#6949) X-Git-Tag: 9.8.0.63668~193 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=539b338d33b70bb58b4dfd88d5a7c3bf4f814bbf;p=sonarqube.git SONAR-17515 new Properties for Login Message in the General Settings panel (#6949) Co-authored-by: Zipeng WU --- diff --git a/build.gradle b/build.gradle index 145e368b0ac..14a5a4f3e9a 100644 --- a/build.gradle +++ b/build.gradle @@ -201,7 +201,7 @@ subprojects { dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.10.0.1456' dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.11.0.3905' dependency 'org.sonarsource.slang:sonar-scala-plugin:1.11.0.3905' - dependency 'org.sonarsource.api.plugin:sonar-plugin-api:9.11.0.290' + dependency 'org.sonarsource.api.plugin:sonar-plugin-api:9.12.0.310' dependency 'org.sonarsource.xml:sonar-xml-plugin:2.6.1.3686' dependency 'org.sonarsource.iac:sonar-iac-plugin:1.9.2.2279' dependency 'org.sonarsource.text:sonar-text-plugin:1.1.0.282' diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java index 038bbe20bac..8d14991d6b1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java @@ -48,6 +48,7 @@ import org.sonar.db.component.BranchDto; import org.sonar.db.component.ComponentDto; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.property.PropertyDto; +import org.sonar.markdown.Markdown; import org.sonar.server.component.ComponentFinder; import org.sonar.server.user.UserSession; import org.sonarqube.ws.Settings; @@ -58,6 +59,7 @@ import static java.util.stream.Stream.concat; import static org.apache.commons.lang.StringUtils.isEmpty; import static org.sonar.api.CoreProperties.SERVER_ID; import static org.sonar.api.CoreProperties.SERVER_STARTTIME; +import static org.sonar.api.PropertyType.FORMATTED_TEXT; import static org.sonar.api.PropertyType.PROPERTY_SET; import static org.sonar.api.web.UserRole.USER; import static org.sonar.server.setting.ws.PropertySetExtractor.extractPropertySetKeys; @@ -297,6 +299,8 @@ public class ValuesAction implements SettingsWsAction { } if (definition.type().equals(PROPERTY_SET)) { valueBuilder.setFieldValues(createFieldValuesBuilder(filterVisiblePropertySets(setting.getPropertySets()))); + } else if (definition.type().equals(FORMATTED_TEXT)) { + valueBuilder.setValues(createFormattedTextValuesBuilder(value)); } else if (definition.multiValues()) { valueBuilder.setValues(createValuesBuilder(value)); } else { @@ -331,6 +335,11 @@ public class ValuesAction implements SettingsWsAction { return Settings.Values.newBuilder().addAllValues(values); } + private Settings.Values.Builder createFormattedTextValuesBuilder(String value) { + List values = List.of(value, Markdown.convertToHtml(value)); + return Settings.Values.newBuilder().addAllValues(values); + } + private Settings.FieldValues.Builder createFieldValuesBuilder(List> fieldValues) { Settings.FieldValues.Builder builder = Settings.FieldValues.newBuilder(); for (Map propertySetMap : fieldValues) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index 51210fe4b8e..235be1d3c35 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -107,6 +107,26 @@ public class ValuesActionTest { assertThat(value.getInherited()).isFalse(); } + @Test + public void return_formatted_values() { + logIn(); + String propertyKey = "sonar.login.message"; + definitions.addComponent(PropertyDefinition + .builder(propertyKey) + .type(PropertyType.FORMATTED_TEXT) + .build()); + db.properties().insertProperties(null, null, null, null, newGlobalPropertyDto().setKey(propertyKey).setValue("[link](https://link.com)")); + + ValuesWsResponse result = executeRequestForGlobalProperties(propertyKey); + + assertThat(result.getSettingsList()).hasSize(1); + Settings.Setting value = result.getSettings(0); + assertThat(value.getKey()).isEqualTo(propertyKey); + assertThat(value.getValues().getValuesList()) + .hasSize(2) + .containsExactly("[link](https://link.com)", "link"); + } + @Test public void return_multi_values() { logIn(); diff --git a/sonar-ws/src/main/protobuf/ws-settings.proto b/sonar-ws/src/main/protobuf/ws-settings.proto index cbaebbb4a72..295d89664af 100644 --- a/sonar-ws/src/main/protobuf/ws-settings.proto +++ b/sonar-ws/src/main/protobuf/ws-settings.proto @@ -82,6 +82,7 @@ enum Type { PROPERTY_SET = 12; LICENSE = 13; JSON = 14; + FORMATTED_TEXT = 15; } // Response of GET api/settings/values