Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove deprecated field `profilePict` from UserProfile.
Comment thread
VeryMilkyJoe marked this conversation as resolved.
16 changes: 16 additions & 0 deletions integration/test/Test/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,19 @@ testSuspendNonExistingUser = do
let quid = object ["domain" .= dom, "id" .= uid]
I.setAccountStatus quid "suspended" >>= assertStatus 404
getUser existingUser quid >>= assertStatus 404

testUserProfileSchemaContainsPicture17 :: (HasCallStack) => App ()
testUserProfileSchemaContainsPicture17 = do
qself <- randomUser OwnDomain def
quser <- randomUser OwnDomain def
withAPIVersion 17 $ getUser qself quser `bindResponse` \resp -> do
resp.status `shouldMatchInt` 200
resp.json %. "picture" `shouldMatch` (Just ())
Comment thread
fisx marked this conversation as resolved.

testUserProfileSchemaContainsPicture :: (HasCallStack) => App ()
testUserProfileSchemaContainsPicture = do
qself <- randomUser OwnDomain def
quser <- randomUser OwnDomain def
getUser qself quser `bindResponse` \resp -> do
resp.status `shouldMatchInt` 200
resp.json `assertFieldMissing` "picture"
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import Wire.API.Federation.Version
import Wire.API.MLS.CipherSuite
import Wire.API.MLS.KeyPackage
import Wire.API.Routes.SpecialiseToVersion
import Wire.API.Routes.Version qualified as V
import Wire.API.Routes.Versioned qualified as V
import Wire.API.User
import Wire.API.User.Client
import Wire.API.User.Client.Prekey (ClientPrekey, PrekeyBundle)
Expand Down Expand Up @@ -78,8 +80,10 @@ instance ToSchema SearchResponse
-- | For conventions see /docs/developer/federation-api-conventions.md
type BrigApi =
FedEndpoint "api-version" () VersionInfo
:<|> FedEndpoint "get-user-by-handle" Handle (Maybe UserProfile)
:<|> FedEndpoint "get-users-by-ids" [UserId] [UserProfile]
:<|> FedEndpointWithMods '[Until V5] (Versioned 'V4 "get-user-by-handle") Handle (Maybe (V.Versioned V.V18 UserProfile))
:<|> FedEndpointWithMods '[From V5] "get-user-by-handle" Handle (Maybe (V.Versioned V.V19 UserProfile))
:<|> FedEndpointWithMods '[Until V5] (Versioned 'V4 "get-users-by-ids") [UserId] [V.Versioned V.V18 UserProfile]
:<|> FedEndpointWithMods '[From V5] "get-users-by-ids" [UserId] [V.Versioned V.V19 UserProfile]
:<|> FedEndpoint "claim-prekey" (UserId, ClientId) (Maybe ClientPrekey)
:<|> FedEndpoint "claim-prekey-bundle" UserId PrekeyBundle
:<|> FedEndpoint "claim-multi-prekey-bundle" UserClients UserClientPrekeyMap
Expand Down
7 changes: 5 additions & 2 deletions libs/wire-api-federation/src/Wire/API/Federation/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Wire.API.Federation.Version
V2Sym0,
V3Sym0,
V4Sym0,
V5Sym0,
intToVersion,
versionInt,
versionText,
Expand Down Expand Up @@ -56,7 +57,7 @@ import Imports
import Servant.API (ToHttpApiData (..))
import Wire.API.MLS.Group.Serialisation

data Version = V0 | V1 | V2 | V3 | V4
data Version = V0 | V1 | V2 | V3 | V4 | V5
deriving stock (Eq, Ord, Bounded, Enum, Show, Generic)
deriving (FromJSON, ToJSON) via (Schema Version)

Expand All @@ -70,6 +71,7 @@ versionInt V1 = 1
versionInt V2 = 2
versionInt V3 = 3
versionInt V4 = 4
versionInt V5 = 5

versionText :: Version -> Text
versionText = ("v" <>) . Text.pack . show . versionInt
Expand All @@ -90,7 +92,8 @@ instance ToSchema Version where
element 1 V1,
element 2 V2,
element 3 V3,
element 4 V4
element 4 V4,
element 5 V5
]

supportedVersions :: Set Version
Expand Down
89 changes: 65 additions & 24 deletions libs/wire-api/src/Wire/API/Routes/Public/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ instance ServiceAPI BrigAPITag v where

type MaxUsersForListClientsBulk = 500

