From 0bec47642e8cc9e25aabe836af81dbe45901b92f Mon Sep 17 00:00:00 2001 From: Vladislav Frolov <50615459+Cheshiriks@users.noreply.github.com> Date: Mon, 31 Jul 2023 15:19:15 +0300 Subject: [PATCH] Delete user information (#2384) * Deleted user information --- .../LnkUserOrganizationRepository.kt | 5 +++++ .../repository/LnkUserProjectRepository.kt | 5 +++++ .../backend/service/UserDetailsService.kt | 21 +++++++++++++++++++ .../controller/OrganizationControllerTest.kt | 3 +++ .../backend/security/BasicSecurityTest.kt | 6 ++++++ 5 files changed, 40 insertions(+) diff --git a/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserOrganizationRepository.kt b/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserOrganizationRepository.kt index 60210df884..b7595cd649 100644 --- a/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserOrganizationRepository.kt +++ b/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserOrganizationRepository.kt @@ -80,4 +80,9 @@ interface LnkUserOrganizationRepository : BaseEntityRepository + + /** + * @param userId id of user + */ + fun deleteByUserId(userId: Long) } diff --git a/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserProjectRepository.kt b/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserProjectRepository.kt index 624c0746ac..ef58f540bd 100644 --- a/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserProjectRepository.kt +++ b/save-backend/src/main/kotlin/com/saveourtool/save/backend/repository/LnkUserProjectRepository.kt @@ -60,4 +60,9 @@ interface LnkUserProjectRepository : BaseEntityRepository { @Param("user_id") userId: Long, @Param("role") role: String ) + + /** + * @param userId id of user + */ + fun deleteByUserId(userId: Long) } diff --git a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/UserDetailsService.kt b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/UserDetailsService.kt index 69ba3d4905..7f60998495 100644 --- a/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/UserDetailsService.kt +++ b/save-backend/src/main/kotlin/com/saveourtool/save/backend/service/UserDetailsService.kt @@ -2,8 +2,12 @@ package com.saveourtool.save.backend.service import com.saveourtool.save.authservice.utils.toSpringUserDetails import com.saveourtool.save.authservice.utils.userId +import com.saveourtool.save.backend.repository.LnkUserOrganizationRepository +import com.saveourtool.save.backend.repository.LnkUserProjectRepository import com.saveourtool.save.backend.repository.OriginalLoginRepository import com.saveourtool.save.backend.repository.UserRepository +import com.saveourtool.save.backend.storage.AvatarKey +import com.saveourtool.save.backend.storage.AvatarStorage import com.saveourtool.save.domain.Role import com.saveourtool.save.domain.UserSaveStatus import com.saveourtool.save.entities.OriginalLogin @@ -26,6 +30,9 @@ import java.util.* class UserDetailsService( private val userRepository: UserRepository, private val originalLoginRepository: OriginalLoginRepository, + private val lnkUserOrganizationRepository: LnkUserOrganizationRepository, + private val lnkUserProjectRepository: LnkUserProjectRepository, + private val avatarStorage: AvatarStorage, ) { /** * @param username @@ -147,12 +154,26 @@ class UserDetailsService( this.name = newName this.status = UserStatus.DELETED this.avatar = null + this.company = null + this.twitter = null + this.email = null + this.gitHub = null + this.linkedin = null + this.location = null }) } else { return UserSaveStatus.CONFLICT } + val avatarKey = AvatarKey( + AvatarType.USER, + name, + ) + avatarStorage.delete(avatarKey) + originalLoginRepository.deleteByUserId(user.requiredId()) + lnkUserProjectRepository.deleteByUserId(user.requiredId()) + lnkUserOrganizationRepository.deleteByUserId(user.requiredId()) return UserSaveStatus.DELETED } diff --git a/save-backend/src/test/kotlin/com/saveourtool/save/backend/controller/OrganizationControllerTest.kt b/save-backend/src/test/kotlin/com/saveourtool/save/backend/controller/OrganizationControllerTest.kt index f2b141302a..a7ed6ca3aa 100644 --- a/save-backend/src/test/kotlin/com/saveourtool/save/backend/controller/OrganizationControllerTest.kt +++ b/save-backend/src/test/kotlin/com/saveourtool/save/backend/controller/OrganizationControllerTest.kt @@ -9,6 +9,7 @@ import com.saveourtool.save.backend.security.ProjectPermissionEvaluator import com.saveourtool.save.backend.service.* import com.saveourtool.save.authservice.utils.AuthenticationDetails import com.saveourtool.save.backend.S11nTestConfig +import com.saveourtool.save.backend.storage.AvatarStorage import com.saveourtool.save.backend.storage.TestsSourceSnapshotStorage import com.saveourtool.save.backend.utils.mutateMockedUser import com.saveourtool.save.domain.Role @@ -80,10 +81,12 @@ import java.util.concurrent.TimeUnit MockBean(AgentRepository::class), MockBean(ProjectRepository::class), MockBean(LnkUserProjectRepository::class), + MockBean(LnkUserOrganizationRepository::class), MockBean(OriginalLoginRepository::class), MockBean(LnkContestProjectService::class), MockBean(LnkOrganizationTestSuiteService::class), MockBean(LnkExecutionTestSuiteService::class), + MockBean(AvatarStorage::class), ) @AutoConfigureWebTestClient @Suppress("UnsafeCallOnNullableType") diff --git a/save-backend/src/test/kotlin/com/saveourtool/save/backend/security/BasicSecurityTest.kt b/save-backend/src/test/kotlin/com/saveourtool/save/backend/security/BasicSecurityTest.kt index deb46e4b9c..d061d09d51 100644 --- a/save-backend/src/test/kotlin/com/saveourtool/save/backend/security/BasicSecurityTest.kt +++ b/save-backend/src/test/kotlin/com/saveourtool/save/backend/security/BasicSecurityTest.kt @@ -7,6 +7,9 @@ import com.saveourtool.save.backend.repository.OriginalLoginRepository import com.saveourtool.save.backend.repository.UserRepository import com.saveourtool.save.backend.service.UserDetailsService import com.saveourtool.save.authservice.utils.AuthenticationDetails +import com.saveourtool.save.backend.repository.LnkUserOrganizationRepository +import com.saveourtool.save.backend.repository.LnkUserProjectRepository +import com.saveourtool.save.backend.storage.AvatarStorage import com.saveourtool.save.entities.User import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach @@ -35,6 +38,9 @@ import org.springframework.test.context.junit.jupiter.SpringExtension MockBean(UserRepository::class), MockBean(OriginalLoginRepository::class), MockBean(NamedParameterJdbcTemplate::class), + MockBean(LnkUserProjectRepository::class), + MockBean(LnkUserOrganizationRepository::class), + MockBean(AvatarStorage::class), ) class BasicSecurityTest { @Autowired