Skip to content

Commit

Permalink
Random nit-picks (#1300)
Browse files Browse the repository at this point in the history
* Make error message more clear.

* Fix garbled english.

* Don't use one-letter identifiers; don't use pointless abstractions.

* ormolu.
  • Loading branch information
fisx authored Dec 29, 2020
1 parent d9acac6 commit e5bfa9e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ changeLocaleH (u ::: conn ::: req) = do
lift $ API.changeLocale u conn l
return empty

-- | (zusr are is ignored by this handler, ie. checking handles is allowed as long as you have
-- | (zusr is ignored by this handler, ie. checking handles is allowed as long as you have
-- *any* account.)
checkHandleH :: UserId ::: Text -> Handler Response
checkHandleH (_uid ::: hndl) = do
Expand Down
42 changes: 19 additions & 23 deletions services/brig/src/Brig/User/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,25 @@ import Imports

-- | Claim a new handle for an existing 'User'.
claimHandle :: UserId -> Maybe Handle -> Handle -> AppIO Bool
claimHandle uid oldHandle newHandle = isJust <$> claimHandleWith (User.updateHandle) uid oldHandle newHandle

-- | Claim a handle for an invitation or a user. Invitations can be referenced by the coerced
-- 'UserId'.
claimHandleWith :: (UserId -> Handle -> AppIO a) -> UserId -> Maybe Handle -> Handle -> AppIO (Maybe a)
claimHandleWith updOperation uid oldHandle h = do
owner <- lookupHandle h
case owner of
Just uid' | uid /= uid' -> return Nothing
_ -> do
env <- ask
let key = "@" <> fromHandle h
withClaim uid key (30 # Minute) $
runAppT env $
do
-- Record ownership
retry x5 $ write handleInsert (params Quorum (h, uid))
-- Update profile
result <- updOperation uid h
-- Free old handle (if it changed)
for_ (mfilter (/= h) oldHandle) $
freeHandle uid
return result
claimHandle uid oldHandle newHandle =
isJust <$> do
owner <- lookupHandle newHandle
case owner of
Just uid' | uid /= uid' -> return Nothing
_ -> do
env <- ask
let key = "@" <> fromHandle newHandle
withClaim uid key (30 # Minute) $
runAppT env $
do
-- Record ownership
retry x5 $ write handleInsert (params Quorum (newHandle, uid))
-- Update profile
result <- User.updateHandle uid newHandle
-- Free old handle (if it changed)
for_ (mfilter (/= newHandle) oldHandle) $
freeHandle uid
return result

-- | Free a 'Handle', making it available to be claimed again.
freeHandle :: UserId -> Handle -> AppIO ()
Expand Down
2 changes: 1 addition & 1 deletion services/spar/src/Spar/Scim/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ assertHandleNotUsedElsewhere :: UserId -> Handle -> Scim.ScimHandler Spar ()
assertHandleNotUsedElsewhere uid hndl = do
musr <- lift $ Brig.getBrigUser Brig.WithPendingInvitations uid
unless ((userHandle =<< musr) == Just hndl) $
assertHandleUnused' "userName does not match UserId" hndl
assertHandleUnused' "userName already in use by another wire user" hndl

-- | Helper function that translates a given brig user into a 'Scim.StoredUser', with some
-- effects like updating the 'ManagedBy' field in brig and storing creation and update time
Expand Down

0 comments on commit e5bfa9e

Please sign in to comment.