type GetUserVerb =
type GetUserVerb v =
MultiVerb
'GET
'[JSON]
'[ ErrorResponse 'UserNotFound,
Respond 200 "User found" UserProfile
VersionedRespond (ToVersion v) 200 "User found" UserProfile
]
(Maybe UserProfile)
(Maybe (Versioned (ToVersion v) UserProfile))

type CaptureUserId name = Capture' '[Description "User Id"] name UserId

Expand Down Expand Up @@ -166,15 +166,25 @@ type UserAPI =
:> ZLocalUser
:> "users"
:> CaptureUserId "uid"
:> GetUserVerb
:> GetUserVerb (Until 'V19)
)
:<|> Named
"get-user-qualified@v18"
( Summary "Get a user by Domain and UserId"
:> Until 'V19
:> ZLocalUser
:> "users"
:> QualifiedCaptureUserId "uid"
:> GetUserVerb (Until 'V19)
)
:<|> Named
"get-user-qualified"
( Summary "Get a user by Domain and UserId"
:> From 'V19
:> ZLocalUser
:> "users"
:> QualifiedCaptureUserId "uid"
:> GetUserVerb
:> GetUserVerb (From 'V19)
)
:<|> Named
"update-user-email"
Expand Down Expand Up @@ -215,32 +225,43 @@ type UserAPI =
'GET
'[JSON]
'[ ErrorResponse 'HandleNotFound,
Respond 200 "User found" UserProfile
VersionedRespond (ToVersion (Until 'V19)) 200 "User found" UserProfile
]
(Maybe UserProfile)
(Maybe (Versioned (ToVersion (Until 'V19)) UserProfile))
)
:<|> Named
"list-users-by-unqualified-ids-or-handles"
( Summary "List users (deprecated)"
:> Until 'V2
:> Description "The 'ids' and 'handles' parameters are mutually exclusive."
:> ZUser
:> "users"
:> QueryParam' [Optional, Strict, Description "User IDs of users to fetch"] "ids" (CommaSeparatedList UserId)
:> QueryParam' [Optional, Strict, Description "Handles of users to fetch, min 1 and max 4 (the check for handles is rather expensive)"] "handles" (Range 1 4 (CommaSeparatedList Handle))
:> Get '[JSON] [UserProfile]
)
"list-users-by-unqualified-ids-or-handles"
( Summary "List users (deprecated)"
:> Until 'V2
:> Description "The 'ids' and 'handles' parameters are mutually exclusive."
:> ZUser
:> "users"
:> QueryParam' [Optional, Strict, Description "User IDs of users to fetch"] "ids" (CommaSeparatedList UserId)
:> QueryParam' [Optional, Strict, Description "Handles of users to fetch, min 1 and max 4 (the check for handles is rather expensive)"] "handles" (Range 1 4 (CommaSeparatedList Handle))
:> Get '[JSON] [Versioned (ToVersion (Until 'V19)) UserProfile]
)
:<|> Named
"list-users-by-ids-or-handles"
"list-users-by-ids-or-handles@v18"
( Summary "List users"
:> Description "The 'qualified_ids' and 'qualified_handles' parameters are mutually exclusive."
:> ZUser
:> From 'V4
:> "list-users"
:> QueryParam' [Optional, Strict, Description "Include whether each local user can currently be contacted"] "include-contact-status" Bool
:> ReqBody '[JSON] ListUsersQuery
:> Post '[JSON] ListUsersById
:> Post '[JSON] (ListUsersById (ToVersion (Until 'V19)))
)
:<|> Named
"list-users-by-ids-or-handles"
( Summary "List users"
:> Description "The 'qualified_ids' and 'qualified_handles' parameters are mutually exclusive."
:> ZUser
:> From 'V4
:> "list-users"
:> QueryParam' [Optional, Strict, Description "Include whether each local user can currently be contacted"] "include-contact-status" Bool
:> ReqBody '[JSON] ListUsersQuery
:> Post '[JSON] (ListUsersById (ToVersion (From 'V19)))
)
:<|> Named
"list-users-by-ids-or-handles@V3"
( Summary "List users"
Expand All @@ -249,7 +270,7 @@ type UserAPI =
:> Until 'V4
:> "list-users"
:> ReqBody '[JSON] ListUsersQuery
:> Post '[JSON] [UserProfile]
:> Post '[JSON] [Versioned (ToVersion (Until 'V19)) UserProfile]
)
:<|> Named
"send-verification-code"
Expand Down Expand Up @@ -2120,15 +2141,25 @@ type SystemSettingsAPI =

