Skip to content
Draft
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 @@
Distribution state for collaborators.
11 changes: 11 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Public/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ type UserAPI =
:> ReqBody '[JSON] EmailUpdate
:> Put '[JSON] ()
)
:<|> Named
"update-collaborator-settings"
( Summary "Set user's distribution status as collaborator in other teams. Default: none"
:> From 'V5
:> ZLocalUser
:> "users"
:> QualifiedCaptureUserId "uid"
:> "collaborator-settings"
:> ReqBody '[JSON] CollaboratorSettings
:> Put '[JSON] ()
)
:<|> Named
"get-handle-info-unqualified"
( Summary "(deprecated, use /search/contacts) Get information on a user handle"
Expand Down
38 changes: 38 additions & 0 deletions libs/wire-api/src/Wire/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module Wire.API.User
-- User (should not be here)
User (..),
UserType (..),
CollaboratorSettings (..),
isSamlUser,
userId,
userDeleted,
Expand Down Expand Up @@ -626,6 +627,8 @@ data User = User
-- | Set if the user represents an external service,
-- i.e. it is a "bot".
userService :: Maybe ServiceRef,
-- | How user behaves in other teams as collaborator.
userCollaboratorSettings :: Maybe CollaboratorSettings,
-- | not required; must be unique if present
userHandle :: Maybe Handle,
-- | Set if the user is ephemeral
Expand All @@ -642,6 +645,40 @@ data User = User
deriving (Arbitrary) via (GenericUniform User)
deriving (ToJSON, FromJSON, S.ToSchema) via (Schema User)

-- | How user behaves in other teams as collaborator.
-- TODO(fisx): maybe move to a better place?
-- TODO(fisx): golden tests.
data CollaboratorSettings = CollaboratorSettings
{ distributionState :: CollaboratorDistributionState
}
deriving stock (Eq, Ord, Show, Generic)
deriving (Arbitrary) via (GenericUniform CollaboratorSettings)
deriving (ToJSON, FromJSON, S.ToSchema) via (Schema CollaboratorSettings)

instance ToSchema CollaboratorSettings where
schema =
object $
CollaboratorSettings
<$> distributionState .= field "distribution_state" schema

-- TODO(fisx): maybe move to a better place?
data CollaboratorDistributionState
= CollaboratorDraft
| CollaboratorNoDistribution
| CollaboratorFullDistribution
deriving stock (Eq, Ord, Show, Generic)
deriving (Arbitrary) via (GenericUniform CollaboratorDistributionState)
deriving (ToJSON, FromJSON, S.ToSchema) via (Schema CollaboratorDistributionState)

instance ToSchema CollaboratorDistributionState where
schema =
enum @Text $
mconcat
[ element "draft" CollaboratorDraft,
element "none" CollaboratorNoDistribution,
element "full" CollaboratorFullDistribution
]

isSamlUser :: User -> Bool
isSamlUser usr = do
case usr.userIdentity of
Expand Down Expand Up @@ -682,6 +719,7 @@ userObjectSchema =
<*> userStatus .= field "status" schema
<*> userLocale .= field "locale" schema
<*> userService .= maybe_ (optField "service" schema)
<*> userCollaboratorSettings .= maybe_ (optField "collaborator_settings" schema)
<*> userHandle .= maybe_ (optField "handle" schema)
<*> userExpire .= maybe_ (optField "expires_at" schema)
<*> userTeam .= maybe_ (optField "team" schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ testObject_SelfProfile_user_1 =
_serviceRefProvider = Id (fromJust (UUID.fromString "00000000-0000-0001-0000-000000000001"))
}
),
userCollaboratorSettings = Nothing,
userHandle = Just (fromJust (parseHandle "do9-5")),
userExpire = Just (fromJust (readUTCTimeMillis "1864-05-07T21:09:29.342Z")),
userTeam = Just (Id (fromJust (UUID.fromString "00000001-0000-0002-0000-000000000002"))),
Expand Down