Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/use-only-us…
Browse files Browse the repository at this point in the history
…er.name#2336
  • Loading branch information
nulls committed Jul 20, 2023
2 parents e080a79 + 0b10c89 commit c5ef563
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.saveourtool.save.gateway.utils
import com.saveourtool.save.domain.Role
import com.saveourtool.save.entities.User
import com.saveourtool.save.gateway.config.ConfigurationProperties
import com.saveourtool.save.info.UserStatus

import org.slf4j.LoggerFactory
import org.springframework.http.MediaType
Expand Down Expand Up @@ -58,6 +59,6 @@ fun Authentication.toUser(): User = User(
authorities.joinToString(",") { it.authority },
toIdentitySource(),
null,
isActive = false,
status = UserStatus.CREATED,
originalLogins = emptyList(),
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saveourtool.save.authservice.repository

import com.saveourtool.save.entities.User
import com.saveourtool.save.info.UserStatus
import com.saveourtool.save.utils.orNotFound
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
import org.springframework.stereotype.Component
Expand Down Expand Up @@ -41,7 +42,7 @@ class AuthenticationUserRepository(
linkedin = record["linkedin"] as String?,
gitHub = record["git_hub"] as String?,
twitter = record["twitter"] as String?,
isActive = record["is_active"] as Boolean,
status = UserStatus.valueOf(record["status"] as String),
rating = record["rating"] as Long,
).apply {
this.id = record["id"] as Long
Expand Down
28 changes: 14 additions & 14 deletions db/test-data/sqlRequests/user.csv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
id;name;password;role;source;avatar;email;company;location;linkedin;git_hub;twitter;is_active;rating
1;"admin";"{bcrypt}$2a$12$7jB6.fJ/uHZiti94w0.QOu0M/lPzKU1lvX9TLL3uZHFjLGIfz1gHq";"ROLE_SUPER_ADMIN";"basic";;;;;;;;true;999
2;"JohnDoe";"{bcrypt}$2a$12$zjCjULtsSvapH5kt6KUq4eyTx3WluDwB3GepcbLA.mf/NcGZCLuvi";"ROLE_VIEWER";"basic";;;;;;;;false;-37
3;"user";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;0
4;"user1";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;-3
5;"user2";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;0
6;"user3";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;15
7;"user4";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;34
8;"user5";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;0
9;"user6";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;54
10;"user7";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;86
11;"user8";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;0
12;"user9";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;12
13;"user10";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;false;24
id;name;password;role;source;avatar;email;company;location;linkedin;git_hub;twitter;rating;status
1;"admin";"{bcrypt}$2a$12$7jB6.fJ/uHZiti94w0.QOu0M/lPzKU1lvX9TLL3uZHFjLGIfz1gHq";"ROLE_SUPER_ADMIN";"basic";;;;;;;;999;"ACTIVE"
2;"JohnDoe";"{bcrypt}$2a$12$zjCjULtsSvapH5kt6KUq4eyTx3WluDwB3GepcbLA.mf/NcGZCLuvi";"ROLE_VIEWER";"basic";;;;;;;;-37;"CREATED"
3;"user";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;0;"CREATED"
4;"user1";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;-3;"CREATED"
5;"user2";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;0;"CREATED"
6;"user3";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;15;"CREATED"
7;"user4";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;34;"CREATED"
8;"user5";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;0;"CREATED"
9;"user6";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;54;"CREATED"
10;"user7";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;86;"CREATED"
11;"user8";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;0;"CREATED"
12;"user9";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;12;"CREATED"
13;"user10";"noop{123}";"ROLE_VIEWER";"basic";;;;;;;;24;"CREATED"
17 changes: 17 additions & 0 deletions db/v-2/tables/user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,21 @@
<addNotNullConstraint tableName="user" columnName="name" columnDataType="varchar(64)"/>
<addNotNullConstraint tableName="user" columnName="source" columnDataType="varchar(64)" defaultNullValue="basic"/>
</changeSet>

<changeSet id="user-add-status" author="frolov" context="dev or prod">
<addColumn tableName="user">
<column name="status" type="varchar(64)" defaultValue="CREATED">
<constraints nullable="false"/>
</column>
</addColumn>

<sql>
UPDATE user SET status = 'ACTIVE' WHERE is_active = 1;
</sql>

<dropColumn tableName="user">
<column name="is_active"/>
</dropColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class UsersDetailsController(
gitHub = newUserInfo.gitHub
linkedin = newUserInfo.linkedin
twitter = newUserInfo.twitter
isActive = newUserInfo.isActive
status = newUserInfo.status
}, newUserInfo.oldName)
} else {
UserSaveStatus.CONFLICT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.saveourtool.save.domain.Role
import com.saveourtool.save.entities.OriginalLogin
import com.saveourtool.save.entities.User
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.info.UserStatus
import com.saveourtool.save.v1
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -36,7 +37,7 @@ class UsersControllerTest {
Role.VIEWER.asSpringSecurityRole(),
"basic2",
null,
isActive = false,
status = UserStatus.CREATED,
).apply { id = 99 }

val originalLogin = OriginalLogin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.saveourtool.save.backend.SaveApplication
import com.saveourtool.save.backend.utils.InfraExtension
import com.saveourtool.save.backend.utils.mutateMockedUser
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.info.UserStatus
import com.saveourtool.save.v1
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
Expand Down Expand Up @@ -34,7 +35,7 @@ class UsersDetailsControllerTest {
source = "basic",
email = "[email protected]",
company = "Example",
isActive = true,
status = UserStatus.ACTIVE,
)

webClient.post()
Expand All @@ -58,7 +59,7 @@ class UsersDetailsControllerTest {
oldName = "admin",
email = "[email protected]",
company = "Example",
isActive = true,
status = UserStatus.ACTIVE,
)

webClient.post()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kotlinx.serialization.Serializable
* @property organizations
* @property globalRole
* @property id
* @property isActive
* @property status
* @property oldName is always null except for the process of renaming the user.
* @property originalLogins
* @property rating
Expand All @@ -46,7 +46,7 @@ data class UserInfo(
val gitHub: String? = null,
val twitter: String? = null,
val globalRole: Role? = null,
val isActive: Boolean = false,
val status: UserStatus = UserStatus.CREATED,
val rating: Long = 0,
) : Validatable {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.saveourtool.save.info

import kotlinx.serialization.Serializable

/**
* Enum of user status
*
* The order of the elements is used for sorting
*/
@Serializable
@Suppress("WRONG_DECLARATIONS_ORDER")
enum class UserStatus {
/**
* User created
*/
CREATED,

/**
* User active
*/
ACTIVE,

/**
* User deleted
*/
DELETED,
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package com.saveourtool.save.entities

import com.saveourtool.save.domain.Role
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.info.UserStatus
import com.saveourtool.save.spring.entity.BaseEntity

import com.fasterxml.jackson.annotation.JsonIgnore

import javax.persistence.Entity
import javax.persistence.FetchType
import javax.persistence.OneToMany
import javax.persistence.*

/**
* @property name
Expand All @@ -22,7 +21,7 @@ import javax.persistence.OneToMany
* @property linkedin
* @property gitHub
* @property twitter
* @property isActive
* @property status
* @property originalLogins
* @property rating rating of user
*/
Expand All @@ -40,7 +39,8 @@ class User(
var linkedin: String? = null,
var gitHub: String? = null,
var twitter: String? = null,
var isActive: Boolean = false,
@Enumerated(EnumType.STRING)
var status: UserStatus = UserStatus.CREATED,
@OneToMany(
fetch = FetchType.EAGER,
mappedBy = "user",
Expand Down Expand Up @@ -69,7 +69,7 @@ class User(
gitHub = gitHub,
twitter = twitter,
location = location,
isActive = isActive,
status = status,
rating = rating,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.saveourtool.save.frontend.http.getUser
import com.saveourtool.save.frontend.routing.basicRouting
import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.info.UserStatus
import com.saveourtool.save.validation.FrontendRoutes

import react.*
Expand Down Expand Up @@ -107,7 +108,7 @@ class App : ComponentWithScope<PropsWithChildren, AppState>() {
requestModalHandler {
userInfo = state.userInfo

if (state.userInfo?.isActive == false) {
if (state.userInfo?.status == UserStatus.CREATED) {
Navigate {
to = "/${FrontendRoutes.REGISTRATION}"
replace = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.saveourtool.save.frontend.components.modal.MAX_Z_INDEX
import com.saveourtool.save.frontend.http.postImageUpload
import com.saveourtool.save.frontend.utils.*
import com.saveourtool.save.info.UserInfo
import com.saveourtool.save.info.UserStatus
import com.saveourtool.save.utils.AvatarType
import com.saveourtool.save.v1
import com.saveourtool.save.validation.isValidName
Expand Down Expand Up @@ -63,7 +64,7 @@ val registrationView: FC<RegistrationProps> = FC { props ->
val saveUser = useDeferredRequest {
val newUserInfo = userInfo.copy(
oldName = props.userInfo?.name!!,
isActive = true,
status = UserStatus.ACTIVE,
)
val response = post(
"$apiUrl/users/save",
Expand Down Expand Up @@ -91,7 +92,7 @@ val registrationView: FC<RegistrationProps> = FC { props ->
}
}

if (props.userInfo?.isActive != false) {
if (props.userInfo?.status == UserStatus.ACTIVE) {
navigate("/", jso { replace = true })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ abstract class UserSettingsView : AbstractView<UserSettingsProps, UserSettingsVi
gitHub = fieldsMap[InputTypes.GIT_HUB]?.trim(),
twitter = fieldsMap[InputTypes.TWITTER]?.trim(),
avatar = state.userInfo!!.avatar,
isActive = state.userInfo!!.isActive,
status = state.userInfo!!.status,
)

val headers = Headers().also {
Expand Down

0 comments on commit c5ef563

Please sign in to comment.