type AppsAPI =
Named
"create-app"
"create-app@v18"
( Summary "Create a new app"
:> From 'V12
:> ZLocalUser
:> "teams"
:> Capture "tid" TeamId
:> "apps"
:> ReqBody '[JSON] NewApp
:> Post '[JSON] CreatedApp
:> Post '[JSON] (CreatedApp (ToVersion (Until 'V19)))
)
:<|> Named "create-app"
( Summary "Create a new app"
:> From 'V12
:> ZLocalUser
:> "teams"
:> Capture "tid" TeamId
:> "apps"
:> ReqBody '[JSON] NewApp
:> Post '[JSON] (CreatedApp (ToVersion (From 'V19)))
)
:<|> Named
"get-app"
Expand All @@ -2140,7 +2171,17 @@ type AppsAPI =
:> Capture "tid" TeamId
:> "apps"
:> Capture "uid" UserId
:> Get '[JSON] UserProfile
:> Get '[JSON] (Versioned (ToVersion (Until 'V19)) UserProfile)
)
:<|> Named
"get-apps@v18"
( Summary "Get all apps owned by the given team (not including collaborators)"
:> From 'V15
:> ZLocalUser
:> "teams"
:> Capture "tid" TeamId
:> "apps"
:> Get '[JSON] [Versioned (ToVersion (Until 'V19)) UserProfile]
)
:<|> Named
"get-apps"
Expand All @@ -2150,7 +2191,7 @@ type AppsAPI =
:> "teams"
:> Capture "tid" TeamId
:> "apps"
:> Get '[JSON] [UserProfile]
:> Get '[JSON] [Versioned (ToVersion (From 'V19)) UserProfile]
)
:<|> Named
"put-app"
Expand Down
3 changes: 2 additions & 1 deletion libs/wire-api/src/Wire/API/Routes/Public/Brig/Bot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ type BotAPI =
:<|> Named
"bot-get-self"
( Summary "Get self"
:> Until V19
:> CanThrow 'UserNotFound
:> CanThrow 'AccessDenied
:> ZBot
:> "bot"
:> "self"
:> Get '[JSON] UserProfile
:> Get '[JSON] (Versioned (ToVersion (Until 'V19)) UserProfile)
)
:<|> Named
"bot-delete-self"
Expand Down
31 changes: 31 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ module Wire.API.Routes.Version
-- * Servant combinators
Until,
From,
Prev,
ToVersion,

-- * Versioned schema-profunctor things.
versionedObject,
Expand Down Expand Up @@ -88,6 +90,7 @@ import Data.Set qualified as Set
import Data.Singletons.Base.TH
import Data.Text qualified as Text
import Data.Text.Encoding as Text
import GHC.TypeError
import Imports hiding ((\\))
import Servant
import Wire.API.Routes.Named hiding (unnamed)
Expand All @@ -108,6 +111,34 @@ data Version = V0 | V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 | V12
deriving (FromJSON, ToJSON) via (Schema Version)
deriving (Arbitrary) via (GenericUniform Version)

-- Type family to be used in endpoints to reflect usage of Until and From
-- and is used to give information to `toSchema` instances
type family ToVersion r where
ToVersion (Until (v :: Version)) = Prev v
ToVersion (From (v :: Version)) = v

type family Prev (v :: Version) where
Prev V0 = TypeError (GHC.TypeError.Text "There is no version before V0.")
Prev V1 = V0
Prev V2 = V1
Prev V3 = V2
Prev V4 = V3
Prev V5 = V4
Prev V6 = V5
Prev V7 = V6
Prev V8 = V7
Prev V9 = V8
Prev V10 = V9
Prev V11 = V10
Prev V12 = V11
Prev V13 = V12
Prev V14 = V13
Prev V15 = V14
Prev V16 = V15
Prev V17 = V16
Prev V18 = V17
Prev V19 = V18

instance RenderableSymbol V1 where renderSymbol = "V1"

instance RenderableSymbol V2 where renderSymbol = "V2"
Expand Down
2 changes: 1 addition & 1 deletion libs/wire-api/src/Wire/API/Routes/Versioned.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ instance
responseUnrender c = fmap unVersioned . responseUnrender @cs @(Respond s desc (Versioned v a)) c

instance
(KnownSymbol desc, S.ToSchema a, SingI v, ToSchema (Versioned v a), Typeable v) =>
(KnownSymbol desc, S.ToSchema (Versioned v a)) =>
IsSwaggerResponse (VersionedRespond (v :: Version) s desc a)
where
responseSwagger = simpleResponseSwagger @(Versioned v a) @'[JSON] @desc
Expand Down
Loading