Skip to content
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
8 changes: 4 additions & 4 deletions services/brig/src/Brig/API/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ addClientWithReAuthPolicy ::
NewClient ->
ExceptT ClientError (AppT r) Client
addClientWithReAuthPolicy policy u con ip new = do
acc <- lift (wrapClient $ Data.lookupAccount u) >>= maybe (throwE (ClientUserNotFound u)) return
acc <- lift (wrapClient $ Data.lookupAccount u) >>= maybe (throwE (ClientUserNotFound u)) pure
wrapHttpClientE $ verifyCode (newClientVerificationCode new) (userId . accountUser $ acc)
loc <- maybe (return Nothing) locationOf ip
loc <- maybe (pure Nothing) locationOf ip
maxPermClients <- fromMaybe Opt.defUserMaxPermClients . Opt.setUserMaxPermClients <$> view settings
let caps :: Maybe (Set ClientCapability)
caps = updlhdev $ newClientCapabilities new
Expand All @@ -172,7 +172,7 @@ addClientWithReAuthPolicy policy u con ip new = do
for_ (userEmail usr) $
\email ->
sendNewClientEmail (userDisplayName usr) email clt (userLocale usr)
return clt
pure clt
where
clientId' = clientIdFromPrekey (unpackLastPrekey $ newClientLastKey new)

Expand Down Expand Up @@ -374,7 +374,7 @@ claimLocalMultiPrekeyBundles protectee userClients = do
getClientKeys u c = do
key <- fmap prekeyData <$> Data.claimPrekey u c
when (isNothing key) $ noPrekeys u c
return key
pure key

-- Utilities

Expand Down
20 changes: 10 additions & 10 deletions services/brig/src/Brig/API/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ createConnectionToLocalUser self conn target = do
<$> wrapClient (Data.lookupName (tUnqualified self))
let e2s = ConnectionUpdated s2o' (ucStatus <$> s2o) Nothing
mapM_ (Intra.onConnectionEvent (tUnqualified self) (Just conn)) [e2o, e2s]
return s2o'
pure s2o'

update :: UserConnection -> UserConnection -> ExceptT ConnectionError (AppT r) (ResponseForExistedCreated UserConnection)
update s2o o2s = case (ucStatus s2o, ucStatus o2s) of
(MissingLegalholdConsent, _) -> throwE $ InvalidTransition (tUnqualified self)
(_, MissingLegalholdConsent) -> throwE $ InvalidTransition (tUnqualified self)
(Accepted, Accepted) -> return $ Existed s2o
(Accepted, Blocked) -> return $ Existed s2o
(Sent, Blocked) -> return $ Existed s2o
(Accepted, Accepted) -> pure $ Existed s2o
(Accepted, Blocked) -> pure $ Existed s2o
(Sent, Blocked) -> pure $ Existed s2o
(Blocked, _) -> throwE $ InvalidTransition (tUnqualified self)
(_, Blocked) -> change s2o SentWithHistory
(_, Sent) -> accept s2o o2s
Expand Down Expand Up @@ -159,7 +159,7 @@ createConnectionToLocalUser self conn target = do
<$> Data.lookupName (tUnqualified self)
let e2s = ConnectionUpdated s2o' (Just $ ucStatus s2o) Nothing
lift $ mapM_ (Intra.onConnectionEvent (tUnqualified self) (Just conn)) [e2o, e2s]
return $ Existed s2o'
pure $ Existed s2o'

resend :: UserConnection -> UserConnection -> ExceptT ConnectionError (AppT r) (ResponseForExistedCreated UserConnection)
resend s2o o2s = do
Expand All @@ -169,7 +169,7 @@ createConnectionToLocalUser self conn target = do
logLocalConnection (tUnqualified self) (qUnqualified (ucTo s2o))
. msg (val "Resending connection request")
s2o' <- insert (Just s2o) (Just o2s)
return $ Existed s2o'
pure $ Existed s2o'

