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;
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.
@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;
}
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;
@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");
}
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();
+ }
}