From 88587752a1ca7c0b6b29bd02a49ebce08126b9a8 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 29 Apr 2016 14:29:28 +0200 Subject: [PATCH] SONAR-7213 Ignore disabled users when searching for default assignee --- .../server/computation/issue/DefaultAssignee.java | 9 +++++---- .../server/computation/issue/DefaultAssigneeTest.java | 10 +++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/DefaultAssignee.java b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/DefaultAssignee.java index 3959ab8375a..3251c06d10b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/issue/DefaultAssignee.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/issue/DefaultAssignee.java @@ -21,7 +21,6 @@ package org.sonar.server.computation.issue; import com.google.common.base.Strings; import javax.annotation.CheckForNull; -import org.sonar.api.CoreProperties; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.server.computation.component.SettingsRepository; @@ -29,6 +28,8 @@ import org.sonar.server.computation.component.TreeRootHolder; import org.sonar.server.user.index.UserDoc; import org.sonar.server.user.index.UserIndex; +import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE; + /** * The user who is optionally declared as being the assignee * of all the issues which SCM author is not associated with any SonarQube user. @@ -53,7 +54,7 @@ public class DefaultAssignee { @CheckForNull public String getLogin() { if (!loaded) { - String configuredLogin = settingsRepository.getSettings(treeRootHolder.getRoot()).getString(CoreProperties.DEFAULT_ISSUE_ASSIGNEE); + String configuredLogin = settingsRepository.getSettings(treeRootHolder.getRoot()).getString(DEFAULT_ISSUE_ASSIGNEE); if (!Strings.isNullOrEmpty(configuredLogin) && isValidLogin(configuredLogin)) { this.login = configuredLogin; } @@ -64,8 +65,8 @@ public class DefaultAssignee { private boolean isValidLogin(String s) { UserDoc user = userIndex.getNullableByLogin(s); - if (user == null) { - LOG.info("Property {} is set with an unknown login: {}", CoreProperties.DEFAULT_ISSUE_ASSIGNEE, s); + if (user == null || !user.active()) { + LOG.info("Property {} is set with an unknown login: {}", DEFAULT_ISSUE_ASSIGNEE, s); return false; } return true; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DefaultAssigneeTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DefaultAssigneeTest.java index 5eb2be95ca2..4377d055198 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DefaultAssigneeTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/issue/DefaultAssigneeTest.java @@ -59,7 +59,7 @@ public class DefaultAssigneeTest { @Test public void default_assignee() { settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik"); - when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik")); + when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik").setActive(true)); assertThat(underTest.getLogin()).isEqualTo("erik"); } @@ -71,4 +71,12 @@ public class DefaultAssigneeTest { assertThat(underTest.getLogin()).isNull(); } + + @Test + public void configured_login_is_disabled() { + settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik"); + when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik").setActive(false)); + + assertThat(underTest.getLogin()).isNull(); + } } -- 2.39.5