]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20021 Add new dismissNotice 'issueCleanCodeGuide' to DismissNoticeAction
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Wed, 2 Aug 2023 10:40:52 +0000 (12:40 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 18 Aug 2023 20:02:48 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/DismissNoticeActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DismissNoticeAction.java

index 7e5f410dbf81f2e276f8f4b81fba493627589408..401b803165f8781009ce3e4925aa420129a9a87f 100644 (file)
@@ -71,6 +71,20 @@ public class DismissNoticeActionIT {
     assertThat(propertyDto).isPresent();
   }
 
+  @Test
+  public void execute_whenNoticeIsIssueCleanCodeGuide_shouldDismissCorrespondingNotice() {
+    userSessionRule.logIn();
+
+    TestResponse testResponse = tester.newRequest()
+      .setParam("notice", "issueCleanCodeGuide")
+      .execute();
+
+    assertThat(testResponse.getStatus()).isEqualTo(204);
+
+    Optional<PropertyDto> propertyDto = db.properties().findFirstUserProperty(userSessionRule.getUuid(), "user.dismissedNotices.issueCleanCodeGuide");
+    assertThat(propertyDto).isPresent();
+  }
+
 
   @Test
   public void authentication_is_required() {
@@ -102,7 +116,7 @@ public class DismissNoticeActionIT {
 
     assertThatThrownBy(testRequest::execute)
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Value of parameter 'notice' (not_supported_value) must be one of: [educationPrinciples, sonarlintAd]");
+      .hasMessage("Value of parameter 'notice' (not_supported_value) must be one of: [educationPrinciples, sonarlintAd, issueCleanCodeGuide]");
   }
 
 
index dae5f958d051b9c1a15064e3699a006352aaf463..8db6b9768fb65556f9cdbcaf7002fb568744881d 100644 (file)
@@ -50,6 +50,7 @@ import static java.util.Optional.ofNullable;
 import static org.apache.commons.lang.StringUtils.EMPTY;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.server.user.ws.DismissNoticeAction.EDUCATION_PRINCIPLES;
+import static org.sonar.server.user.ws.DismissNoticeAction.ISSUE_CLEAN_CODE_GUIDE;
 import static org.sonar.server.user.ws.DismissNoticeAction.SONARLINT_AD;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 import static org.sonarqube.ws.Users.CurrentWsResponse.HomepageType.APPLICATION;
@@ -125,7 +126,8 @@ public class CurrentAction implements UsersWsAction {
       .setHomepage(buildHomepage(dbSession, user))
       .setUsingSonarLintConnectedMode(user.getLastSonarlintConnectionDate() != null)
       .putDismissedNotices(EDUCATION_PRINCIPLES, isNoticeDismissed(user, EDUCATION_PRINCIPLES))
-      .putDismissedNotices(SONARLINT_AD, isNoticeDismissed(user, SONARLINT_AD));
+      .putDismissedNotices(SONARLINT_AD, isNoticeDismissed(user, SONARLINT_AD))
+      .putDismissedNotices(ISSUE_CLEAN_CODE_GUIDE, isNoticeDismissed(user, ISSUE_CLEAN_CODE_GUIDE));
     ofNullable(emptyToNull(user.getEmail())).ifPresent(builder::setEmail);
     ofNullable(emptyToNull(user.getEmail())).ifPresent(u -> builder.setAvatar(avatarResolver.create(user)));
     ofNullable(user.getExternalLogin()).ifPresent(builder::setExternalIdentity);
index 1b7809499ecabb8cd3e64aa581f549d3b52f1d62..f1d2e432ddf2453ae35095c8cd805da85789ec95 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.user.ws;
 
+import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
@@ -34,6 +35,7 @@ public class DismissNoticeAction implements UsersWsAction {
 
   public static final String EDUCATION_PRINCIPLES = "educationPrinciples";
   public static final String SONARLINT_AD = "sonarlintAd";
+  public static final String ISSUE_CLEAN_CODE_GUIDE = "issueCleanCodeGuide";
   public static final String USER_DISMISS_CONSTANT = "user.dismissedNotices.";
 
   private final UserSession userSession;
@@ -48,6 +50,7 @@ public class DismissNoticeAction implements UsersWsAction {
   public void define(WebService.NewController context) {
     WebService.NewAction action = context.createAction("dismiss_notice")
       .setDescription("Dismiss a notice for the current user. Silently ignore if the notice is already dismissed.")
+      .setChangelog(new Change("10.2", "Support for new notice '%s' was added.".formatted(ISSUE_CLEAN_CODE_GUIDE)))
       .setSince("9.6")
       .setInternal(true)
       .setHandler(this)
@@ -56,7 +59,7 @@ public class DismissNoticeAction implements UsersWsAction {
     action.createParam("notice")
       .setDescription("notice key to dismiss")
       .setExampleValue(EDUCATION_PRINCIPLES)
-      .setPossibleValues(EDUCATION_PRINCIPLES, SONARLINT_AD);
+      .setPossibleValues(EDUCATION_PRINCIPLES, SONARLINT_AD, ISSUE_CLEAN_CODE_GUIDE);
   }
 
   @Override