diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2023-08-02 12:40:52 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-18 20:02:48 +0000 |
commit | 105f998934e88b40b049dea836bd029085de34b0 (patch) | |
tree | a78cd7b2e694b7da8ff25d59927255ef4bcdb753 | |
parent | bd312b70ae05b495a6f19b43b33c4321346148d1 (diff) | |
download | sonarqube-105f998934e88b40b049dea836bd029085de34b0.tar.gz sonarqube-105f998934e88b40b049dea836bd029085de34b0.zip |
SONAR-20021 Add new dismissNotice 'issueCleanCodeGuide' to DismissNoticeAction
3 files changed, 22 insertions, 3 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/DismissNoticeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/DismissNoticeActionIT.java index 7e5f410dbf8..401b803165f 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/DismissNoticeActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/DismissNoticeActionIT.java @@ -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]"); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java index dae5f958d05..8db6b9768fb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java @@ -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); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DismissNoticeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DismissNoticeAction.java index 1b7809499ec..f1d2e432ddf 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DismissNoticeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/DismissNoticeAction.java @@ -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 |