Skip to content

Commit

Permalink
Remove unnecessary conversations and also just use unwrap for tagged …
Browse files Browse the repository at this point in the history
…strings
  • Loading branch information
realvictorprm committed Jan 19, 2022
1 parent 2213d51 commit cde761f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import scalaz.syntax.show._
import spray.json.JsValue

import scala.concurrent.Future
import scalaz.syntax.tag._

@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements"))
trait HttpServiceIntegrationTestUserManagementFuns
Expand All @@ -52,7 +53,7 @@ trait HttpServiceIntegrationTestUserManagementFuns
def headersWithUserAuth(userId: String): List[Authorization] =
authorizationHeader(jwtForUser(userId))

def getUniqueUserName(name: String): String = getUniqueParty(name).toString
def getUniqueUserName(name: String): String = getUniqueParty(name).unwrap

}

Expand All @@ -72,8 +73,6 @@ class HttpServiceIntegrationTestUserManagementNoAuth

override def wsConfig: Option[WebsocketConfig] = None

import scalaz.syntax.tag._

"Json format of UserRight should be stable" in Future {
import spray.json._
val ham = getUniqueParty("ham")
Expand All @@ -100,7 +99,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth
user <- createUser(ledgerClient)(
Ref.UserId.assertFromString(getUniqueUserName("nice.user")),
initialRights = List(
CanActAs(Ref.Party.assertFromString(alice.toString))
CanActAs(Ref.Party.assertFromString(alice.unwrap))
),
)
(status, output) <- postJsonRequest(
Expand Down Expand Up @@ -128,7 +127,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth
user <- createUser(ledgerClient)(
Ref.UserId.assertFromString(getUniqueUserName("nice.user")),
initialRights = List(
CanActAs(Ref.Party.assertFromString(bob.toString))
CanActAs(Ref.Party.assertFromString(bob.unwrap))
),
)
(status, output) <- postJsonRequest(
Expand Down Expand Up @@ -156,8 +155,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth
user <- createUser(ledgerClient)(
Ref.UserId.assertFromString(getUniqueUserName("nice.user")),
initialRights = List(
CanActAs(Ref.Party.assertFromString(alice.toString)),
CanActAs(Ref.Party.assertFromString(bob.toString)),
CanActAs(Ref.Party.assertFromString(alice.unwrap)),
CanActAs(Ref.Party.assertFromString(bob.unwrap)),
),
)
(status, output) <- postJsonRequest(
Expand Down Expand Up @@ -190,7 +189,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth
assertStatus(output, StatusCodes.OK)
getResult(output).convertTo[UserDetails] shouldEqual UserDetails(
user.id,
user.primaryParty.map(_.toString),
user.primaryParty: Option[String],
)
}
} yield assertion
Expand All @@ -206,8 +205,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth
user <- createUser(ledgerClient)(
Ref.UserId.assertFromString(getUniqueUserName("nice.user")),
initialRights = List(
CanActAs(Ref.Party.assertFromString(alice.toString)),
CanActAs(Ref.Party.assertFromString(bob.toString)),
CanActAs(Ref.Party.assertFromString(alice.unwrap)),
CanActAs(Ref.Party.assertFromString(bob.unwrap)),
),
)
(status, output) <- postRequest(
Expand Down Expand Up @@ -236,8 +235,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth
user <- createUser(ledgerClient)(
Ref.UserId.assertFromString(getUniqueUserName("nice.user")),
initialRights = List(
CanActAs(Ref.Party.assertFromString(alice.toString)),
CanActAs(Ref.Party.assertFromString(bob.toString)),
CanActAs(Ref.Party.assertFromString(alice.unwrap)),
CanActAs(Ref.Party.assertFromString(bob.unwrap)),
),
)
(status, output) <- getRequest(
Expand Down Expand Up @@ -486,7 +485,7 @@ class HttpServiceIntegrationTestUserManagementNoAuth
user <- createUser(ledgerClient)(
Ref.UserId.assertFromString(getUniqueUserName("nice.user")),
initialRights = List(
CanActAs(Ref.Party.assertFromString(alice))
CanActAs(Ref.Party.assertFromString(alice.unwrap))
),
)
(status, output) <- postRequest(
Expand Down Expand Up @@ -543,8 +542,8 @@ class HttpServiceIntegrationTestUserManagementNoAuth
user <- createUser(ledgerClient)(
Ref.UserId.assertFromString(getUniqueUserName("nice.user")),
initialRights = List(
CanActAs(Ref.Party.assertFromString(alice.toString)),
CanActAs(Ref.Party.assertFromString(bob.toString)),
CanActAs(Ref.Party.assertFromString(alice.unwrap)),
CanActAs(Ref.Party.assertFromString(bob.unwrap)),
ParticipantAdmin,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,24 @@ object domain extends com.daml.fetchcontracts.domain.Aliases {
import com.daml.ledger.api.domain.{UserRight => LedgerUserRight}, com.daml.lf.data.Ref
import scalaz.syntax.traverse._
import scalaz.syntax.std.either._
import scalaz.syntax.tag._

def toLedgerUserRights(input: List[UserRight]): String \/ List[LedgerUserRight] =
input.traverse {
case ParticipantAdmin => \/.right(LedgerUserRight.ParticipantAdmin)
case CanActAs(party) =>
Ref.Party.fromString(Party.unwrap(party)).map(LedgerUserRight.CanActAs).disjunction
Ref.Party.fromString(party.unwrap).map(LedgerUserRight.CanActAs).disjunction
case CanReadAs(party) =>
Ref.Party.fromString(Party.unwrap(party)).map(LedgerUserRight.CanReadAs).disjunction
Ref.Party.fromString(party.unwrap).map(LedgerUserRight.CanReadAs).disjunction
}

def fromLedgerUserRights(input: Vector[LedgerUserRight]): List[UserRight] = input
.map[domain.UserRight] {
case LedgerUserRight.ParticipantAdmin => ParticipantAdmin
case LedgerUserRight.CanActAs(party) =>
CanActAs(Party(party.toString: String))
CanActAs(Party(party: String))
case LedgerUserRight.CanReadAs(party) =>
CanReadAs(Party(party.toString: String))
CanReadAs(Party(party: String))
}
.toList
}
Expand Down

0 comments on commit cde761f

Please sign in to comment.