Skip to content

Commit

Permalink
Delete user information (#2384)
Browse files Browse the repository at this point in the history
* Deleted user information
  • Loading branch information
Cheshiriks authored Jul 31, 2023
1 parent 130576c commit 0bec476
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,9 @@ interface LnkUserOrganizationRepository : BaseEntityRepository<LnkUserOrganizati
* @return List of [LnkUserOrganization] in which user with [userName] participates
*/
fun findByUserName(userName: String): List<LnkUserOrganization>

/**
* @param userId id of user
*/
fun deleteByUserId(userId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ interface LnkUserProjectRepository : BaseEntityRepository<LnkUserProject> {
@Param("user_id") userId: Long,
@Param("role") role: String
)

/**
* @param userId id of user
*/
fun deleteByUserId(userId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0bec476

Please sign in to comment.