From cca54363cce13b207615faab638212c511ca50d1 Mon Sep 17 00:00:00 2001 From: Steve Marion Date: Fri, 14 Apr 2023 17:15:09 +0200 Subject: [PATCH] [SONAR-18964] the sonarlint and SQ last connected before request fields now includes users that never connected. --- .../org/sonar/db/user/UserMapper.xml | 4 ++-- .../sonar/server/user/ws/SearchActionIT.java | 19 +++++++++++++++++++ .../sonar/server/user/ws/SearchAction.java | 12 ++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml index 791f63c990c..3f0612c39a1 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserMapper.xml @@ -188,13 +188,13 @@ AND u.last_connection_date >= #{query.lastConnectionDateFrom, jdbcType=BIGINT} - AND u.last_connection_date < #{query.lastConnectionDateTo, jdbcType=BIGINT} + AND (u.last_connection_date is null or u.last_connection_date < #{query.lastConnectionDateTo, jdbcType=BIGINT}) AND u.last_sonarlint_connection >= #{query.sonarLintLastConnectionDateFrom, jdbcType=BIGINT} - AND u.last_sonarlint_connection < #{query.sonarLintLastConnectionDateTo, jdbcType=BIGINT} + AND (u.last_sonarlint_connection is null or u.last_sonarlint_connection < #{query.sonarLintLastConnectionDateTo, jdbcType=BIGINT}) diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java index db71e878fea..4a4c315715d 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/user/ws/SearchActionIT.java @@ -529,6 +529,25 @@ public class SearchActionIT { assertUserWithFilter(SearchAction.SONAR_LINT_LAST_CONNECTION_DATE_TO, lastConnection, user.getLogin(), true); } + + @Test + public void search_whenNoLastConnection_shouldReturnForBeforeOnly() { + userSession.logIn().setSystemAdministrator(); + final Instant lastConnection = Instant.now(); + UserDto user = db.users().insertUser(u -> u + .setLogin("user-%_%-login") + .setName("user-name") + .setEmail("user@mail.com") + .setLocal(true) + .setScmAccounts(singletonList("user1"))); + + assertUserWithFilter(SearchAction.LAST_CONNECTION_DATE_FROM, lastConnection, user.getLogin(), false); + assertUserWithFilter(SearchAction.LAST_CONNECTION_DATE_TO, lastConnection, user.getLogin(), true); + + assertUserWithFilter(SearchAction.SONAR_LINT_LAST_CONNECTION_DATE_FROM, lastConnection, user.getLogin(), false); + assertUserWithFilter(SearchAction.SONAR_LINT_LAST_CONNECTION_DATE_TO, lastConnection, user.getLogin(), true); + } + @Test public void search_whenNotAdmin_shouldThrowForbidden() { userSession.logIn(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SearchAction.java index 1f83f093fde..e0d3e4d8b7a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SearchAction.java @@ -146,7 +146,8 @@ public class SearchAction implements UsersWsAction { action.createParam(LAST_CONNECTION_DATE_FROM) .setSince("10.1") .setDescription(""" - Filter the users based on the last connection date field. Only users who interacted with this instance at or after the date will be returned. + Filter the users based on the last connection date field. + Only users who interacted with this instance at or after the date will be returned. The format must be ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hhmm)""") .setRequired(false) .setDefaultValue(null) @@ -154,7 +155,8 @@ public class SearchAction implements UsersWsAction { action.createParam(LAST_CONNECTION_DATE_TO) .setSince("10.1") .setDescription(""" - Filter the users based on the last connection date field. Only users who interacted with this instance at or before the date will be returned. + Filter the users based on the last connection date field. + Only users that never connected or who interacted with this instance at or before the date will be returned. The format must be ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hhmm)""") .setRequired(false) .setDefaultValue(null) @@ -162,7 +164,8 @@ public class SearchAction implements UsersWsAction { action.createParam(SONAR_LINT_LAST_CONNECTION_DATE_FROM) .setSince("10.1") .setDescription(""" - Filter the users based on the sonar lint last connection date field. Only users who interacted with this instance using SonarLint at or after the date will be returned. + Filter the users based on the sonar lint last connection date field + Only users who interacted with this instance using SonarLint at or after the date will be returned. The format must be ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hhmm)""") .setRequired(false) .setDefaultValue(null) @@ -170,7 +173,8 @@ public class SearchAction implements UsersWsAction { action.createParam(SONAR_LINT_LAST_CONNECTION_DATE_TO) .setSince("10.1") .setDescription(""" - Filter the users based on the sonar lint last connection date field. Only users who interacted with this instance using SonarLint at or before the date will be returned. + Filter the users based on the sonar lint last connection date field. + Only users that never connected or who interacted with this instance using SonarLint at or before the date will be returned. The format must be ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hhmm)""") .setRequired(false) .setDefaultValue(null) -- 2.39.5