Skip to content

Commit

Permalink
Expose internal EJPD request end-point to backoffice. (#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx authored Oct 1, 2021
1 parent 3e2b26e commit 48ac1da
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/5-internal/stern-ejpd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Expose wire.com internal EJDP process to backoffice/stern.
15 changes: 15 additions & 0 deletions tools/stern/src/Stern/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ routes = do
Doc.response 403 "Only teams with 1 user can be deleted" (Doc.model Doc.errorModel)
Doc.response 404 "Binding team mismatch" (Doc.model Doc.errorModel)

get "/ejpd-info" (continue ejpdInfoByHandles) $
param "handles"
.&. def False (query "include_contacts")
document "GET" "ejpd-info" $ do
Doc.summary "internal wire.com process: https://wearezeta.atlassian.net/wiki/spaces/~463749889/pages/256738296/EJPD+official+requests+process"
Doc.parameter Doc.Query "handles" Doc.string' $
Doc.description "Handles of the user, separated by comments"
Doc.parameter Doc.Query "include_contacts" Doc.bool' $ do
Doc.description "If 'true', this gives you more more exhaustive information about this user (including social network)"
Doc.optional
Doc.response 200 "Required information about the listed users (where found)" Doc.end

head "/users/blacklist" (continue isUserKeyBlacklisted) $
(query "email" ||| phoneParam)
document "HEAD" "checkBlacklistStatus" $ do
Expand Down Expand Up @@ -488,6 +500,9 @@ usersByIds = liftM json . Intra.getUserProfiles . Left . fromList
usersByHandles :: List Handle -> Handler Response
usersByHandles = liftM json . Intra.getUserProfiles . Right . fromList

ejpdInfoByHandles :: (List Handle ::: Bool) -> Handler Response
ejpdInfoByHandles (handles ::: includeContacts) = json <$> Intra.getEjpdInfo (fromList handles) includeContacts

userConnections :: UserId -> Handler Response
userConnections uid = do
conns <- Intra.getUserConnections uid
Expand Down
22 changes: 22 additions & 0 deletions tools/stern/src/Stern/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Stern.Intra
getUsersConnections,
getUserProfiles,
getUserProfilesByIdentity,
getEjpdInfo,
getUserProperties,
getInvoiceUrl,
revokeIdentity,
Expand Down Expand Up @@ -77,6 +78,7 @@ import Data.Id
import Data.Int
import Data.List.Split (chunksOf)
import Data.Qualified (qUnqualified)
import Data.String.Conversions (cs)
import Data.Text (strip)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Text.Lazy (pack)
Expand All @@ -94,6 +96,7 @@ import Stern.Types
import System.Logger.Class hiding (Error, name, (.=))
import qualified System.Logger.Class as Log
import UnliftIO.Exception hiding (Handler)
import qualified Wire.API.Routes.Internal.Brig.EJPD as EJPD
import qualified Wire.API.Team.Feature as Public

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -226,6 +229,25 @@ getUserProfilesByIdentity emailOrPhone = do
)
parseResponse (mkError status502 "bad-upstream") r

getEjpdInfo :: [Handle] -> Bool -> Handler EJPD.EJPDResponseBody
getEjpdInfo handles includeContacts = do
info $ msg "Getting ejpd info on users by handle"
b <- view brig
let bdy :: Value
bdy = object ["ejpd_request" .= ((cs @_ @Text . toByteString') <$> handles)]
r <-
catchRpcErrors $
rpc'
"brig"
b
( method POST
. path "/i/ejpd-request"
. Bilge.json bdy
. (if includeContacts then queryItem "include_contacts" "true" else id)
. expect2xx
)
parseResponse (mkError status502 "bad-upstream") r

getContacts :: UserId -> Text -> Int32 -> Handler (SearchResult Contact)
getContacts u q s = do
info $ msg "Getting user contacts"
Expand Down

0 comments on commit 48ac1da

Please sign in to comment.