change :: UserConnection -> RelationWithHistory -> ExceptT ConnectionError (AppT r) (ResponseForExistedCreated UserConnection)
change c s = Existed <$> lift (wrapClient $ Data.updateConnection c s)
Expand All @@ -183,7 +183,7 @@ checkLegalholdPolicyConflict uid1 uid2 = do
let catchProfileNotFound =
-- Does not fit into 'ExceptT', so throw in '(AppT r)'. Anyway at the time of writing
-- this, users are guaranteed to exist when called from 'createConnectionToLocalUser'.
maybe (throwM (errorToWai @'E.UserNotFound)) return
maybe (throwM (errorToWai @'E.UserNotFound)) pure

status1 <- lift (wrapHttpClient $ getLegalHoldStatus uid1) >>= catchProfileNotFound
status2 <- lift (wrapHttpClient $ getLegalHoldStatus uid2) >>= catchProfileNotFound
Expand Down Expand Up @@ -270,14 +270,14 @@ updateConnectionToLocalUser self other newStatus conn = do
-- Cancelled -> {Blocked}
(Cancelled, _, Blocked) -> block s2o
-- no change
(old, _, new) | old == new -> return Nothing
(old, _, new) | old == new -> pure Nothing
-- invalid
_ -> throwE $ InvalidTransition (tUnqualified self)
let s2oUserConn = s2o'
lift . for_ s2oUserConn $ \c ->
let e2s = ConnectionUpdated c (Just $ ucStatus s2o) Nothing
in Intra.onConnectionEvent (tUnqualified self) conn e2s
return s2oUserConn
pure s2oUserConn
where
accept :: UserConnection -> UserConnection -> ExceptT ConnectionError (AppT r) (Maybe UserConnection)
accept s2o o2s = do
Expand Down Expand Up @@ -496,4 +496,4 @@ lookupConnections :: UserId -> Maybe UserId -> Range 1 500 Int32 -> (AppT r) Use
lookupConnections from start size = do
lusr <- qualifyLocal from
rs <- wrapClient $ Data.lookupLocalConnections lusr start size
return $! UserConnectionList (Data.resultList rs) (Data.resultHasMore rs)
pure $! UserConnectionList (Data.resultList rs) (Data.resultHasMore rs)
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/Handler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ runHandler e r h k = do
a <-
runAppT e' (runExceptT h)
`catches` brigErrorHandlers (view applog e) (unRequestId (view requestId e))
either (onError (view applog e') r k) return a
either (onError (view applog e') r k) pure a

toServantHandler :: Env -> (Handler BrigCanonicalEffects) a -> Servant.Handler a
toServantHandler env action = do
Expand Down
46 changes: 23 additions & 23 deletions services/brig/src/Brig/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ sitemap ::
Members '[CodeStore, PasswordResetStore] r =>
Routes a (Handler r) ()
sitemap = do
get "/i/status" (continue $ const $ return empty) true
head "/i/status" (continue $ const $ return empty) true
get "/i/status" (continue $ const $ pure empty) true
head "/i/status" (continue $ const $ pure empty) true

-- internal email activation (used in tests and in spar for validating emails obtained as
-- SAML user identifiers). if the validate query parameter is false or missing, only set
Expand Down Expand Up @@ -367,12 +367,12 @@ legalHoldClientRequestedH :: UserId ::: JsonRequest LegalHoldClientRequest ::: J
legalHoldClientRequestedH (targetUser ::: req ::: _) = do
clientRequest <- parseJsonBody req
lift $ API.legalHoldClientRequested targetUser clientRequest
return $ setStatus status200 empty
pure $ setStatus status200 empty

removeLegalHoldClientH :: UserId ::: JSON -> (Handler r) Response
removeLegalHoldClientH (uid ::: _) = do
lift $ API.removeLegalHoldClient uid
return $ setStatus status200 empty
pure $ setStatus status200 empty

internalListClientsH :: JSON ::: JsonRequest UserSet -> (Handler r) Response
internalListClientsH (_ ::: req) = do
Expand Down Expand Up @@ -481,7 +481,7 @@ getActivationCodeH (_ ::: emailOrPhone) = do
getActivationCode :: Either Email Phone -> (Handler r) GetActivationCodeResp
getActivationCode emailOrPhone = do
apair <- lift . wrapClient $ API.lookupActivationCode emailOrPhone
maybe (throwStd activationKeyNotFound) (return . GetActivationCodeResp) apair
maybe (throwStd activationKeyNotFound) (pure . GetActivationCodeResp) apair

newtype GetActivationCodeResp = GetActivationCodeResp (ActivationKey, ActivationCode)

Expand Down Expand Up @@ -511,19 +511,19 @@ changeAccountStatusH :: UserId ::: JsonRequest AccountStatusUpdate -> (Handler r
changeAccountStatusH (usr ::: req) = do
status <- suStatus <$> parseJsonBody req
wrapHttpClientE (API.changeSingleAccountStatus usr status) !>> accountStatusError
return empty
pure empty

getAccountStatusH :: JSON ::: UserId -> (Handler r) Response
getAccountStatusH (_ ::: usr) = do
status <- lift $ wrapClient $ API.lookupStatus usr
return $ case status of
pure $ case status of
Just s -> json $ AccountStatusResp s
Nothing -> setStatus status404 empty

getConnectionsStatusUnqualified :: ConnectionsStatusRequest -> Maybe Relation -> (Handler r) [ConnectionStatus]
getConnectionsStatusUnqualified ConnectionsStatusRequest {csrFrom, csrTo} flt = lift $ do
r <- wrapClient $ maybe (API.lookupConnectionStatus' csrFrom) (API.lookupConnectionStatus csrFrom) csrTo
return $ maybe r (filterByRelation r) flt
pure $ maybe r (filterByRelation r) flt
where
filterByRelation l rel = filter ((== rel) . csStatus) l

Expand All @@ -547,49 +547,49 @@ getConnectionsStatus (ConnectionsStatusRequestV2 froms mtos mrel) = do
revokeIdentityH :: Either Email Phone -> (Handler r) Response
revokeIdentityH emailOrPhone = do
lift $ API.revokeIdentity emailOrPhone
return $ setStatus status200 empty
pure $ setStatus status200 empty

updateConnectionInternalH :: JSON ::: JsonRequest UpdateConnectionsInternal -> (Handler r) Response
updateConnectionInternalH (_ ::: req) = do
updateConn <- parseJsonBody req
API.updateConnectionInternal updateConn !>> connError
return $ setStatus status200 empty
pure $ setStatus status200 empty

checkBlacklistH :: Either Email Phone -> (Handler r) Response
checkBlacklistH emailOrPhone = do
bl <- lift $ API.isBlacklisted emailOrPhone
return $ setStatus (bool status404 status200 bl) empty
pure $ setStatus (bool status404 status200 bl) empty

deleteFromBlacklistH :: Either Email Phone -> (Handler r) Response
deleteFromBlacklistH emailOrPhone = do
void . lift $ API.blacklistDelete emailOrPhone
return empty
pure empty

addBlacklistH :: Either Email Phone -> (Handler r) Response
addBlacklistH emailOrPhone = do
void . lift $ API.blacklistInsert emailOrPhone
return empty
pure empty

-- | Get any matching prefixes. Also try for shorter prefix matches,
-- i.e. checking for +123456 also checks for +12345, +1234, ...
getPhonePrefixesH :: PhonePrefix -> (Handler r) Response
getPhonePrefixesH prefix = do
results <- lift $ API.phonePrefixGet prefix
return $ case results of
pure $ case results of
[] -> setStatus status404 empty
_ -> json results

-- | Delete a phone prefix entry (must be an exact match)
deleteFromPhonePrefixH :: PhonePrefix -> (Handler r) Response
deleteFromPhonePrefixH prefix = do
void . lift $ API.phonePrefixDelete prefix
return empty
pure empty

addPhonePrefixH :: JSON ::: JsonRequest ExcludedPrefix -> (Handler r) Response
addPhonePrefixH (_ ::: req) = do
prefix :: ExcludedPrefix <- parseJsonBody req
void . lift $ API.phonePrefixInsert prefix
return empty
pure empty

updateSSOIdH :: UserId ::: JSON ::: JsonRequest UserSSOId -> (Handler r) Response
updateSSOIdH (uid ::: _ ::: req) = do
Expand All @@ -598,23 +598,23 @@ updateSSOIdH (uid ::: _ ::: req) = do
if success
then do
lift $ wrapHttpClient $ Intra.onUserEvent uid Nothing (UserUpdated ((emptyUserUpdatedData uid) {eupSSOId = Just ssoid}))
return empty
else return . setStatus status404 $ plain "User does not exist or has no team."
pure empty
else pure . setStatus status404 $ plain "User does not exist or has no team."

deleteSSOIdH :: UserId ::: JSON -> (Handler r) Response
deleteSSOIdH (uid ::: _) = do
success <- lift $ wrapClient $ Data.updateSSOId uid Nothing
if success
then do
lift $ wrapHttpClient $ Intra.onUserEvent uid Nothing (UserUpdated ((emptyUserUpdatedData uid) {eupSSOIdRemoved = True}))
return empty
else return . setStatus status404 $ plain "User does not exist or has no team."
pure empty
else pure . setStatus status404 $ plain "User does not exist or has no team."

updateManagedByH :: UserId ::: JSON ::: JsonRequest ManagedByUpdate -> (Handler r) Response
updateManagedByH (uid ::: _ ::: req) = do
ManagedByUpdate managedBy <- parseJsonBody req
lift $ wrapClient $ Data.updateManagedBy uid managedBy
return empty
pure empty

updateRichInfoH :: UserId ::: JSON ::: JsonRequest RichInfoUpdate -> (Handler r) Response
updateRichInfoH (uid ::: _ ::: req) = do
Expand Down Expand Up @@ -677,9 +677,9 @@ checkHandleInternalH =
getContactListH :: JSON ::: UserId -> (Handler r) Response
getContactListH (_ ::: uid) = do
contacts <- lift . wrapClient $ API.lookupContactList uid
return $ json $ UserIds contacts
pure $ json $ UserIds contacts

-- Utilities

ifNothing :: Utilities.Error -> Maybe a -> (Handler r) a
ifNothing e = maybe (throwStd e) return
ifNothing e = maybe (throwStd e) pure
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/MLS/KeyPackages/Validation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ checkRequiredExtensions re =
<*> maybe (Left "Missing capability extension") (pure . Identity) (reCapabilities re)

findExtensions :: [Extension] -> Either Text (RequiredExtensions Identity)
findExtensions = (checkRequiredExtensions =<<) . getAp . foldMap findExtension
findExtensions = checkRequiredExtensions <=< (getAp . foldMap findExtension)

findExtension :: Extension -> Ap (Either Text) (RequiredExtensions Maybe)
findExtension ext = (Ap (decodeExtension ext) >>=) . foldMap $ \case
Expand Down
20 changes: 10 additions & 10 deletions services/brig/src/Brig/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ listPropertyKeys u = lift $ wrapClient (API.lookupPropertyKeys u)
listPropertyKeysAndValues :: UserId -> Handler r Public.PropertyKeysAndValues
listPropertyKeysAndValues u = do
keysAndVals <- fmap Map.fromList . lift $ wrapClient (API.lookupPropertyKeysAndValues u)
fmap Public.PropertyKeysAndValues $ traverse parseStoredPropertyValue keysAndVals
Public.PropertyKeysAndValues <$> traverse parseStoredPropertyValue keysAndVals

getPrekeyUnqualifiedH :: UserId -> UserId -> ClientId -> (Handler r) Public.ClientPrekey
getPrekeyUnqualifiedH zusr user client = do
Expand Down Expand Up @@ -689,7 +689,7 @@ createUser (Public.NewUserPublic new) = lift . runExceptT $ do
-- NOTE: Welcome e-mails for the team creator are not dealt by brig anymore
sendWelcomeEmail e (CreateUserTeam t n) newUser l = case newUser of
Public.NewTeamCreator _ ->
return ()
pure ()
Public.NewTeamMember _ ->
Team.sendMemberWelcomeMail e t n l
Public.NewTeamMemberSSO _ ->
Expand Down Expand Up @@ -798,7 +798,7 @@ checkHandlesH (_ ::: _ ::: req) = do
Public.CheckHandles hs num <- parseJsonBody req
let handles = mapMaybe parseHandle (fromRange hs)
free <- lift . wrapClient $ API.checkHandles handles (fromRange num)
return $ json (free :: [Handle])
pure $ json (free :: [Handle])

-- | This endpoint returns UserHandleInfo instead of UserProfile for backwards
-- compatibility, whereas the corresponding qualified endpoint (implemented by
Expand Down Expand Up @@ -841,7 +841,7 @@ completePasswordResetH ::
completePasswordResetH (_ ::: req) = do
Public.CompletePasswordReset {..} <- parseJsonBody req
API.completePasswordReset cpwrIdent cpwrCode cpwrPassword !>> pwResetError
return empty
pure empty

sendActivationCodeH :: JsonRequest Public.SendActivationCode -> (Handler r) Response
sendActivationCodeH req =
Expand Down Expand Up @@ -891,7 +891,7 @@ updateConnection self conn other update = do
let newStatus = Public.cuStatus update
lself <- qualifyLocal self
mc <- API.updateConnection lself other newStatus (Just conn) !>> connError
return $ maybe Public.Unchanged Public.Updated mc
pure $ maybe Public.Unchanged Public.Updated mc

listLocalConnections :: UserId -> Maybe UserId -> Maybe (Range 1 500 Int32) -> (Handler r) Public.UserConnectionList
listLocalConnections uid start msize = do
Expand Down Expand Up @@ -962,7 +962,7 @@ verifyDeleteUserH :: JsonRequest Public.VerifyDeleteUser ::: JSON -> (Handler r)
verifyDeleteUserH (r ::: _) = do
body <- parseJsonBody r
API.verifyDeleteUser body !>> deleteUserError
return (setStatus status200 empty)
pure (setStatus status200 empty)

updateUserEmail :: UserId -> UserId -> Public.EmailUpdate -> (Handler r) ()
updateUserEmail zuserId emailOwnerId (Public.EmailUpdate email) = do
Expand Down Expand Up @@ -1015,10 +1015,10 @@ activate :: Public.Activate -> (Handler r) ActivationRespWithStatus
activate (Public.Activate tgt code dryrun)
| dryrun = do
wrapClientE (API.preverify tgt code) !>> actError
return ActivationRespDryRun
pure ActivationRespDryRun
| otherwise = do
result <- API.activate tgt code Nothing !>> actError
return $ case result of
pure $ case result of
ActivationSuccess ident x -> respond ident x
ActivationPass -> ActivationRespPass
where
Expand Down Expand Up @@ -1088,9 +1088,9 @@ deprecatedCompletePasswordResetH (_ ::: k ::: req) = do
(Public.pwrCode pwr)
(Public.pwrPassword pwr)
!>> pwResetError
return empty
pure empty

-- Utilities

ifNothing :: Utilities.Error -> Maybe a -> (Handler r) a
ifNothing e = maybe (throwStd e) return
ifNothing e = maybe (throwStd e) pure
Loading