Skip to content

Commit

Permalink
Make UserId properly opaque by defining it as a variant (#12476)
Browse files Browse the repository at this point in the history
* Make UserId properly opaque by defining it as a variant instead of as a record.

changelog_begin
changelog_end

* hand coded Show instance for UserId

* rename: userName --> userIdToText
  • Loading branch information
nickchapman-da authored Jan 19, 2022
1 parent 3159d60 commit ebd3827
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions compiler/damlc/tests/src/DA/Test/ScriptService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,8 @@ main =
, " u2 <- validateUserId \"user2\""
, " let user1 = User u1 None"
, " let user2 = User u2 None"
, " userName u1 === \"user1\""
, " userName u2 === \"user2\""
, " userIdToText u1 === \"user1\""
, " userIdToText u2 === \"user2\""
, " users <- listUsers"
, " users === []"
, " createUser user1 []"
Expand Down
16 changes: 9 additions & 7 deletions daml-script/daml/Daml/Script.daml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module Daml.Script
, UserNotFound(..)
, User(..)
, UserRight(..)
, userName
, userIdToText
, validateUserId
, createUser
, createUserOn
Expand Down Expand Up @@ -767,10 +767,12 @@ submitTreeMulti actAs readAs cmds =


-- | HIDE Identifier for a user in the user management service
data UserId = UserId
with
userName : Text
deriving (Eq, Ord, Show)
newtype UserId = UserId Text deriving (Eq, Ord)

instance Show UserId where show (UserId text) = "'" <> text <> "'"

userIdToText : UserId -> Text
userIdToText (UserId text) = text

-- | HIDE User as used in the user management service
data User = User
Expand Down Expand Up @@ -804,7 +806,7 @@ exception UserAlreadyExists
with
userId : UserId
where
message (userName userId)
message (userIdToText userId)

checkUserAlreadyExists : UserId -> Script (Optional ()) -> Script ()
checkUserAlreadyExists userId script = do
Expand All @@ -817,7 +819,7 @@ exception UserNotFound
with
userId : UserId
where
message (userName userId)
message (userIdToText userId)

checkUserNotFound : UserId -> Script (Optional a) -> Script a
checkUserNotFound userId script = do
Expand Down

0 comments on commit ebd3827

Please sign in to comment.