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

Remove autoconnect functionality; deprecate end-point. #1005

Merged
merged 5 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/reference/user/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Members of the same team are always considered connected, see [Connections betwe

Internally, connection status is a _directed_ edge from one user to another that is attributed with a relation state and some meta information. If a user has a connection to another user, it can be in one of the six [connection states](#RefConnectionStates).

TODO describe autoconnection and onboarding.

## Connection states {#RefConnectionStates}

### Sent {#RefConnectionSent}
Expand Down
1 change: 0 additions & 1 deletion libs/brig-types/src/Brig/Types.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Brig.Types (module M) where

import Brig.Types.Activation as M
import Brig.Types.AddressBook as M
import Brig.Types.Client as M
import Brig.Types.Connection as M
import Brig.Types.Properties as M
Expand Down
109 changes: 0 additions & 109 deletions libs/brig-types/src/Brig/Types/AddressBook.hs

This file was deleted.

11 changes: 0 additions & 11 deletions libs/brig-types/src/Brig/Types/Swagger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ brigModels =
addressBook,
card,
match,
onboardingMatches,
-- Search
searchResult,
searchContact,
Expand Down Expand Up @@ -834,16 +833,6 @@ match = defineModel "Match" $ do
property "cards" (array string') $
description "List of card ids for this match."

onboardingMatches :: Model
onboardingMatches = defineModel "onboardingMatches" $ do
description "Result of the address book matching"
property "results" (array (ref match)) $
description "List of matches."
property "auto-connects" (array (ref match)) $
description
"List of user IDs matched. It's a bit redudant given 'results' \
\but it is here for reasons of backwards compatibility."

--------------------------------------------------------------------------------
-- Search

Expand Down
52 changes: 30 additions & 22 deletions services/brig/src/Brig/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -810,15 +810,16 @@ sitemap o = do
Doc.notes "DEPRECATED: Use 'POST /password-reset/complete'."
---

post "/onboarding/v3" (continue onboardingH) $
post "/onboarding/v3" (continue deprecatedOnboardingH) $
accept "application" "json"
.&. header "Z-User"
.&. jsonRequest @AddressBook
.&. jsonRequest @Value
document "POST" "onboardingV3" $ do
Doc.summary "Upload contacts and invoke matching. Returns the list of Matches"
Doc.body (Doc.ref Doc.addressBook) $ Doc.description "Address book"
Doc.returns (Doc.ref Doc.onboardingMatches)
Doc.response 200 "Matches" Doc.end
Doc.deprecated
Doc.summary "Upload contacts and invoke matching."
Doc.notes
"DEPRECATED: the feature has been turned off, the end-point does \
\nothing and always returns '{\"results\":[],\"auto-connects\":[]}'."
-----

Provider.routes
Expand Down Expand Up @@ -1347,17 +1348,6 @@ sendActivationCode SendActivationCode {..} = do
changeSelfEmailH :: UserId ::: ConnId ::: JsonRequest EmailUpdate -> Handler Response
changeSelfEmailH (u ::: _ ::: req) = changeEmail u req True

-- Deprecated and to be removed after new versions of brig and galley are
-- deployed. Reason for deprecation: it returns N^2 things (which is not
-- needed), it doesn't scale, and it accepts everything in URL parameters,
-- which doesn't work when the list of users is long.
deprecatedGetConnectionsStatusH :: List UserId ::: Maybe Relation -> Handler Response
deprecatedGetConnectionsStatusH (users ::: flt) = do
r <- lift $ API.lookupConnectionStatus (fromList users) (fromList users)
return . json $ maybe r (filterByRelation r) flt
where
filterByRelation l rel = filter ((== rel) . csStatus) l

getConnectionsStatusH ::
JSON ::: JsonRequest ConnectionsStatusRequest ::: Maybe Relation ->
Handler Response
Expand Down Expand Up @@ -1511,11 +1501,6 @@ verifyDeleteUserH (r ::: _) = do
API.verifyDeleteUser body !>> deleteUserError
return (setStatus status200 empty)

onboardingH :: JSON ::: UserId ::: JsonRequest AddressBook -> Handler Response
onboardingH (_ ::: uid ::: r) = do
ab <- parseJsonBody r
json <$> API.onboarding uid ab !>> connError

getContactListH :: JSON ::: UserId -> Handler Response
getContactListH (_ ::: uid) = do
contacts <- lift $ API.lookupContactList uid
Expand Down Expand Up @@ -1559,6 +1544,29 @@ respFromActivationRespWithStatus = \case

-- Deprecated

-- Deprecated and to be removed after new versions of brig and galley are
-- deployed. Reason for deprecation: it returns N^2 things (which is not
-- needed), it doesn't scale, and it accepts everything in URL parameters,
-- which doesn't work when the list of users is long.
deprecatedGetConnectionsStatusH :: List UserId ::: Maybe Relation -> Handler Response
deprecatedGetConnectionsStatusH (users ::: flt) = do
r <- lift $ API.lookupConnectionStatus (fromList users) (fromList users)
return . json $ maybe r (filterByRelation r) flt
where
filterByRelation l rel = filter ((== rel) . csStatus) l

deprecatedOnboardingH :: JSON ::: UserId ::: JsonRequest Value -> Handler Response
deprecatedOnboardingH (_ ::: _ ::: _) = pure $ json DeprecatedMatchingResult

data DeprecatedMatchingResult = DeprecatedMatchingResult

instance ToJSON DeprecatedMatchingResult where
toJSON DeprecatedMatchingResult =
object
[ "results" .= ([] :: [()]),
"auto-connects" .= ([] :: [()])
]

deprecatedCompletePasswordResetH :: JSON ::: PasswordResetKey ::: JsonRequest PasswordReset -> Handler Response
deprecatedCompletePasswordResetH (_ ::: k ::: req) = do
pwr <- parseJsonBody req
Expand Down
41 changes: 0 additions & 41 deletions services/brig/src/Brig/API/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,23 @@ module Brig.API.Connection
Data.lookupConnection,
Data.lookupConnectionStatus,
Data.lookupContactList,

-- * Onboarding
onboarding,
)
where

import Brig.API.Types
import Brig.App
import qualified Brig.Data.Connection as Data
import qualified Brig.Data.User as Data
import qualified Brig.Data.UserKey as Data
import qualified Brig.IO.Intra as Intra
import Brig.Options (setUserMaxConnections)
import Brig.Types
import Brig.Types.Intra
import Brig.User.Event
import qualified Brig.User.Event.Log as Log
import Control.Concurrent.Async (mapConcurrently)
import Control.Error
import Control.Lens ((^.), view)
import Data.Id
import Data.List.Split (chunksOf)
import Data.Range
import Data.Set (fromList)
import qualified Data.Set as Set
import Galley.Types (ConvType (..), cnvType)
import qualified Galley.Types.Teams as Team
Expand Down Expand Up @@ -285,40 +278,6 @@ lookupConnections from start size = do
rs <- Data.lookupConnections from start size
return $! UserConnectionList (Data.resultList rs) (Data.resultHasMore rs)

onboarding :: UserId -> AddressBook -> ExceptT ConnectionError AppIO MatchingResult
onboarding uid ab = do
-- The choice of 25 is arbitrary and is here only to avoid having a user
-- auto-connect to too many users; thus the upper limit
ms <- lift $ collectMatches 25 [] (chunksOf 25 (abCards ab))
autos <- autoConnect uid (fromList $ map fst ms) Nothing
let connected = map ucTo $ filter ((== uid) . ucFrom) autos
return $ MatchingResult (toMatches connected ms) connected
where
collectMatches :: Int -> [(UserId, Maybe CardId)] -> [[Card]] -> AppIO [(UserId, Maybe CardId)]
collectMatches 0 acc _ = return acc
collectMatches _ acc [] = return acc
collectMatches n acc cards = do
-- Make 4 parallel requests, each will have at most 25 keys to look up
let (cur, rest) = splitAt 4 cards
e <- ask
ms <-
take n <$> filter ((/= uid) . fst) . join
<$> liftIO (mapConcurrently (runAppT e . lookupHashes) cur)
collectMatches (n - length ms) (acc ++ ms) rest
lookupHashes :: [Card] -> AppIO [(UserId, Maybe CardId)]
lookupHashes xs =
concatMap findCards
<$> Data.lookupPhoneHashes (map abEntrySha256 (concatMap cEntries xs))
where
findCards :: (ByteString, UserId) -> [(UserId, Maybe CardId)]
findCards (h, u) =
map ((u,) . cCardId) $
filter ((h `elem`) . (map abEntrySha256 . cEntries)) xs
toMatches :: [UserId] -> [(UserId, Maybe CardId)] -> [Match]
toMatches uids =
map (\(u, c) -> Match u c (maybeToList c))
. filter ((`elem` uids) . fst)

-- Helpers

checkLimit :: UserId -> ExceptT ConnectionError AppIO ()
Expand Down
2 changes: 0 additions & 2 deletions services/brig/test/integration/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import qualified API.User.Auth
import qualified API.User.Client
import qualified API.User.Connection
import qualified API.User.Handles
import qualified API.User.Onboarding
import qualified API.User.PasswordReset
import qualified API.User.Property
import qualified API.User.RichInfo
Expand Down Expand Up @@ -33,7 +32,6 @@ tests conf p b c ch g n aws = do
API.User.Auth.tests conf p z b g n,
API.User.Connection.tests cl at conf p b c g,
API.User.Handles.tests cl at conf p b c g,
API.User.Onboarding.tests cl at conf p b c g,
API.User.PasswordReset.tests cl at conf p b c g,
API.User.Property.tests cl at conf p b c g,
API.User.RichInfo.tests cl at conf p b c g
Expand Down
67 changes: 0 additions & 67 deletions services/brig/test/integration/API/User/Onboarding.hs

This file was deleted.