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
1 change: 1 addition & 0 deletions changelog.d/5-internal/user-types-refactoring
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove `UserAccount` and `ExtendedUserAccount` and their fields to the `User` type
1 change: 0 additions & 1 deletion libs/brig-types/brig-types.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ test-suite brig-types-tests
, openapi3
, QuickCheck >=2.9
, tasty
, tasty-hunit
, tasty-quickcheck
, wire-api

Expand Down
2 changes: 0 additions & 2 deletions libs/brig-types/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
, openapi3
, QuickCheck
, tasty
, tasty-hunit
, tasty-quickcheck
, types-common
, wire-api
Expand All @@ -40,7 +39,6 @@ mkDerivation {
openapi3
QuickCheck
tasty
tasty-hunit
tasty-quickcheck
wire-api
];
Expand Down
2 changes: 1 addition & 1 deletion libs/brig-types/src/Brig/Types/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Brig.Types.Intra
( UserAccount (..),
( User (..),
NewUserScimInvitation (..),
UserSet (..),
)
Expand Down
20 changes: 2 additions & 18 deletions libs/brig-types/test/unit/Test/Brig/Types/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
module Test.Brig.Types.User where

import Brig.Types.Connection (UpdateConnectionsInternal (..))
import Brig.Types.Intra (NewUserScimInvitation (..), UserAccount (..))
import Brig.Types.Intra
import Brig.Types.User (ManagedByUpdate (..), RichInfoUpdate (..))
import Data.Aeson
import Imports
import Test.Brig.Roundtrip (testRoundTrip, testRoundTripWithSwagger)
import Test.QuickCheck (Arbitrary (arbitrary))
import Test.Tasty
import Test.Tasty.HUnit
import Wire.API.Routes.Internal.Brig.EJPD (EJPDRequestBody (..), EJPDResponseBody (..))
import Wire.API.User.Auth.ReAuth

Expand All @@ -48,22 +46,8 @@ roundtripTests =
testRoundTrip @NewUserScimInvitation,
testRoundTripWithSwagger @EJPDRequestBody,
testRoundTripWithSwagger @EJPDResponseBody,
testRoundTrip @UpdateConnectionsInternal,
testRoundTripWithSwagger @UserAccount,
testGroup "golden tests" $
[testCaseUserAccount]
testRoundTrip @UpdateConnectionsInternal
]

instance Arbitrary ReAuthUser where
arbitrary = ReAuthUser <$> arbitrary <*> arbitrary <*> arbitrary

testCaseUserAccount :: TestTree
testCaseUserAccount = testCase "UserAcccount" $ do
assertEqual "1" (Just json1) (encode <$> decode @UserAccount json1)
assertEqual "2" (Just json2) (encode <$> decode @UserAccount json2)
where
json1 :: LByteString
json1 = "{\"accent_id\":1,\"assets\":[],\"deleted\":true,\"email\":\"foo@example.com\",\"expires_at\":\"1864-05-09T17:20:22.192Z\",\"handle\":\"-ve\",\"id\":\"00000000-0000-0001-0000-000100000000\",\"locale\":\"lu\",\"managed_by\":\"wire\",\"name\":\"bla\",\"picture\":[],\"qualified_id\":{\"domain\":\"4-o60.j7-i\",\"id\":\"00000000-0000-0001-0000-000100000000\"},\"service\":{\"id\":\"00000000-0000-0001-0000-000000000001\",\"provider\":\"00000001-0000-0001-0000-000000000001\"},\"status\":\"suspended\",\"supported_protocols\":[\"proteus\"],\"team\":\"00000000-0000-0001-0000-000100000001\"}"

