Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random nit-picks #1300

Merged
merged 4 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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