]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17515 new Properties for Login Message in the General Settings panel (#6949)
authorzipeng-wu-sonarsource <68143726+zipeng-wu-sonarsource@users.noreply.github.com>
Thu, 27 Oct 2022 15:39:54 +0000 (17:39 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 27 Oct 2022 20:03:02 +0000 (20:03 +0000)
Co-authored-by: Zipeng WU <zipeng.wu@sonarsource.com>
build.gradle
server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/ValuesAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java
sonar-ws/src/main/protobuf/ws-settings.proto

index 145e368b0aced871674c670160a958471ff25f3b..14a5a4f3e9a4b7151997b2c8d2b0a0627f04cd08 100644 (file)
@@ -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'
index 038bbe20bacfc3c2ef8aa75e0d19fa4062aced3d..8d14991d6b1d630f3901307360b18019a53eca66 100644 (file)
@@ -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<String> values = List.of(value, Markdown.convertToHtml(value));
+      return Settings.Values.newBuilder().addAllValues(values);
+    }
+
     private Settings.FieldValues.Builder createFieldValuesBuilder(List<Map<String, String>> fieldValues) {
       Settings.FieldValues.Builder builder = Settings.FieldValues.newBuilder();
       for (Map<String, String> propertySetMap : fieldValues) {
index 51210fe4b8e4c3c36677f7f78728ece09a81ce1e..235be1d3c352a1e81fb68a020f27eb78e591cb40 100644 (file)
@@ -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)", "<a href=\"https://link.com\" target=\"_blank\">link</a>");
+  }
+
   @Test
   public void return_multi_values() {
     logIn();
index cbaebbb4a72295ea970e0ee8fafecd882169375b..295d89664af881fd6291524b59898bb6c8249a82 100644 (file)
@@ -82,6 +82,7 @@ enum Type {
   PROPERTY_SET = 12;
   LICENSE = 13;
   JSON = 14;
+  FORMATTED_TEXT = 15;
 }
 
 // Response of GET api/settings/values