diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-03-29 16:20:40 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-04-01 08:22:58 +0000 |
commit | dc84e9f271f4a72de0b55c0cfd141bf67e1ddeb8 (patch) | |
tree | 53d489c0daf9151261fcab862bd6ba23020e3697 /server/sonar-db-dao | |
parent | d27e2321560f15d7d5a59e1c99c80891d7632bdd (diff) | |
download | sonarqube-dc84e9f271f4a72de0b55c0cfd141bf67e1ddeb8.tar.gz sonarqube-dc84e9f271f4a72de0b55c0cfd141bf67e1ddeb8.zip |
SONAR-16139 Drop api/users/set_setting and related db table
Diffstat (limited to 'server/sonar-db-dao')
13 files changed, 0 insertions, 584 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java index 514b8396379..c0c487f2f34 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java @@ -88,7 +88,6 @@ import org.sonar.db.user.SessionTokensDao; import org.sonar.db.user.UserDao; import org.sonar.db.user.UserDismissedMessagesDao; import org.sonar.db.user.UserGroupDao; -import org.sonar.db.user.UserPropertiesDao; import org.sonar.db.user.UserTokenDao; import org.sonar.db.webhook.WebhookDao; import org.sonar.db.webhook.WebhookDeliveryDao; @@ -165,7 +164,6 @@ public class DaoModule extends Module { UserDismissedMessagesDao.class, UserGroupDao.class, UserPermissionDao.class, - UserPropertiesDao.class, UserTokenDao.class, WebhookDao.class, WebhookDeliveryDao.class); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java index d4738c368d1..d545de23ae5 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java @@ -88,7 +88,6 @@ import org.sonar.db.user.SessionTokensDao; import org.sonar.db.user.UserDao; import org.sonar.db.user.UserDismissedMessagesDao; import org.sonar.db.user.UserGroupDao; -import org.sonar.db.user.UserPropertiesDao; import org.sonar.db.user.UserTokenDao; import org.sonar.db.webhook.WebhookDao; import org.sonar.db.webhook.WebhookDeliveryDao; @@ -117,7 +116,6 @@ public class DbClient { private final UserDao userDao; private final UserGroupDao userGroupDao; private final UserTokenDao userTokenDao; - private final UserPropertiesDao userPropertiesDao; private final GroupMembershipDao groupMembershipDao; private final RoleDao roleDao; private final GroupPermissionDao groupPermissionDao; @@ -197,7 +195,6 @@ public class DbClient { userDao = getDao(map, UserDao.class); userGroupDao = getDao(map, UserGroupDao.class); userTokenDao = getDao(map, UserTokenDao.class); - userPropertiesDao = getDao(map, UserPropertiesDao.class); groupMembershipDao = getDao(map, GroupMembershipDao.class); roleDao = getDao(map, RoleDao.class); groupPermissionDao = getDao(map, GroupPermissionDao.class); @@ -353,10 +350,6 @@ public class DbClient { return userTokenDao; } - public UserPropertiesDao userPropertiesDao() { - return userPropertiesDao; - } - public GroupMembershipDao groupMembershipDao() { return groupMembershipDao; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java index 05264bc1b8f..99875cdcbd7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java @@ -151,7 +151,6 @@ import org.sonar.db.user.UserDto; import org.sonar.db.user.UserGroupDto; import org.sonar.db.user.UserGroupMapper; import org.sonar.db.user.UserMapper; -import org.sonar.db.user.UserPropertiesMapper; import org.sonar.db.user.UserTokenCount; import org.sonar.db.user.UserTokenDto; import org.sonar.db.user.UserTokenMapper; @@ -307,7 +306,6 @@ public class MyBatis { UserGroupMapper.class, UserMapper.class, UserPermissionMapper.class, - UserPropertiesMapper.class, UserTokenMapper.class, WebhookMapper.class, WebhookDeliveryMapper.class diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java index 7ec024dc93e..6ed7738db0a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java @@ -22,7 +22,6 @@ package org.sonar.db.audit.model; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.db.property.PropertyDto; -import org.sonar.db.user.UserPropertyDto; public class PropertyNewValue extends NewValue { private String propertyKey; @@ -48,14 +47,6 @@ public class PropertyNewValue extends NewValue { @Nullable private String qualifier; - public PropertyNewValue(UserPropertyDto userPropertyDto, @Nullable String login) { - this.propertyKey = userPropertyDto.getKey(); - this.userUuid = userPropertyDto.getUserUuid(); - this.userLogin = login; - - setValue(propertyKey, userPropertyDto.getValue()); - } - public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String componentKey, @Nullable String componentName, @Nullable String qualifier) { this.propertyKey = propertyDto.getKey(); this.userUuid = propertyDto.getUserUuid(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertiesDao.java deleted file mode 100644 index a9760372208..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertiesDao.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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.List; -import javax.annotation.Nullable; -import org.sonar.api.utils.System2; -import org.sonar.core.util.UuidFactory; -import org.sonar.db.Dao; -import org.sonar.db.DbSession; -import org.sonar.db.audit.AuditPersister; -import org.sonar.db.audit.model.PropertyNewValue; - -public class UserPropertiesDao implements Dao { - - private final System2 system2; - private final UuidFactory uuidFactory; - private final AuditPersister auditPersister; - - public UserPropertiesDao(System2 system2, UuidFactory uuidFactory, AuditPersister auditPersister) { - this.system2 = system2; - this.uuidFactory = uuidFactory; - this.auditPersister = auditPersister; - } - - public List<UserPropertyDto> selectByUser(DbSession session, UserDto user) { - return mapper(session).selectByUserUuid(user.getUuid()); - } - - public UserPropertyDto insertOrUpdate(DbSession session, UserPropertyDto dto, @Nullable String login) { - long now = system2.now(); - boolean isUpdate = true; - if (mapper(session).update(dto, now) == 0) { - mapper(session).insert(dto.setUuid(uuidFactory.create()), now); - isUpdate = false; - } - - if (isUpdate) { - auditPersister.updateProperty(session, new PropertyNewValue(dto, login), true); - } else { - auditPersister.addProperty(session, new PropertyNewValue(dto, login), true); - } - - return dto; - } - - public void deleteByUser(DbSession session, UserDto user) { - List<UserPropertyDto> userProperties = selectByUser(session, user); - int deletedRows = mapper(session).deleteByUserUuid(user.getUuid()); - - if (deletedRows > 0) { - userProperties.stream() - .filter(p -> auditPersister.isTrackedProperty(p.getKey())) - .forEach(p -> auditPersister.deleteProperty(session, new PropertyNewValue(p, user.getLogin()), true)); - } - } - - private static UserPropertiesMapper mapper(DbSession session) { - return session.getMapper(UserPropertiesMapper.class); - } - -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertiesMapper.java deleted file mode 100644 index f2ba305f19b..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertiesMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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.List; -import org.apache.ibatis.annotations.Param; - -public interface UserPropertiesMapper { - - List<UserPropertyDto> selectByUserUuid(@Param("userUuid") String userUuid); - - void insert(@Param("userProperty") UserPropertyDto userPropertyDto, @Param("now") long now); - - int update(@Param("userProperty") UserPropertyDto userPropertyDto, @Param("now") long now); - - int deleteByUserUuid(@Param("userUuid") String userUuid); - -} diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertyDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertyDto.java deleted file mode 100644 index 8d5030792bf..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/UserPropertyDto.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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; - -public class UserPropertyDto { - - /** - * Unique UUID identifier. Max size is 40. Can't be null. - */ - private String uuid; - - /** - * The UUID of the user the settings belongs to. Max size is 255. Can't be null. - */ - private String userUuid; - - /** - * The key of the settings. Max size is 100. Can't be null. - */ - private String key; - - /** - * The value of the settings. Max size is 4000. Can't be null. - */ - private String value; - - public String getUuid() { - return uuid; - } - - UserPropertyDto setUuid(String uuid) { - this.uuid = uuid; - return this; - } - - public String getUserUuid() { - return userUuid; - } - - public UserPropertyDto setUserUuid(String userUuid) { - this.userUuid = userUuid; - return this; - } - - public String getKey() { - return key; - } - - public UserPropertyDto setKey(String key) { - this.key = key; - return this; - } - - public String getValue() { - return value; - } - - public UserPropertyDto setValue(String value) { - this.value = value; - return this; - } - -} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserPropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserPropertiesMapper.xml deleted file mode 100644 index 28016ebf74e..00000000000 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/UserPropertiesMapper.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd"> - -<mapper namespace="org.sonar.db.user.UserPropertiesMapper"> - - <sql id="userPropertiesColumns"> - us.uuid as uuid, - us.user_uuid as userUuid, - us.kee as "key", - us.text_value as "value" - </sql> - - <select id="selectByUserUuid" parameterType="String" resultType="org.sonar.db.user.UserPropertyDto"> - SELECT - <include refid="userPropertiesColumns"/> - FROM user_properties us - WHERE us.user_uuid=#{userUuid} - </select> - - <insert id="insert" parameterType="map" useGeneratedKeys="false"> - INSERT INTO user_properties ( - uuid, - user_uuid, - kee, - text_value, - created_at, - updated_at - ) VALUES ( - #{userProperty.uuid,jdbcType=VARCHAR}, - #{userProperty.userUuid,jdbcType=VARCHAR}, - #{userProperty.key,jdbcType=VARCHAR}, - #{userProperty.value,jdbcType=VARCHAR}, - #{now,jdbcType=BIGINT}, - #{now,jdbcType=BIGINT} - ) - </insert> - - <update id="update" parameterType="map"> - UPDATE user_properties SET - text_value = #{userProperty.value, jdbcType=VARCHAR}, - updated_at = #{now,jdbcType=BIGINT} - WHERE - user_uuid = #{userProperty.userUuid, jdbcType=VARCHAR} - AND kee = #{userProperty.key, jdbcType=VARCHAR} - </update> - - <update id="deleteByUserUuid" parameterType="String"> - DELETE FROM user_properties WHERE user_uuid=#{userUuid,jdbcType=VARCHAR} - </update> - -</mapper> diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index acb80785e6c..ed4aaad7927 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -942,17 +942,6 @@ CREATE UNIQUE INDEX "UNIQ_USER_DISMISSED_MESSAGES" ON "USER_DISMISSED_MESSAGES"( CREATE INDEX "UDM_PROJECT_UUID" ON "USER_DISMISSED_MESSAGES"("PROJECT_UUID" NULLS FIRST); CREATE INDEX "UDM_MESSAGE_TYPE" ON "USER_DISMISSED_MESSAGES"("MESSAGE_TYPE" NULLS FIRST); -CREATE TABLE "USER_PROPERTIES"( - "UUID" CHARACTER VARYING(40) NOT NULL, - "USER_UUID" CHARACTER VARYING(255) NOT NULL, - "KEE" CHARACTER VARYING(100) NOT NULL, - "TEXT_VALUE" CHARACTER VARYING(4000) NOT NULL, - "CREATED_AT" BIGINT NOT NULL, - "UPDATED_AT" BIGINT NOT NULL -); -ALTER TABLE "USER_PROPERTIES" ADD CONSTRAINT "PK_USER_PROPERTIES" PRIMARY KEY("UUID"); -CREATE UNIQUE INDEX "USER_PROPERTIES_USER_UUID_KEE" ON "USER_PROPERTIES"("USER_UUID" NULLS FIRST, "KEE" NULLS FIRST); - CREATE TABLE "USER_ROLES"( "UUID" CHARACTER VARYING(40) NOT NULL, "ROLE" CHARACTER VARYING(64) NOT NULL, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserPropertiesDaoTest.java deleted file mode 100644 index 674923b96a2..00000000000 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserPropertiesDaoTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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.List; -import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.impl.utils.TestSystem2; -import org.sonar.db.DbTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - -public class UserPropertiesDaoTest { - - private static final long NOW = 1_500_000_000_000L; - - private TestSystem2 system2 = new TestSystem2().setNow(NOW); - - @Rule - public DbTester db = DbTester.create(system2); - - private UserPropertiesDao underTest = db.getDbClient().userPropertiesDao(); - - @Test - public void select_by_user() { - UserDto user = db.users().insertUser(); - UserPropertyDto userSetting1 = db.users().insertUserSetting(user); - UserPropertyDto userSetting2 = db.users().insertUserSetting(user); - UserDto anotherUser = db.users().insertUser(); - UserPropertyDto userSetting3 = db.users().insertUserSetting(anotherUser); - - List<UserPropertyDto> results = underTest.selectByUser(db.getSession(), user); - - assertThat(results) - .extracting(UserPropertyDto::getUuid) - .containsExactlyInAnyOrder(userSetting1.getUuid(), userSetting2.getUuid()) - .doesNotContain(userSetting3.getUuid()); - } - - @Test - public void insert() { - UserDto user = db.users().insertUser(); - - UserPropertyDto userSetting = underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey("a_key") - .setValue("a_value"), - user.getLogin()); - - Map<String, Object> map = db.selectFirst(db.getSession(), "select uuid as \"uuid\",\n" + - " user_uuid as \"userUuid\",\n" + - " kee as \"key\",\n" + - " text_value as \"value\"," + - " created_at as \"createdAt\",\n" + - " updated_at as \"updatedAt\"" + - " from user_properties"); - assertThat(map).contains( - entry("uuid", userSetting.getUuid()), - entry("userUuid", user.getUuid()), - entry("key", "a_key"), - entry("value", "a_value"), - entry("createdAt", NOW), - entry("updatedAt", NOW)); - } - - @Test - public void update() { - UserDto user = db.users().insertUser(); - UserPropertyDto userProperty = underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey("a_key") - .setValue("old_value"), - user.getLogin()); - - system2.setNow(2_000_000_000_000L); - underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey("a_key") - .setValue("new_value"), - user.getLogin()); - - Map<String, Object> map = db.selectFirst(db.getSession(), "select uuid as \"uuid\",\n" + - " user_uuid as \"userUuid\",\n" + - " kee as \"key\",\n" + - " text_value as \"value\"," + - " created_at as \"createdAt\",\n" + - " updated_at as \"updatedAt\"" + - " from user_properties"); - assertThat(map).contains( - entry("uuid", userProperty.getUuid()), - entry("userUuid", user.getUuid()), - entry("key", "a_key"), - entry("value", "new_value"), - entry("createdAt", NOW), - entry("updatedAt", 2_000_000_000_000L)); - } - - @Test - public void delete_by_user() { - UserDto user = db.users().insertUser(); - db.users().insertUserSetting(user); - db.users().insertUserSetting(user); - UserDto anotherUser = db.users().insertUser(); - db.users().insertUserSetting(anotherUser); - - underTest.deleteByUser(db.getSession(), user); - - assertThat(underTest.selectByUser(db.getSession(), user)).isEmpty(); - assertThat(underTest.selectByUser(db.getSession(), anotherUser)).hasSize(1); - } -} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserPropertiesDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserPropertiesDaoWithPersisterTest.java deleted file mode 100644 index d491d8085df..00000000000 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserPropertiesDaoWithPersisterTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2022 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 org.junit.Rule; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.sonar.api.impl.utils.TestSystem2; -import org.sonar.db.DbTester; -import org.sonar.db.audit.AuditPersister; -import org.sonar.db.audit.model.PropertyNewValue; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -public class UserPropertiesDaoWithPersisterTest { - private static final long NOW = 1_500_000_000_000L; - private static final String SECURED_PROPERTY_KEY = "a_key.secured"; - private static final String PROPERTY_KEY = "a_key"; - - private final AuditPersister auditPersister = mock(AuditPersister.class); - private ArgumentCaptor<PropertyNewValue> newValueCaptor = ArgumentCaptor.forClass(PropertyNewValue.class); - - private TestSystem2 system2 = new TestSystem2().setNow(NOW); - - @Rule - public DbTester db = DbTester.create(system2, auditPersister); - - private UserPropertiesDao underTest = db.getDbClient().userPropertiesDao(); - - @Test - public void insertTrackedUserPropertyIsPersisted() { - UserDto user = db.users().insertUser(); - - verify(auditPersister).addUser(eq(db.getSession()), any()); - - UserPropertyDto userSetting = underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey(PROPERTY_KEY) - .setValue("a_value"), - user.getLogin()); - - verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true)); - assertThat(newValueCaptor.getValue()) - .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, - PropertyNewValue::getUserLogin) - .containsExactly(userSetting.getKey(), userSetting.getValue(), user.getUuid(), user.getLogin()); - - } - - @Test - public void insertTrackedAndSecuredUserPropertyIsPersisted() { - UserDto user = db.users().insertUser(); - - verify(auditPersister).addUser(eq(db.getSession()), any()); - - UserPropertyDto userSetting = underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey(SECURED_PROPERTY_KEY) - .setValue("a_value"), - user.getLogin()); - - verify(auditPersister).addProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true)); - PropertyNewValue newValue = newValueCaptor.getValue(); - assertThat(newValue) - .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, - PropertyNewValue::getUserLogin) - .containsExactly(userSetting.getKey(), null, user.getUuid(), user.getLogin()); - assertThat(newValue.toString()).doesNotContain("propertyValue"); - } - - @Test - public void updateTrackedUserPropertyIsPersisted() { - UserDto user = db.users().insertUser(); - underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey(PROPERTY_KEY) - .setValue("old_value"), - user.getLogin()); - system2.setNow(2_000_000_000_000L); - UserPropertyDto userSetting = underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey(PROPERTY_KEY) - .setValue("new_value"), - user.getLogin()); - - verify(auditPersister).addUser(eq(db.getSession()), any()); - verify(auditPersister).addProperty(eq(db.getSession()), any(), eq(true)); - verify(auditPersister).updateProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true)); - assertThat(newValueCaptor.getValue()) - .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, - PropertyNewValue::getUserLogin) - .containsExactly(userSetting.getKey(), userSetting.getValue(), user.getUuid(), user.getLogin()); - } - - @Test - public void deleteTrackedUserPropertyIsPersisted() { - when(auditPersister.isTrackedProperty(PROPERTY_KEY)).thenReturn(true); - when(auditPersister.isTrackedProperty(SECURED_PROPERTY_KEY)).thenReturn(false); - - UserDto user = db.users().insertUser(); - UserPropertyDto userSetting = underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey(PROPERTY_KEY) - .setValue("a_value"), - user.getLogin()); - underTest.insertOrUpdate(db.getSession(), new UserPropertyDto() - .setUserUuid(user.getUuid()) - .setKey(SECURED_PROPERTY_KEY) - .setValue("another_value"), - user.getLogin()); - underTest.deleteByUser(db.getSession(), user); - - verify(auditPersister).addUser(eq(db.getSession()), any()); - verify(auditPersister, times(2)).addProperty(eq(db.getSession()), any(), eq(true)); - verify(auditPersister).isTrackedProperty(PROPERTY_KEY); - verify(auditPersister).isTrackedProperty(SECURED_PROPERTY_KEY); - verify(auditPersister).deleteProperty(eq(db.getSession()), newValueCaptor.capture(), eq(true)); - verifyNoMoreInteractions(auditPersister); - assertThat(newValueCaptor.getValue()) - .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, - PropertyNewValue::getUserLogin) - .containsExactly(userSetting.getKey(), userSetting.getValue(), user.getUuid(), user.getLogin()); - } - - @Test - public void deleteTrackedUserPropertyWithoutAffectedRowsIsNotPersisted() { - UserDto user = db.users().insertUser(); - - underTest.deleteByUser(db.getSession(), user); - - verify(auditPersister).addUser(eq(db.getSession()), any()); - verifyNoMoreInteractions(auditPersister); - } -} diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java index 180ce68082e..5078c9d1b39 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java @@ -122,17 +122,6 @@ public class UserDbTester { return Optional.ofNullable(dbClient.userDao().selectByExternalLoginAndIdentityProvider(db.getSession(), login, identityProvider)); } - // USER SETTINGS - - @SafeVarargs - public final UserPropertyDto insertUserSetting(UserDto user, Consumer<UserPropertyDto>... populators) { - UserPropertyDto dto = UserTesting.newUserSettingDto(user); - stream(populators).forEach(p -> p.accept(dto)); - dbClient.userPropertiesDao().insertOrUpdate(db.getSession(), dto, user.getLogin()); - db.commit(); - return dto; - } - // GROUPS public GroupDto insertGroup(String name) { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java index f47fd4e622d..042e80f9c4e 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserTesting.java @@ -20,7 +20,6 @@ package org.sonar.db.user; import javax.annotation.Nullable; -import org.sonar.core.util.Uuids; import static java.util.Collections.singletonList; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; @@ -86,12 +85,4 @@ public class UserTesting { .setCryptedPassword(null) .setSalt(null); } - - public static UserPropertyDto newUserSettingDto(UserDto user) { - return new UserPropertyDto() - .setUuid(Uuids.createFast()) - .setUserUuid(user.getUuid()) - .setKey(randomAlphanumeric(20)) - .setValue(randomAlphanumeric(100)); - } } |