json2 :: LByteString
json2 = "{\"accent_id\":0,\"assets\":[{\"key\":\"3-4-00000000-0000-0001-0000-000000000000\",\"size\":\"preview\",\"type\":\"image\"}],\"email\":\"a@b\",\"expires_at\":\"1864-05-10T22:45:44.823Z\",\"handle\":\"b8m\",\"id\":\"00000000-0000-0000-0000-000000000001\",\"locale\":\"tk-KZ\",\"managed_by\":\"wire\",\"name\":\"name2\",\"picture\":[],\"qualified_id\":{\"domain\":\"1-8wq0.b22k1.w5\",\"id\":\"00000000-0000-0000-0000-000000000001\"},\"service\":{\"id\":\"00000000-0000-0001-0000-000000000001\",\"provider\":\"00000001-0000-0001-0000-000100000000\"},\"status\":\"pending-invitation\",\"supported_protocols\":[\"proteus\"],\"team\":\"00000000-0000-0001-0000-000000000001\"}"
4 changes: 2 additions & 2 deletions libs/wire-api/src/Wire/API/Routes/Internal/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ type AccountAPI =
]
"includePendingInvitations"
Bool
:> Get '[Servant.JSON] [ExtendedUserAccount]
:> Get '[Servant.JSON] [User]
)
:<|> Named
"iGetUserContacts"
Expand Down Expand Up @@ -594,7 +594,7 @@ type TeamInvitations =
:> Capture "tid" TeamId
:> "invitations"
:> Servant.ReqBody '[JSON] NewUserScimInvitation
:> Post '[JSON] UserAccount
:> Post '[JSON] User
)

type UserAPI =
Expand Down
73 changes: 16 additions & 57 deletions libs/wire-api/src/Wire/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Wire.API.User
-- User (should not be here)
User (..),
userId,
userDeleted,
userEmail,
userSSOId,
userIssuer,
Expand Down Expand Up @@ -110,10 +111,6 @@ module Wire.API.User
AccountStatusUpdate (..),
AccountStatusResp (..),

-- * Account
UserAccount (..),
ExtendedUserAccount (..),

-- * Scim invitations
NewUserScimInvitation (..),

