Skip to content

Commit

Permalink
add save mandatory actions capability
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFlick72 committed Oct 14, 2023
1 parent f28f675 commit b7d85e1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data class Account(
val birthDate: Optional<Date>,
val phone: Optional<Phone>,
val locale: Optional<UserLocale>,
val mandatoryActions: List<AccountMandatoryAction> = listOf(NO_ACTION)
val mandatoryAction: AccountMandatoryAction =NO_ACTION
) {
val sub: String
get() = email.toSha256()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.vauthenticator.server.account.repository

import com.vauthenticator.server.account.*
import com.vauthenticator.server.extentions.*
import com.vauthenticator.server.extentions.asDynamoAttribute
import com.vauthenticator.server.extentions.valueAsBoolFor
import com.vauthenticator.server.extentions.valueAsStringFor
import com.vauthenticator.server.extentions.valueAsStringSetFor
import software.amazon.awssdk.services.dynamodb.model.AttributeValue

object DynamoAccountConverter {
Expand All @@ -22,8 +25,7 @@ object DynamoAccountConverter {
birthDate = Date.isoDateFor(dynamoPayload.valueAsStringFor("birthDate")),
phone = Phone.phoneFor(dynamoPayload.valueAsStringFor("phone")),
locale = UserLocale.localeFrom(dynamoPayload.valueAsStringFor("locale")),
mandatoryActions = dynamoPayload.valuesAsListOfStringFor("mandatory_actions")
.map(AccountMandatoryAction::valueOf)
mandatoryAction = AccountMandatoryAction.valueOf(dynamoPayload.valueAsStringFor("mandatory_action"))
)

fun fromDomainToDynamo(account: Account) =
Expand All @@ -42,6 +44,6 @@ object DynamoAccountConverter {
"birthDate" to account.birthDate.map { it.asDynamoAttribute() }.orElse("".asDynamoAttribute()),
"phone" to account.phone.map { it.asDynamoAttribute() }.orElse("".asDynamoAttribute()),
"locale" to account.locale.map { it.formattedLocale().asDynamoAttribute() }.orElse("".asDynamoAttribute()),
"mandatory_actions" to account.mandatoryActions.map { it.name }.toSet().asDynamoAttribute()
"mandatory_action" to account.mandatoryAction.let { it.name }.asDynamoAttribute()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,8 @@ object AccountTestFixture {
birthDate = Date.empty(),
phone = Phone.empty(),
locale = UserLocale.empty(),
mandatoryActions = listOf(AccountMandatoryAction.NO_ACTION)
mandatoryAction = AccountMandatoryAction.NO_ACTION
)

fun anAccount(roles: Set<Role>) = Account(
enabled = true,
username = EMAIL,
password = "secret",
authorities = roles.map { it.name }.toSet(),
email = EMAIL,
firstName = "A First Name",
lastName = "A Last Name",
birthDate = Date.empty(),
phone = Phone.empty(),
locale = UserLocale.empty(),
mandatoryActions = listOf(AccountMandatoryAction.NO_ACTION)
)
fun anAccount(roles: Set<Role>) = anAccount().copy(authorities = roles.map { it.name }.toSet())
}

0 comments on commit b7d85e1

Please sign in to comment.