"schema_migrations",
"scim_groups",
"scim_users",
+ "scm_accounts",
"session_tokens",
"snapshots",
"users",
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
assertThat(underTest.selectByUuid(session, "unknown")).isNull();
}
+ @Test
+ public void selectByUuid_withScmAccount_retrievesScmAccounts() {
+ List<String> scmAccountsUser1 = List.of("account1_1", "account1_2");
+ UserDto user1 = db.users().insertUser(u -> u.setScmAccounts(scmAccountsUser1));
+ UserDto user2 = db.users().insertUser(u -> u.setScmAccounts(List.of("account2_1", "account2_2")));
+
+ UserDto userDto = underTest.selectByUuid(session, user1.getUuid());
+ assertThat(userDto).isNotNull();
+ assertThat(userDto.getSortedScmAccounts()).containsExactlyElementsOf(scmAccountsUser1);
+ }
+
@Test
public void selectUserByLogin_ignore_inactive() {
db.users().insertUser(user -> user.setLogin("user1"));
assertThat(user.isResetPassword()).isFalse();
assertThat(user.isLocal()).isTrue();
- assertThat(user.getScmAccountsAsList()).isEmpty();
- assertThat(user.getScmAccounts()).isNull();
+ assertThat(user.getSortedScmAccounts()).isEmpty();
assertThat(user.getHashMethod()).isNull();
assertThat(user.getLastConnectionDate()).isNull();
assertThat(user.getHomepageType()).isNull();
.setLogin("john")
.setName("John")
.setEmail("jo@hn.com")
- .setScmAccounts(",jo.hn,john2,")
+ .setScmAccounts(List.of("jo.hn", "john2", ""))
.setActive(true)
.setResetPassword(true)
.setSalt("1234")
assertThat(user.getEmail()).isEqualTo("jo@hn.com");
assertThat(user.isActive()).isTrue();
assertThat(user.isResetPassword()).isTrue();
- assertThat(user.getScmAccounts()).isEqualTo(",jo.hn,john2,");
+ assertThat(user.getSortedScmAccounts()).containsExactly("jo.hn", "john2");
assertThat(user.getSalt()).isEqualTo("1234");
assertThat(user.getCryptedPassword()).isEqualTo("abcd");
assertThat(user.getHashMethod()).isEqualTo("SHA1");
.setLogin("johnDoo")
.setName("John Doo")
.setEmail("jodoo@hn.com")
- .setScmAccounts(",jo.hn,john2,johndoo,")
+ .setScmAccounts(List.of("jo.hn", "john2", "johndoo", ""))
.setActive(false)
.setResetPassword(true)
.setSalt("12345")
assertThat(reloaded.getEmail()).isEqualTo("jodoo@hn.com");
assertThat(reloaded.isActive()).isFalse();
assertThat(reloaded.isResetPassword()).isTrue();
- assertThat(reloaded.getScmAccounts()).isEqualTo(",jo.hn,john2,johndoo,");
+ assertThat(reloaded.getSortedScmAccounts()).containsExactly("jo.hn", "john2", "johndoo");
assertThat(reloaded.getSalt()).isEqualTo("12345");
assertThat(reloaded.getCryptedPassword()).isEqualTo("abcde");
assertThat(reloaded.getHashMethod()).isEqualTo("BCRYPT");
assertThat(reloaded.getLastConnectionDate()).isEqualTo(10_000_000_000L);
}
+ @Test
+ public void update_scmAccounts() {
+ UserDto user = db.users().insertUser(u -> u.setScmAccounts(emptyList()));
+
+ underTest.update(db.getSession(), user.setScmAccounts(List.of("jo.hn", "john2", "johndoo", "")));
+ UserDto reloaded = Objects.requireNonNull(underTest.selectByUuid(db.getSession(), user.getUuid()));
+ assertThat(reloaded.getSortedScmAccounts()).containsExactly("jo.hn", "john2", "johndoo");
+
+ underTest.update(db.getSession(), user.setScmAccounts(List.of("jo.hn", "john2")));
+ reloaded = Objects.requireNonNull(underTest.selectByUuid(db.getSession(), user.getUuid()));
+ assertThat(reloaded.getSortedScmAccounts()).containsExactly("jo.hn", "john2");
+
+ underTest.update(db.getSession(), user.setScmAccounts(List.of("jo.hn", "john3", "john2")));
+ reloaded = Objects.requireNonNull(underTest.selectByUuid(db.getSession(), user.getUuid()));
+ assertThat(reloaded.getSortedScmAccounts()).containsExactly("jo.hn", "john2", "john3");
+ }
+
@Test
public void deactivate_user() {
UserDto user = insertActiveUser();
assertThat(userReloaded.getExternalLogin()).isEqualTo(user.getExternalLogin());
assertThat(userReloaded.getExternalIdentityProvider()).isEqualTo(user.getExternalIdentityProvider());
assertThat(userReloaded.getEmail()).isNull();
- assertThat(userReloaded.getScmAccounts()).isNull();
+ assertThat(userReloaded.getSortedScmAccounts()).isEmpty();
assertThat(userReloaded.getSalt()).isNull();
assertThat(userReloaded.getCryptedPassword()).isNull();
assertThat(userReloaded.getUpdatedAt()).isEqualTo(NOW);
.setName("Marius")
.setEmail("marius@lesbronzes.fr")
.setActive(true)
- .setScmAccounts("\nma\nmarius33\n")
+ .setScmAccounts(List.of("ma", "marius33"))
.setSalt("79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365")
.setCryptedPassword("650d2261c98361e2f67f90ce5c65a95e7d8ea2fg")
.setHomepageType("project")
assertThat(dto.getName()).isEqualTo("Marius");
assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
assertThat(dto.isActive()).isTrue();
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
+ assertThat(dto.getSortedScmAccounts()).containsExactly("ma", "marius33");
assertThat(dto.getSalt()).isEqualTo("79bd6a8e79fb8c76ac8b121cc7e8e11ad1af8365");
assertThat(dto.getCryptedPassword()).isEqualTo("650d2261c98361e2f67f90ce5c65a95e7d8ea2fg");
assertThat(dto.getCreatedAt()).isEqualTo(user1.getCreatedAt());
@Test
public void select_nullable_by_scm_account() {
db.users().insertUser(user -> user.setLogin("marius").setName("Marius").setEmail("marius@lesbronzes.fr").setScmAccounts(asList("ma", "marius33")));
- db.users().insertUser(user -> user.setLogin("sbrandhof").setName("Simon Brandhof").setEmail("sbrandhof@lesbronzes.fr").setScmAccounts((String) null));
+ db.users().insertUser(user -> user.setLogin("sbrandhof").setName("Simon Brandhof").setEmail("sbrandhof@lesbronzes.fr").setScmAccounts(emptyList()));
+
+ List<UserDto> searchByMa = underTest.selectByScmAccountOrLoginOrEmail(session, "ma");
+ assertThat(searchByMa).extracting(UserDto::getLogin).containsExactly("marius");
+ assertThat(searchByMa.iterator().next().getSortedScmAccounts()).containsExactly("ma", "marius33");
- assertThat(underTest.selectByScmAccountOrLoginOrEmail(session, "ma")).extracting(UserDto::getLogin).containsExactly("marius");
assertThat(underTest.selectByScmAccountOrLoginOrEmail(session, "marius")).extracting(UserDto::getLogin).containsExactly("marius");
assertThat(underTest.selectByScmAccountOrLoginOrEmail(session, "marius@lesbronzes.fr")).extracting(UserDto::getLogin).containsExactly("marius");
assertThat(underTest.selectByScmAccountOrLoginOrEmail(session, "m")).isEmpty();
@Test
public void select_nullable_by_scm_account_return_many_results_when_same_email_is_used_by_many_users() {
db.users().insertUser(user -> user.setLogin("marius").setName("Marius").setEmail("marius@lesbronzes.fr").setScmAccounts(asList("ma", "marius33")));
- db.users().insertUser(user -> user.setLogin("sbrandhof").setName("Simon Brandhof").setEmail("marius@lesbronzes.fr").setScmAccounts((String) null));
+ db.users().insertUser(user -> user.setLogin("sbrandhof").setName("Simon Brandhof").setEmail("marius@lesbronzes.fr").setScmAccounts(emptyList()));
List<UserDto> results = underTest.selectByScmAccountOrLoginOrEmail(session, "marius@lesbronzes.fr");
List<UserTelemetryDto> result = underTest.selectUsersForTelemetry(db.getSession());
assertThat(result)
- .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::isActive, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate, UserTelemetryDto::getScimUuid)
+ .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::isActive, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate,
+ UserTelemetryDto::getScimUuid)
.containsExactlyInAnyOrder(
tuple(u1.getUuid(), u1.isActive(), u1.getLastConnectionDate(), u1.getLastSonarlintConnectionDate(), null),
tuple(u2.getUuid(), u2.isActive(), u2.getLastConnectionDate(), u2.getLastSonarlintConnectionDate(), null)
List<UserTelemetryDto> result = underTest.selectUsersForTelemetry(db.getSession());
assertThat(result)
- .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::isActive, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate, UserTelemetryDto::getScimUuid)
+ .extracting(UserTelemetryDto::getUuid, UserTelemetryDto::isActive, UserTelemetryDto::getLastConnectionDate, UserTelemetryDto::getLastSonarlintConnectionDate,
+ UserTelemetryDto::getScimUuid)
.containsExactlyInAnyOrder(
tuple(u1.getUuid(), u1.isActive(), u1.getLastConnectionDate(), u1.getLastSonarlintConnectionDate(), scimUser1.getScimUserUuid()),
tuple(u2.getUuid(), u2.isActive(), u2.getLastConnectionDate(), u2.getLastSonarlintConnectionDate(), null)
return dto;
}
-
private ScimUserDto enableScimForUser(UserDto userDto) {
return dbClient.scimUserDao().enableScimForUser(db.getSession(), userDto.getUuid());
}
package org.sonar.db.user;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
.setLogin("johnDoo")
.setName("John Doo")
.setEmail("jodoo@hn.com")
- .setScmAccounts(",jo.hn,john2,johndoo,")
+ .setScmAccounts(List.of("jo.hn","john2","johndoo"))
.setActive(false)
.setResetPassword(true)
.setSalt("12345")
UserNewValue::getScmAccounts, UserNewValue::getExternalId, UserNewValue::getExternalLogin, UserNewValue::getExternalIdentityProvider,
UserNewValue::isLocal, UserNewValue::getLastConnectionDate)
.containsExactly(updatedUser.getUuid(), updatedUser.getLogin(), updatedUser.getName(), updatedUser.getEmail(), updatedUser.isActive(),
- updatedUser.getScmAccounts(), updatedUser.getExternalId(), updatedUser.getExternalLogin(), updatedUser.getExternalIdentityProvider(),
+ updatedUser.getSortedScmAccounts(), updatedUser.getExternalId(), updatedUser.getExternalLogin(), updatedUser.getExternalIdentityProvider(),
updatedUser.isLocal(), updatedUser.getLastConnectionDate());
assertThat(newValue.toString())
.contains("name")
*/
package org.sonar.db.audit.model;
+import java.util.ArrayList;
+import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.ObjectUtils;
@Nullable
private Boolean isActive;
- @Nullable
- private String scmAccounts;
+ private List<String> scmAccounts = new ArrayList<>();
@Nullable
private String externalId;
this.name = userDto.getName();
this.email = userDto.getEmail();
this.isActive = userDto.isActive();
- this.scmAccounts = userDto.getScmAccounts();
+ this.scmAccounts = userDto.getSortedScmAccounts();
this.externalId = userDto.getExternalId();
this.externalLogin = userDto.getExternalLogin();
this.externalIdentityProvider = userDto.getExternalIdentityProvider();
return this.isActive;
}
- @CheckForNull
- public String getScmAccounts() {
+ public List<String> getScmAccounts() {
return this.scmAccounts;
}
addField(sb, "\"name\": ", this.name, true);
addField(sb, "\"email\": ", this.email, true);
addField(sb, "\"isActive\": ", ObjectUtils.toString(this.isActive), false);
- addField(sb, "\"scmAccounts\": ", this.scmAccounts, true);
+ addField(sb, "\"scmAccounts\": ", String.join(",", scmAccounts), true);
addField(sb, "\"externalId\": ", this.externalId, true);
addField(sb, "\"externalLogin\": ", this.externalLogin, true);
addField(sb, "\"externalIdentityProvider\": ", this.externalIdentityProvider, true);
import java.util.function.Function;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.Dao;
import static java.util.concurrent.TimeUnit.DAYS;
import static org.sonar.db.DatabaseUtils.executeLargeInputs;
import static org.sonar.db.DatabaseUtils.executeLargeInputsWithoutOutput;
-import static org.sonar.db.user.UserDto.SCM_ACCOUNTS_SEPARATOR;
public class UserDao implements Dao {
private static final long WEEK_IN_MS = DAYS.toMillis(7L);
/**
* Select users by uuids, including disabled users. An empty list is returned
* if list of uuids is empty, without any db round trips.
+ *
* @return
*/
public List<UserDto> selectByUuids(DbSession session, Collection<String> uuids) {
public UserDto insert(DbSession session, UserDto dto) {
long now = system2.now();
mapper(session).insert(dto.setUuid(uuidFactory.create()).setCreatedAt(now).setUpdatedAt(now));
+ insertScmAccounts(session, dto.getUuid(), dto.getSortedScmAccounts());
auditPersister.addUser(session, new UserNewValue(dto.getUuid(), dto.getLogin()));
return dto;
}
+ private static void insertScmAccounts(DbSession session, String userUuid, List<String> scmAccounts) {
+ scmAccounts.stream()
+ .filter(StringUtils::isNotBlank)
+ .forEach(scmAccount -> mapper(session).insertScmAccount(userUuid, scmAccount));
+ }
+
public UserDto update(DbSession session, UserDto dto) {
return update(session, dto, true);
}
public UserDto update(DbSession session, UserDto dto, boolean track) {
mapper(session).update(dto.setUpdatedAt(system2.now()));
+ mapper(session).deleteAllScmAccounts(dto.getUuid());
+ insertScmAccounts(session, dto.getUuid(), dto.getSortedScmAccounts());
if (track) {
auditPersister.updateUser(session, new UserNewValue(dto));
}
public void deactivateUser(DbSession dbSession, UserDto user) {
mapper(dbSession).deactivateUser(user.getLogin(), system2.now());
+ mapper(dbSession).deleteAllScmAccounts(user.getUuid());
auditPersister.deactivateUser(dbSession, new UserNewValue(user.getUuid(), user.getLogin()));
}
}
public List<UserDto> selectByScmAccountOrLoginOrEmail(DbSession session, String scmAccountOrLoginOrEmail) {
- String like = new StringBuilder().append("%")
- .append(SCM_ACCOUNTS_SEPARATOR).append(scmAccountOrLoginOrEmail)
- .append(SCM_ACCOUNTS_SEPARATOR).append("%").toString();
- return mapper(session).selectNullableByScmAccountOrLoginOrEmail(scmAccountOrLoginOrEmail, like);
+ return mapper(session).selectNullableByScmAccountOrLoginOrEmail(scmAccountOrLoginOrEmail);
}
/**
* Search for an active user with the given emailCaseInsensitive exits in database
- *
* Select is case insensitive. Result for searching 'mail@emailCaseInsensitive.com' or 'Mail@Email.com' is the same
*/
public List<UserDto> selectByEmail(DbSession dbSession, String emailCaseInsensitive) {
*/
package org.sonar.db.user;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.core.user.DefaultUser;
+import static java.lang.String.CASE_INSENSITIVE_ORDER;
+import static java.util.Comparator.comparing;
+
/**
* @since 3.2
*/
private String name;
private String email;
private boolean active = true;
- private String scmAccounts;
private String externalId;
private String externalLogin;
private String externalIdentityProvider;
private String homepageParameter;
private boolean local = true;
private boolean resetPassword = false;
+ private List<String> scmAccounts = new ArrayList<>();
/**
* Date of the last time the user has accessed to the server.
return this;
}
- @CheckForNull
- public String getScmAccounts() {
+ /**
+ * Used by mybatis
+ */
+ private List<String> getScmAccounts() {
return scmAccounts;
}
- public List<String> getScmAccountsAsList() {
- return decodeScmAccounts(scmAccounts);
- }
-
- public UserDto setScmAccounts(@Nullable String s) {
- this.scmAccounts = s;
- return this;
+ public List<String> getSortedScmAccounts() {
+ // needs to be done when reading, as mybatis do not use the setter
+ return scmAccounts.stream().sorted(comparing(s -> s, CASE_INSENSITIVE_ORDER)).toList();
}
- public UserDto setScmAccounts(@Nullable List<String> list) {
- this.scmAccounts = encodeScmAccounts(list);
+ public UserDto setScmAccounts(List<String> scmAccounts) {
+ this.scmAccounts = scmAccounts;
return this;
}
- @CheckForNull
- public static String encodeScmAccounts(@Nullable List<String> scmAccounts) {
- if (scmAccounts != null && !scmAccounts.isEmpty()) {
- return String.format("%s%s%s", SCM_ACCOUNTS_SEPARATOR, String.join(String.valueOf(SCM_ACCOUNTS_SEPARATOR), scmAccounts), SCM_ACCOUNTS_SEPARATOR);
- }
- return null;
- }
-
- public static List<String> decodeScmAccounts(@Nullable String dbValue) {
- if (dbValue == null) {
- return new ArrayList<>();
- } else {
- return Lists.newArrayList(Splitter.on(SCM_ACCOUNTS_SEPARATOR).omitEmptyStrings().split(dbValue));
- }
- }
-
public String getExternalId() {
return externalId;
}
* Can return multiple results if an email is used by many users (For instance, technical account can use the same email as a none technical account)
*/
@CheckForNull
- List<UserDto> selectNullableByScmAccountOrLoginOrEmail(@Param("scmAccount") String scmAccountOrLoginOrEmail, @Param("likeScmAccount") String likeScmAccount);
+ List<UserDto> selectNullableByScmAccountOrLoginOrEmail(@Param("scmAccount") String scmAccountOrLoginOrEmail);
/**
* Select user by login. Note that disabled users are ignored.
long countActiveSonarlintUsers(@Param("sinceDate") long sinceDate);
long countActiveUsers();
+
+ void insertScmAccount(@Param("userUuid") String userUuid, @Param("scmAccount") String scmAccount);
+
+ void deleteAllScmAccounts(@Param("userUuid") String userUuid);
}
u.name as name,
u.email as email,
u.active as "active",
- u.scm_accounts as "scmAccounts",
u.salt as "salt",
u.crypted_password as "cryptedPassword",
u.hash_method as "hashMethod",
u.updated_at as "updatedAt"
</sql>
- <select id="selectByUuid" parameterType="String" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <sql id="usersAndScmAccountsColumns">
+ sa.scm_account as "scm_account",
+ <include refid="userColumns"/>
+ </sql>
+
+
+ <sql id="leftOuterJoinScmAccounts">
+ left outer join scm_accounts sa on
+ sa.user_uuid = u.uuid
+ </sql>
+
+ <sql id="selectFromUsersAndJoinScmAccounts">
+ SELECT
+ <include refid="usersAndScmAccountsColumns"/>
+ FROM users u
+ <include refid="leftOuterJoinScmAccounts"/>
+ </sql>
+
+ <resultMap id="userResultMap" type="org.sonar.db.user.UserDto" autoMapping="true">
+ <id property="uuid" column="uuid"/>
+ <collection property="scmAccounts" javaType="list" ofType="java.lang.String">
+ <result column="scm_account"/>
+ </collection>
+ </resultMap>
+
+ <select id="selectByUuid" parameterType="String" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.uuid=#{uuid, jdbcType=VARCHAR}
</select>
- <select id="selectByLogin" parameterType="String" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectByLogin" parameterType="String" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.login=#{login, jdbcType=VARCHAR}
</select>
- <select id="selectNullableByScmAccountOrLoginOrEmail" parameterType="map" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
- WHERE
- u.login=#{scmAccount, jdbcType=VARCHAR}
- OR u.email=#{scmAccount, jdbcType=VARCHAR}
- OR u.scm_accounts like #{likeScmAccount, jdbcType=VARCHAR}
+ <select id="selectNullableByScmAccountOrLoginOrEmail" parameterType="map" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
+ WHERE uuid IN (
+ SELECT
+ u.uuid
+ FROM users u
+ <include refid="leftOuterJoinScmAccounts"/>
+ WHERE
+ u.login=#{scmAccount, jdbcType=VARCHAR}
+ OR u.email=#{scmAccount, jdbcType=VARCHAR}
+ OR sa.scm_account=#{scmAccount, jdbcType=VARCHAR}
+ )
</select>
- <select id="selectUserByLogin" parameterType="string" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectUserByLogin" parameterType="string" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.login=#{id, jdbcType=INTEGER} AND u.active=${_true}
</select>
- <select id="selectByLogins" parameterType="string" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectByLogins" parameterType="string" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.login in
<foreach collection="list" open="(" close=")" item="login" separator=",">
#{login, jdbcType=VARCHAR}
</foreach>
</select>
- <select id="selectByUuids" parameterType="string" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectByUuids" parameterType="string" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.uuid in
<foreach collection="list" open="(" close=")" item="uuid" separator=",">
#{uuid, jdbcType=VARCHAR}
</foreach>
</select>
- <select id="scrollAll" resultType="User" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
- select
- <include refid="userColumns"/>
- from users u
+ <select id="scrollAll" resultMap="userResultMap" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY" resultOrdered="true">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
+ ORDER BY u.uuid, sa.scm_account
</select>
- <select id="selectUsers" parameterType="map" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectUsers" parameterType="map" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
<include refid="searchByQueryWhereClause"/>
ORDER BY u.login
limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
</select>
- <select id="selectUsers" parameterType="map" resultType="User" databaseId="mssql">
+ <select id="selectUsers" parameterType="map" resultMap="userResultMap" databaseId="mssql">
SELECT
- <include refid="userColumns"/>
+ <include refid="usersAndScmAccountsColumns"/>
FROM
(SELECT
<include refid="searchByQueryInnerQueryColumns"/>
offset #{pagination.offset} rows
fetch next #{pagination.pageSize,jdbcType=INTEGER} rows only
) u
+ <include refid="leftOuterJoinScmAccounts"/>
</select>
- <select id="selectUsers" parameterType="map" resultType="User" databaseId="oracle">
+ <select id="selectUsers" parameterType="map" resultMap="userResultMap" databaseId="oracle">
SELECT
- <include refid="userColumns"/>
+ <include refid="usersAndScmAccountsColumns"/>
FROM
(SELECT rownum as rn, t.* from (
SELECT
ORDER BY u.login ASC
) t
) u
+ <include refid="leftOuterJoinScmAccounts"/>
WHERE
u.rn BETWEEN #{pagination.startRowNumber,jdbcType=INTEGER} and #{pagination.endRowNumber,jdbcType=INTEGER}
ORDER BY u.rn ASC
ORDER BY u.uuid
</select>
- <select id="selectByEmail" parameterType="String" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectByEmail" parameterType="String" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE lower(u.email)=#{email, jdbcType=VARCHAR}
AND u.active=${_true}
</select>
SELECT distinct(external_identity_provider) from users
</select>
- <select id="selectByExternalIdAndIdentityProvider" parameterType="map" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectByExternalIdAndIdentityProvider" parameterType="map" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.external_id=#{externalId, jdbcType=VARCHAR} AND u.external_identity_provider=#{externalIdentityProvider, jdbcType=VARCHAR}
</select>
- <select id="selectByExternalIdsAndIdentityProvider" parameterType="map" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectByExternalIdsAndIdentityProvider" parameterType="map" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.external_identity_provider=#{externalIdentityProvider, jdbcType=VARCHAR}
AND u.external_id in
<foreach collection="externalIds" open="(" close=")" item="externalId" separator=",">
</foreach>
</select>
- <select id="selectByExternalLoginAndIdentityProvider" parameterType="map" resultType="User">
- SELECT
- <include refid="userColumns"/>
- FROM users u
+ <select id="selectByExternalLoginAndIdentityProvider" parameterType="map" resultMap="userResultMap">
+ <include refid="selectFromUsersAndJoinScmAccounts"/>
WHERE u.external_login=#{externalLogin, jdbcType=VARCHAR} AND u.external_identity_provider=#{externalIdentityProvider, jdbcType=VARCHAR}
</select>
name,
email,
active,
- scm_accounts,
external_id,
external_login,
external_identity_provider,
#{user.name,jdbcType=VARCHAR},
#{user.email,jdbcType=VARCHAR},
#{user.active,jdbcType=BOOLEAN},
- #{user.scmAccounts,jdbcType=VARCHAR},
#{user.externalId,jdbcType=VARCHAR},
#{user.externalLogin,jdbcType=VARCHAR},
#{user.externalIdentityProvider,jdbcType=VARCHAR},
name = #{user.name, jdbcType=VARCHAR},
email = #{user.email, jdbcType=VARCHAR},
active = #{user.active, jdbcType=BOOLEAN},
- scm_accounts = #{user.scmAccounts, jdbcType=VARCHAR},
external_id = #{user.externalId, jdbcType=VARCHAR},
external_login = #{user.externalLogin, jdbcType=VARCHAR},
external_identity_provider = #{user.externalIdentityProvider, jdbcType=VARCHAR},
select count(1) from users u WHERE u.active=${_true}
</select>
+ <insert id="insertScmAccount" parameterType="map" useGeneratedKeys="false">
+ insert into scm_accounts (
+ user_uuid,
+ scm_account
+ ) values (
+ #{userUuid,jdbcType=VARCHAR},
+ #{scmAccount,jdbcType=VARCHAR}
+ )
+ </insert>
+
+ <delete id="deleteAllScmAccounts" parameterType="map">
+ delete from scm_accounts
+ where
+ user_uuid = #{userUuid,jdbcType=VARCHAR}
+ </delete>
+
</mapper>
CREATE TABLE "SCM_ACCOUNTS"(
"USER_UUID" CHARACTER VARYING(255) NOT NULL,
- "SCM_ACCOUNT" CHARACTER VARYING(100) NOT NULL
+ "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
);
ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
*/
package org.sonar.db.audit.model;
+import java.util.List;
import org.json.simple.parser.JSONParser;
import org.junit.Test;
import org.sonar.db.user.UserDto;
+import static java.util.Collections.emptyList;
import static org.junit.Assert.fail;
public class UserNewValueTest {
@Test
public void toString_givenAllFieldsWithValue_returnValidJSON() {
- UserDto userDto = new UserDto();
- userDto.setName("name");
- userDto.setEmail("name@email.com");
- userDto.setActive(true);
- userDto.setScmAccounts("\ngithub-account\n");
- userDto.setExternalId("name");
- userDto.setExternalLogin("name");
- userDto.setExternalIdentityProvider("github");
- userDto.setLocal(false);
- userDto.setLastConnectionDate(System.currentTimeMillis());
+ UserDto userDto = createUserDto();
+ UserNewValue userNewValue = new UserNewValue(userDto);
+
+ String jsonString = userNewValue.toString();
+
+ assertValidJSON(jsonString);
+ }
+
+ @Test
+ public void toString_givenEmptyScmAccount_returnValidJSON() {
+ UserDto userDto = createUserDto();
+ userDto.setScmAccounts(emptyList());
UserNewValue userNewValue = new UserNewValue(userDto);
String jsonString = userNewValue.toString();
assertValidJSON(jsonString);
}
-
+
+ private static UserDto createUserDto() {
+ UserDto userDto = new UserDto();
+ userDto.setName("name");
+ userDto.setEmail("name@email.com");
+ userDto.setActive(true);
+ userDto.setScmAccounts(List.of("github-account", "gitlab-account"));
+ userDto.setExternalId("name");
+ userDto.setExternalLogin("name");
+ userDto.setExternalIdentityProvider("github");
+ userDto.setLocal(false);
+ userDto.setLastConnectionDate(System.currentTimeMillis());
+ return userDto;
+ }
+
private void assertValidJSON(String jsonString) {
try {
jsonParser.parse(jsonString);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.db.user;
-
-import java.util.Arrays;
-import java.util.Collections;
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class UserDtoTest {
-
-
- @Test
- public void encode_scm_accounts() {
- assertThat(UserDto.encodeScmAccounts(null)).isNull();
- assertThat(UserDto.encodeScmAccounts(Collections.emptyList())).isNull();
- assertThat(UserDto.encodeScmAccounts(Arrays.asList("foo"))).isEqualTo("\nfoo\n");
- assertThat(UserDto.encodeScmAccounts(Arrays.asList("foo", "bar"))).isEqualTo("\nfoo\nbar\n");
- }
-
- @Test
- public void decode_scm_accounts() {
- assertThat(UserDto.decodeScmAccounts(null)).isEmpty();
- assertThat(UserDto.decodeScmAccounts("\nfoo\n")).containsOnly("foo");
- assertThat(UserDto.decodeScmAccounts("\nfoo\nbar\n")).containsOnly("foo", "bar");
- }
-}
import javax.annotation.Nullable;
+import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang.math.RandomUtils.nextBoolean;
return newUserDto()
.setActive(false)
// All these fields are reset when disabling a user
- .setScmAccounts((String) null)
+ .setScmAccounts(emptyList())
.setEmail(null)
.setCryptedPassword(null)
.setSalt(null);
static final String SCM_ACCOUNT_COLUMN_NAME = "scm_account";
@VisibleForTesting
- static final int SCM_ACCOUNT_SIZE = 100;
+ static final int SCM_ACCOUNT_SIZE = 255;
public CreateScmAccountsTable(Database db) {
super(db, TABLE_NAME);
CREATE TABLE "SCM_ACCOUNTS"(
"USER_UUID" CHARACTER VARYING(255) NOT NULL,
- "SCM_ACCOUNT" CHARACTER VARYING(100) NOT NULL
+ "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
);
ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
CREATE TABLE "SCM_ACCOUNTS"(
"USER_UUID" CHARACTER VARYING(255) NOT NULL,
- "SCM_ACCOUNT" CHARACTER VARYING(100) NOT NULL
+ "SCM_ACCOUNT" CHARACTER VARYING(255) NOT NULL
);
ALTER TABLE "SCM_ACCOUNTS" ADD CONSTRAINT "PK_SCM_ACCOUNTS" PRIMARY KEY("USER_UUID", "SCM_ACCOUNT");
assertThat(doc.name()).isEqualTo(user.getName());
assertThat(doc.email()).isEqualTo(user.getEmail());
assertThat(doc.active()).isEqualTo(user.isActive());
- assertThat(doc.scmAccounts()).isEqualTo(user.getScmAccountsAsList());
+ assertThat(doc.scmAccounts()).isEqualTo(user.getSortedScmAccounts());
}
@Test
assertThat(doc.name()).isEqualTo(user.getName());
assertThat(doc.email()).isEqualTo(user.getEmail());
assertThat(doc.active()).isEqualTo(user.isActive());
- assertThat(doc.scmAccounts()).isEqualTo(user.getScmAccountsAsList());
+ assertThat(doc.scmAccounts()).isEqualTo(user.getSortedScmAccounts());
}
@Test
doc.setName(user.getName());
doc.setEmail(user.getEmail());
doc.setActive(user.isActive());
- doc.setScmAccounts(UserDto.decodeScmAccounts(user.getScmAccounts()));
+ doc.setScmAccounts(user.getSortedScmAccounts());
return doc.toIndexRequest();
}
+
}
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import static com.google.common.collect.Lists.newArrayList;
import static java.lang.String.format;
import static java.util.Arrays.stream;
+import static java.util.Collections.emptyList;
import static java.util.stream.Stream.concat;
import static org.sonar.api.CoreProperties.DEFAULT_ISSUE_ASSIGNEE;
import static org.sonar.core.util.Slug.slugify;
private boolean updateScmAccounts(DbSession dbSession, UpdateUser updateUser, UserDto userDto, List<String> messages) {
String email = updateUser.email();
List<String> scmAccounts = sanitizeScmAccounts(updateUser.scmAccounts());
- List<String> existingScmAccounts = userDto.getScmAccountsAsList();
+ List<String> existingScmAccounts = userDto.getSortedScmAccounts();
if (updateUser.isScmAccountsChanged() && !(existingScmAccounts.containsAll(scmAccounts) && scmAccounts.containsAll(existingScmAccounts))) {
if (!scmAccounts.isEmpty()) {
String newOrOldEmail = email != null ? email : userDto.getEmail();
userDto.setScmAccounts(scmAccounts);
}
} else {
- userDto.setScmAccounts((String) null);
+ userDto.setScmAccounts(emptyList());
}
return true;
}
.sorted(String::compareToIgnoreCase)
.collect(toList(scmAccounts.size()));
}
- return Collections.emptyList();
+ return emptyList();
}
private void checkLoginUniqueness(DbSession dbSession, String login) {
assertThat(dto.getLogin()).isEqualTo("user");
assertThat(dto.getName()).isEqualTo("User");
assertThat(dto.getEmail()).isEqualTo("user@mail.com");
- assertThat(dto.getScmAccountsAsList()).containsOnly("u1", "u_1", "User 1");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("u1", "u_1", "User 1");
assertThat(dto.isActive()).isTrue();
assertThat(dto.isLocal()).isTrue();
assertThat(dto.getLogin()).isEqualTo("us");
assertThat(dto.getName()).isEqualTo("User");
assertThat(dto.getEmail()).isNull();
- assertThat(dto.getScmAccounts()).isNull();
+ assertThat(dto.getSortedScmAccounts()).isEmpty();
assertThat(dto.isActive()).isTrue();
}
.build(), u -> {
});
- assertThat(dbClient.userDao().selectByLogin(session, "user").getScmAccountsAsList()).containsOnly("u1");
+ assertThat(dbClient.userDao().selectByLogin(session, "user").getSortedScmAccounts()).containsOnly("u1");
}
@Test
.build(), u -> {
});
- assertThat(dbClient.userDao().selectByLogin(session, "user").getScmAccounts()).isNull();
+ assertThat(dbClient.userDao().selectByLogin(session, "user").getSortedScmAccounts()).isEmpty();
}
@Test
.build(), u -> {
});
- assertThat(dbClient.userDao().selectByLogin(session, "user").getScmAccountsAsList()).containsOnly("u1");
+ assertThat(dbClient.userDao().selectByLogin(session, "user").getSortedScmAccounts()).containsOnly("u1");
}
@Test
assertThat(reloaded.getLogin()).isEqualTo("marius");
assertThat(reloaded.getName()).isEqualTo("Marius2");
assertThat(reloaded.getEmail()).isEqualTo("marius2@mail.com");
- assertThat(reloaded.getScmAccounts()).isNull();
+ assertThat(reloaded.getSortedScmAccounts()).isEmpty();
assertThat(reloaded.isLocal()).isTrue();
assertThat(reloaded.getSalt()).isNotNull();
assertThat(reloaded.getHashMethod()).isEqualTo(HashMethod.PBKDF2.name());
assertThat(dto.isActive()).isTrue();
assertThat(dto.getName()).isEqualTo(user.getName());
- assertThat(dto.getScmAccounts()).isNull();
+ assertThat(dto.getSortedScmAccounts()).isEmpty();
assertThat(dto.getSalt()).isNull();
assertThat(dto.getCryptedPassword()).isNull();
assertThat(dto.getCreatedAt()).isEqualTo(user.getCreatedAt());
assertThat(updatedUser.isActive()).isTrue();
assertThat(updatedUser.getName()).isEqualTo("Marius2");
assertThat(updatedUser.getEmail()).isEqualTo("marius2@mail.com");
- assertThat(updatedUser.getScmAccountsAsList()).containsOnly("ma2");
+ assertThat(updatedUser.getSortedScmAccounts()).containsOnly("ma2");
assertThat(updatedUser.getCreatedAt()).isEqualTo(user.getCreatedAt());
assertThat(updatedUser.getUpdatedAt()).isGreaterThan(user.getCreatedAt());
});
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("ma2");
verify(auditPersister, times(1)).updateUserPassword(any(), any());
}
assertThat(userReloaded.isLocal()).isTrue();
assertThat(userReloaded.getName()).isEqualTo(user.getName());
assertThat(userReloaded.getEmail()).isEqualTo(user.getEmail());
- assertThat(userReloaded.getScmAccountsAsList()).containsAll(user.getScmAccountsAsList());
+ assertThat(userReloaded.getSortedScmAccounts()).containsAll(user.getSortedScmAccounts());
assertThat(userReloaded.getSalt()).isEqualTo(user.getSalt());
assertThat(userReloaded.getCryptedPassword()).isEqualTo(user.getCryptedPassword());
}
assertThat(userReloaded.getExternalId()).isEqualTo(user.getExternalId());
assertThat(userReloaded.getName()).isEqualTo(user.getName());
assertThat(userReloaded.getEmail()).isEqualTo(user.getEmail());
- assertThat(userReloaded.getScmAccountsAsList()).containsAll(user.getScmAccountsAsList());
+ assertThat(userReloaded.getSortedScmAccounts()).containsAll(user.getSortedScmAccounts());
assertThat(userReloaded.getSalt()).isEqualTo(user.getSalt());
assertThat(userReloaded.getCryptedPassword()).isEqualTo(user.getCryptedPassword());
}
// Following fields has not changed
assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("ma", "marius33");
assertThat(dto.getSalt()).isEqualTo("salt");
assertThat(dto.getCryptedPassword()).isEqualTo("crypted password");
}
// Following fields has not changed
assertThat(dto.getName()).isEqualTo("Marius");
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("ma", "marius33");
assertThat(dto.getSalt()).isEqualTo("salt");
assertThat(dto.getCryptedPassword()).isEqualTo("crypted password");
}
});
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma2");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("ma2");
// Following fields has not changed
assertThat(dto.getName()).isEqualTo("Marius");
});
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("ma", "marius33");
}
@Test
});
UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
- assertThat(dto.getScmAccounts()).isNull();
+ assertThat(dto.getSortedScmAccounts()).isEmpty();
}
@Test
// Following fields has not changed
assertThat(dto.getName()).isEqualTo("Marius");
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("ma", "marius33");
assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
}
// Following fields has not changed
assertThat(dto.getName()).isEqualTo("Marius");
- assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
+ assertThat(dto.getSortedScmAccounts()).containsOnly("ma", "marius33");
assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
}
underTest.updateAndCommit(session, user, new UpdateUser()
.setName(user.getName())
.setEmail(user.getEmail())
- .setScmAccounts(user.getScmAccountsAsList())
+ .setScmAccounts(user.getSortedScmAccounts())
.setExternalIdentity(new ExternalIdentity(user.getExternalIdentityProvider(), user.getExternalLogin(), user.getExternalId())), u -> {
});
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
+import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
.setName("Ada Lovelace")
.setActive(false)
.setEmail(null)
- .setScmAccounts((String) null)
+ .setScmAccounts(emptyList())
.setExternalIdentityProvider("provider")
.setExternalLogin("external.login")
.setExternalId("external.id"));
import org.sonarqube.ws.Users.CurrentWsResponse;
import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
CurrentWsResponse::getLocal,
CurrentWsResponse::getExternalIdentity, CurrentWsResponse::getExternalProvider, CurrentWsResponse::getScmAccountsList)
.containsExactly(true, "obiwan.kenobi", "Obiwan Kenobi", "obiwan.kenobi@starwars.com", "f5aa64437a1821ffe8b563099d506aef", true, "obiwan", "sonarqube",
- newArrayList("obiwan:github", "obiwan:bitbucket"));
+ newArrayList("obiwan:bitbucket", "obiwan:github"));
}
@Test
.setLocal(true)
.setExternalLogin("obiwan")
.setExternalIdentityProvider("sonarqube")
- .setScmAccounts((String) null));
+ .setScmAccounts(emptyList()));
userSession.logIn(user);
CurrentWsResponse response = call();
assertThat(user).isPresent();
assertThat(user.get().isActive()).isFalse();
assertThat(user.get().getEmail()).isNull();
- assertThat(user.get().getScmAccountsAsList()).isEmpty();
+ assertThat(user.get().getSortedScmAccounts()).isEmpty();
}
private void verifyThatUserIsAnomymized(String login) {
package org.sonar.server.user.ws;
import java.util.Arrays;
+import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
.execute();
UserDto userDto = dbClient.userDao().selectByLogin(dbSession, "john");
- assertThat(userDto.getScmAccounts()).isNull();
+ assertThat(userDto.getSortedScmAccounts()).isEmpty();
}
@Test
.assertJson(getClass(), "update_scm_accounts.json");
UserDto user = dbClient.userDao().selectByLogin(dbSession, "john");
- assertThat(user.getScmAccountsAsList()).containsOnly("jon.snow");
+ assertThat(user.getSortedScmAccounts()).containsOnly("jon.snow");
}
@Test
- public void update_scm_account_having_coma() {
+ public void update_scm_account() {
createUser();
ws.newRequest()
.setParam("login", "john")
- .setMultiParam("scmAccount", singletonList("jon,snow"))
+ .setMultiParam("scmAccount", List.of("jon", "snow"))
.execute();
UserDto user = dbClient.userDao().selectByLogin(dbSession, "john");
- assertThat(user.getScmAccountsAsList()).containsOnly("jon,snow");
+ assertThat(user.getSortedScmAccounts()).containsExactly("jon", "snow");
}
@Test
.execute();
UserDto user = dbClient.userDao().selectByLogin(dbSession, "john");
- assertThat(user.getScmAccountsAsList()).containsExactly("Jon.1", "JON.2", "jon.3");
+ assertThat(user.getSortedScmAccounts()).containsExactly("Jon.1", "JON.2", "jon.3");
}
@Test
.setName(userDto.getName())
.setActive(userDto.isActive())
.setLocal(userDto.isLocal())
- .addAllScmAccounts(userDto.getScmAccountsAsList());
+ .addAllScmAccounts(userDto.getSortedScmAccounts());
ofNullable(emptyToNull(userDto.getEmail())).ifPresent(userBuilder::setEmail);
return CreateWsResponse.newBuilder().setUser(userBuilder).build();
}
.setName(user.getName())
.setLocal(user.isLocal())
.addAllGroups(groups)
- .addAllScmAccounts(user.getScmAccountsAsList())
+ .addAllScmAccounts(user.getSortedScmAccounts())
.setPermissions(Permissions.newBuilder().addAllGlobal(getGlobalPermissions()).build())
.setHomepage(buildHomepage(dbSession, user))
.setUsingSonarLintConnectedMode(user.getLastSonarlintConnectionDate() != null)
userBuilder.setActive(user.isActive());
userBuilder.setLocal(user.isLocal());
ofNullable(user.getExternalIdentityProvider()).ifPresent(userBuilder::setExternalProvider);
- if (!user.getScmAccountsAsList().isEmpty()) {
- userBuilder.setScmAccounts(ScmAccounts.newBuilder().addAllScmAccounts(user.getScmAccountsAsList()));
+ if (!user.getSortedScmAccounts().isEmpty()) {
+ userBuilder.setScmAccounts(ScmAccounts.newBuilder().addAllScmAccounts(user.getSortedScmAccounts()));
}
}
if (userSession.isSystemAdministrator() || Objects.equals(userSession.getUuid(), user.getUuid())) {
if (isFieldNeeded(FIELD_SCM_ACCOUNTS, fields)) {
json.name(FIELD_SCM_ACCOUNTS)
.beginArray()
- .values(user.getScmAccountsAsList())
+ .values(user.getSortedScmAccounts())
.endArray();
}
}