Expand Down Expand Up @@ -558,6 +555,7 @@ data User = User
-- the user is activated, and the email/phone contained in it will be guaranteedly
-- verified. {#RefActivation}
userIdentity :: Maybe UserIdentity,
userEmailUnvalidated :: Maybe EmailAddress,
-- | required; non-unique
userDisplayName :: Name,
-- | text status
Expand All @@ -566,7 +564,7 @@ data User = User
userPict :: Pict,
userAssets :: [Asset],
userAccentId :: ColourId,
userDeleted :: Bool,
userStatus :: AccountStatus,
userLocale :: Locale,
-- | Set if the user represents an external service,
-- i.e. it is a "bot".
Expand All @@ -589,6 +587,9 @@ data User = User
userId :: User -> UserId
userId = qUnqualified . userQualifiedId

userDeleted :: User -> Bool
userDeleted u = userStatus u == Deleted

-- -- FUTUREWORK:
-- -- disentangle json serializations for 'User', 'NewUser', 'UserIdentity', 'NewUserOrigin'.
instance ToSchema User where
Expand All @@ -601,8 +602,8 @@ userObjectSchema =
.= field "qualified_id" schema
<* userId
.= optional (field "id" (deprecatedSchema "qualified_id" schema))
<*> userIdentity
.= maybeUserIdentityObjectSchema
<*> userIdentity .= maybeUserIdentityObjectSchema
<*> userEmailUnvalidated .= maybe_ (optField "email_unvalidated" schema)
<*> userDisplayName
.= field "name" schema
<*> userTextStatus
Expand All @@ -611,22 +612,17 @@ userObjectSchema =
.= (fromMaybe noPict <$> optField "picture" schema)
<*> userAssets
.= (fromMaybe [] <$> optField "assets" (array schema))
<*> userAccentId
.= field "accent_id" schema
<*> (fromMaybe False <$> (\u -> if userDeleted u then Just True else Nothing) .= maybe_ (optField "deleted" schema))
<*> userLocale
.= field "locale" schema
<*> userService
.= maybe_ (optField "service" schema)
<*> userHandle
.= maybe_ (optField "handle" schema)
<*> userExpire
.= maybe_ (optField "expires_at" schema)
<*> userTeam
.= maybe_ (optField "team" schema)
<*> userAccentId .= field "accent_id" schema
<*> userStatus .= field "status" schema
<*> userLocale .= field "locale" schema
<*> userService .= maybe_ (optField "service" schema)
<*> userHandle .= maybe_ (optField "handle" schema)
<*> userExpire .= maybe_ (optField "expires_at" schema)
<*> userTeam .= maybe_ (optField "team" schema)
<*> userManagedBy
.= (fromMaybe ManagedByWire <$> optField "managed_by" schema)
<*> userSupportedProtocols .= supportedProtocolsObjectSchema
<* (fromMaybe False <$> (\u -> if userDeleted u then Just True else Nothing) .= maybe_ (optField "deleted" schema))

userEmail :: User -> Maybe EmailAddress
userEmail = emailIdentity <=< userIdentity
Expand Down Expand Up @@ -1813,43 +1809,6 @@ instance Schema.ToSchema AccountStatusUpdate where
-------------------------------------------------------------------------------
-- UserAccount

-- | A UserAccount is targeted to be used by our \"backoffice\" and represents
-- all the data related to a user in our system, regardless of whether they
-- are active or not, their status, etc.
data UserAccount = UserAccount
{ accountUser :: !User,
accountStatus :: !AccountStatus
}
deriving (Eq, Ord, Show, Generic)
deriving (Arbitrary) via (GenericUniform UserAccount)
deriving (ToJSON, FromJSON, S.ToSchema) via Schema.Schema UserAccount

instance Schema.ToSchema UserAccount where
schema = Schema.object "UserAccount" userAccountObjectSchema

userAccountObjectSchema :: ObjectSchema SwaggerDoc UserAccount
userAccountObjectSchema =
UserAccount
<$> accountUser Schema..= userObjectSchema
<*> accountStatus Schema..= Schema.field "status" Schema.schema

-- | This can be parsed as UserAccount, but it has an extra field `email_unvalidated` from
-- brig's cassandra that is needed in spar. so we return this from GET /i/users in brig.
data ExtendedUserAccount = ExtendedUserAccount
{ account :: UserAccount,
emailUnvalidated :: Maybe EmailAddress
}
deriving (Eq, Ord, Show, Generic)
deriving (Arbitrary) via (GenericUniform ExtendedUserAccount)
deriving (ToJSON, FromJSON, S.ToSchema) via Schema.Schema ExtendedUserAccount

instance Schema.ToSchema ExtendedUserAccount where
schema =
Schema.object "ExtendedUserAccount" $
ExtendedUserAccount
<$> account Schema..= userAccountObjectSchema
<*> emailUnvalidated Schema..= maybe_ (Schema.optField "email_unvalidated" Schema.schema)

-------------------------------------------------------------------------------
-- NewUserScimInvitation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ testObject_SelfProfile_user_1 =
{ qUnqualified = Id (fromJust (UUID.fromString "00000001-0000-0000-0000-000000000002")),
qDomain = Domain {_domainText = "n0-994.m-226.f91.vg9p-mj-j2"}
},
userIdentity =
Just (EmailIdentity (unsafeEmailAddress "some" "example")),
userIdentity = Just (EmailIdentity (unsafeEmailAddress "some" "example")),
userEmailUnvalidated = Nothing,
userDisplayName = Name {fromName = "@\1457\2598\66242\US\1104967l+\137302\&6\996495^\162211Mu\t"},
userTextStatus = rightToMaybe $ mkTextStatus "text status",
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
userDeleted = False,
userStatus = Active,
userLocale =
Locale {lLanguage = Language Data.LanguageCodes.GL, lCountry = Just (Country {fromCountry = PA})},
userService =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ testObject_User_user_1 =
qDomain = Domain {_domainText = "s-f4.s"}
},
userIdentity = Nothing,
userEmailUnvalidated = Nothing,
userDisplayName = Name {fromName = "\NULuv\996028su\28209lRi"},
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
userDeleted = True,
userStatus = Deleted,
userLocale = Locale {lLanguage = Language Data.LanguageCodes.TN, lCountry = Just (Country {fromCountry = SB})},
userService = Nothing,
userHandle = Nothing,
Expand All @@ -79,6 +80,7 @@ testObject_User_user_2 =
qDomain = Domain {_domainText = "k.vbg.p"}
},
userIdentity = Just (EmailIdentity (unsafeEmailAddress "some" "example")),
userEmailUnvalidated = Nothing,
userDisplayName =
Name
{ fromName =
Expand All @@ -92,7 +94,7 @@ testObject_User_user_2 =
ImageAsset (AssetKeyV3 (Id (fromJust (UUID.fromString "5cd81cc4-c643-4e9c-849c-c596a88c27fd"))) AssetExpiring) (Just AssetComplete)
],
userAccentId = ColourId {fromColourId = -2},
userDeleted = True,
userStatus = Deleted,
userLocale = Locale {lLanguage = Language Data.LanguageCodes.DA, lCountry = Just (Country {fromCountry = TN})},
userService =
Just
Expand All @@ -117,13 +119,14 @@ testObject_User_user_3 =
qDomain = Domain {_domainText = "dt.n"}
},
userIdentity = Just (EmailIdentity (unsafeEmailAddress "some" "example")),
userEmailUnvalidated = Nothing,
userDisplayName =
Name {fromName = ",r\EMXEg0$\98187\RS\SI'uS\ETX/\1009222`\228V.J{\fgE(\rK!\SOp8s9gXO\21810Xj\STX\RS\DC2"},
userTextStatus = Nothing,
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = -2},
userDeleted = True,
userStatus = Deleted,
userLocale = Locale {lLanguage = Language Data.LanguageCodes.TG, lCountry = Just (Country {fromCountry = UA})},
userService =
Just
Expand All @@ -149,6 +152,7 @@ testObject_User_user_4 =
},
userIdentity =
Just (SSOIdentity (UserScimExternalId "") (Just (unsafeEmailAddress "some" "example"))),
userEmailUnvalidated = Nothing,
userDisplayName =
Name
{ fromName =
Expand All @@ -158,7 +162,7 @@ testObject_User_user_4 =
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 0},
userDeleted = False,
userStatus = Active,
userLocale = Locale {lLanguage = Language Data.LanguageCodes.BI, lCountry = Just (Country {fromCountry = MQ})},
userService =
Just
Expand All @@ -185,6 +189,7 @@ testObject_User_user_5 =
},
userIdentity =
Just (EmailIdentity (unsafeEmailAddress "some" "example")),
userEmailUnvalidated = Nothing,
userDisplayName =
Name
{ fromName =
Expand All @@ -194,7 +199,7 @@ testObject_User_user_5 =
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 0},
userDeleted = False,
userStatus = Active,
userLocale = Locale {lLanguage = Language Data.LanguageCodes.BI, lCountry = Just (Country {fromCountry = MQ})},
userService =
Just
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ alice =
qDomain = Domain {_domainText = "foo.example.com"}
},
userIdentity = Nothing,
userEmailUnvalidated = Nothing,
userDisplayName = Name "alice",
userTextStatus = rightToMaybe $ mkTextStatus "text status",
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 1},
userDeleted = True,
userStatus = Deleted,
userLocale =
Locale
{ lLanguage = Language L.TN,
Expand All @@ -253,12 +254,13 @@ bob =
qDomain = Domain {_domainText = "baz.example.com"}
},
userIdentity = Nothing,
userEmailUnvalidated = Nothing,
userDisplayName = Name "bob",
userTextStatus = rightToMaybe $ mkTextStatus "text status",
userPict = Pict {fromPict = []},
userAssets = [],
userAccentId = ColourId {fromColourId = 2},
userDeleted = False,
userStatus = Active,
userLocale =
Locale
{ lLanguage = Language L.CA,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"id": "00000000-0000-0001-0000-000000000000",
"provider": "00000000-0000-0001-0000-000000000001"
},
"status": "active",
"supported_protocols": [
"proteus"
],
Expand Down
1 change: 1 addition & 0 deletions libs/wire-api/test/golden/testObject_UserEvent_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"domain": "foo.example.com",
"id": "539d9183-32a5-4fc4-ba5c-4634454e7585"
},
"status": "deleted",
"supported_protocols": [
"proteus"
],
Expand Down
1 change: 1 addition & 0 deletions libs/wire-api/test/golden/testObject_UserEvent_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"domain": "foo.example.com",
"id": "539d9183-32a5-4fc4-ba5c-4634454e7585"
},
"status": "deleted",
"supported_protocols": [
"proteus"
],
Expand Down
1 change: 1 addition & 0 deletions libs/wire-api/test/golden/testObject_User_user_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"domain": "s-f4.s",
"id": "00000002-0000-0001-0000-000200000002"
},
"status": "deleted",
"supported_protocols": [
"proteus"
]
Expand Down
1 change: 1 addition & 0 deletions libs/wire-api/test/golden/testObject_User_user_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"id": "00000000-0000-0000-0000-000000000001",
"provider": "00000000-0000-0000-0000-000100000000"
},
"status": "deleted",
"supported_protocols": [],
"text_status": "text status"
}
Loading