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

User subsystem: add profile update operations #4046

Merged
merged 134 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
8c4ec63
UpdateUser operation; work on Error sub-effects.
pcapriotti May 10, 2024
2b044a8
Fix build
pcapriotti May 13, 2024
1e17a86
Rename onUserEvent → generateUserEvent
pcapriotti May 13, 2024
a1352a4
Use state effect for local users in mini backends
pcapriotti May 13, 2024
0466072
Implement user update in mini backends
pcapriotti May 13, 2024
478693d
Add user update property test
pcapriotti May 13, 2024
7d70e79
[feat] rethrow errors as wai errors
MangoIV May 13, 2024
6d6695c
[feat] test behaviour if user is managed by scim
MangoIV May 13, 2024
1ed40db
[feat] set galley api access
MangoIV May 13, 2024
17b5155
[feat] test all of the update record members
MangoIV May 13, 2024
619d032
[feat] interpret user events
MangoIV May 13, 2024
b34debf
Use MiniBackend state effect in mini-backend stack
pcapriotti May 14, 2024
e58521e
Add fake event interpreter
pcapriotti May 14, 2024
9ee4efe
Add Arbitrary instance for AllowSCIMUpdates
pcapriotti May 14, 2024
2bbb388
Replace UserUpdate with a new type
pcapriotti May 14, 2024
dc57f85
Use update functionality in brig
pcapriotti May 14, 2024
898b917
Add locale update to user subsystem
pcapriotti May 14, 2024
696342a
Move allowScim argument to update structure
pcapriotti May 14, 2024
11dc928
Add handle update functionality to UserSubsystem
pcapriotti May 17, 2024
e38f08b
Make sure NotPending users have an identity
pcapriotti May 22, 2024
8c79463
Check claimed handles
pcapriotti May 22, 2024
3f3ac72
Implement handle lookup in mini backend
pcapriotti May 22, 2024
8f211d8
Add DeleteUser action to UserStore
pcapriotti May 23, 2024
9617c93
Add some TODOs
pcapriotti May 23, 2024
1ea9657
Lint and format
elland May 23, 2024
189d545
Added missing where clause.
elland May 23, 2024
0c96894
Fixed tombstone.
elland May 23, 2024
ff4a366
Renamed cql query function for clarity.
elland May 23, 2024
89d4024
usersubsystems: added handle parsing text.
elland May 23, 2024
7fb0676
Formatting.
elland May 23, 2024
4f55d8a
UserSubsystems: Added prop tests for handles.
elland May 23, 2024
8d42e40
lint
elland May 23, 2024
5623de1
UserSubsystem: added scim handle update tests.
elland May 23, 2024
b536183
added changelog
elland May 27, 2024
70b32c7
Added update supported protocols.
elland May 27, 2024
8e02e24
[stash]
fisx May 27, 2024
a98058f
...
fisx May 27, 2024
e72c7d7
...
fisx May 27, 2024
db9db70
...
fisx May 27, 2024
8630333
Fix.
fisx May 27, 2024
86565b0
TODO.
fisx May 27, 2024
0c7e31d
Fix 2 test cases.
fisx May 27, 2024
f98c6d0
Fixed property test.
elland May 28, 2024
7c79cb6
Deleted repeated lines.
elland May 28, 2024
4f1ec69
Regen nix.
elland May 28, 2024
9a2764f
Removed ambiguity.
elland May 28, 2024
5061acb
Updated call sites.
elland May 28, 2024
2dd847d
Remove bogus (and unnecessary) -Wwarn pragma.
fisx May 28, 2024
bc049fb
explicit imports, exports.
fisx May 28, 2024
64c3de9
Removed outdated FUTUREWORK.
fisx May 28, 2024
0523868
Typo.
fisx May 28, 2024
45ddd8d
Make leaking interpreter implementation into brig more explicit.
fisx May 28, 2024
7faed02
Drive-by fix.
fisx May 28, 2024
00fcb9f
Send handle update events.
fisx May 28, 2024
8441af9
Fixup bc049fbc144938e9e42d3c5b313f369b5d885e2a
fisx May 28, 2024
872f9fb
Fixup 00fcb9f2135e2a54dd9d3d9691786289d8a418f6
fisx May 28, 2024
23d85a9
Fixup bc049fbc144938e9e42d3c5b313f369b5d885e2a
fisx May 28, 2024
c9fdec2
Test for update supportedProtocols.
fisx May 28, 2024
dc59c26
Update supportedProtocols [wip]
fisx May 28, 2024
145e364
Fixed test for supported protocols.
elland May 28, 2024
840d625
WIP: fix permissio checks
elland May 29, 2024
6d2c2f5
Move BadHandle type and qc generator to types-common.
fisx May 29, 2024
f6d1840
Fix handle update for blocklisted handles.
fisx May 29, 2024
5a4f836
Make supported-protocols update test a property.
fisx May 29, 2024
1f8e2b3
Fix more failing test cases (same pattern as before).
fisx May 29, 2024
5077b89
Simplify checkHandle test
akshaymankar May 29, 2024
92d37f7
UserSubsystem: Implement GetSelfProfile
akshaymankar May 29, 2024
10c7282
UserSubsystem.updateUserProfile: Add assertion for updating locale
akshaymankar May 29, 2024
1af8eeb
Remove TODO deemed requiring discussion
akshaymankar May 29, 2024
8d85bef
UserSubsystem: Implement GetSelfProfile
akshaymankar May 29, 2024
0644bd5
Merge remote-tracking branch 'origin/develop' into update-profile
fisx May 30, 2024
431dc3e
Rename names.
fisx May 30, 2024
20d020c
Re-align userstore and user subsystem interfaces around handle.
fisx May 30, 2024
95c0895
Rm some boolean blindness.
fisx May 30, 2024
68e9cfb
Rename names (really bad ones this time...).
fisx May 30, 2024
19af787
Fix UpdateOriginType values in brig api.
fisx May 30, 2024
8f111d2
rm TODO.
fisx May 30, 2024
a204ee3
Add TODOs.
fisx May 30, 2024
ac171fc
Fix TODO syntax :)
fisx May 30, 2024
c263709
Deprioritize TODO.
fisx May 30, 2024
83bbf0e
Haddocs.
fisx May 30, 2024
125c6bb
Merge remote-tracking branch 'origin/develop' into update-profile
fisx May 31, 2024
08e382b
Improve error message for invalid handles.
fisx May 31, 2024
6a1b88b
Rename names.
fisx May 31, 2024
f2cf6db
Note on db performance.
fisx May 31, 2024
59e5bba
Remove unproducable error.
fisx May 31, 2024
2f21e55
Haddocks.
fisx May 31, 2024
73c2d3d
Remove misguided TODOs.
fisx May 31, 2024
49fd0c0
Fix: update locale by client not allowed if user is managed by scim.
fisx May 31, 2024
f875082
Fix names.
fisx May 31, 2024
a45671f
remove more low-prio TODOs.
fisx May 31, 2024
103f48f
Resolve TODO.
fisx May 31, 2024
b6b8781
Add test for locale update under scim management.
fisx May 31, 2024
b22d481
Fix test.
fisx May 31, 2024
3aab327
Fix tests, add happy path for profile update.
fisx May 31, 2024
491611f
Fixup
fisx May 31, 2024
0a79d96
Fix locale update.
fisx May 31, 2024
8ebd1f7
Rm dead code.
fisx May 31, 2024
261a9cc
Typo
fisx May 31, 2024
1fb67b1
Fix compiler errors.
fisx May 31, 2024
1000b25
Rm dead code.
fisx May 31, 2024
be9bc67
Test coverage.
fisx May 31, 2024
41224da
Fix missing fields in update event.
fisx May 31, 2024
abb1f9d
Dry-by fix: make responseJsonUnsafe more helpful when crashing.
fisx May 31, 2024
992fe5d
hlint.
fisx May 31, 2024
a7f9f84
hlint. (?!)
fisx Jun 3, 2024
58a639b
Polish haddocks.
fisx Jun 3, 2024
9be4bdf
Changelog.
fisx Jun 3, 2024
459e966
Make Handle data type abstract.
fisx Jun 3, 2024
93cdaeb
Revert "Make Handle data type abstract."
fisx Jun 3, 2024
99915bc
Move local function in where block.
fisx Jun 3, 2024
4ee712c
Remove FUTUREWORK
fisx Jun 3, 2024
07d53e5
Rename local function.
fisx Jun 3, 2024
948b889
Fix test case.
fisx Jun 3, 2024
49c0cf6
Merge remote-tracking branch 'origin/develop' into update-profile
fisx Jun 3, 2024
555161e
remove obsolete changelog entry (this has been fixed in WPB-9488).
fisx Jun 3, 2024
8c66230
Rm dead code from rest api.
fisx Jun 3, 2024
e039e95
Revert "Rm dead code from rest api."
fisx Jun 3, 2024
79fe0e5
Update services/brig/test/integration/API/UserPendingActivation.hs
fisx Jun 4, 2024
874d7ba
Merge remote-tracking branch 'origin/develop' into update-profile
fisx Jun 4, 2024
149854d
Update services/brig/src/Brig/User/Auth.hs
fisx Jun 4, 2024
88b0190
More guards in unit tests against invalid arbitrary values.
fisx Jun 4, 2024
7fa4efa
Merge remote-tracking branch 'refs/remotes/origin/update-profile' int…
fisx Jun 4, 2024
93ee32d
Fixup
fisx Jun 4, 2024
4059bf9
Fix test case.
fisx Jun 4, 2024
385a29a
Improve error message for `*ManagedByScim`.
fisx Jun 4, 2024
298c406
Revert "Fix test case."
fisx Jun 4, 2024
829c88a
Fix application logic around blocking updates because scim or e2eid.
fisx Jun 5, 2024
b9067a7
Merge remote-tracking branch 'origin/develop' into update-profile
fisx Jun 5, 2024
5f50929
hlint.
fisx Jun 5, 2024
c40670e
failed attempt to port a galley test to /integration
fisx Jun 5, 2024
66a9abc
Revert "failed attempt to port a galley test to /integration"
fisx Jun 5, 2024
f927d98
I think I found the problem with this test! (fix coming up)
fisx Jun 5, 2024
4ac5de7
Small fix for legacy integration test.
fisx Jun 6, 2024
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/WPB-8880
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added profile update operations to the user subsystem.
2 changes: 1 addition & 1 deletion libs/bilge/src/Bilge/Response.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ responseJsonUnsafe ::
(HasCallStack, Typeable a, FromJSON a) =>
ResponseLBS ->
a
responseJsonUnsafe = responseJsonUnsafeWithMsg ""
responseJsonUnsafe resp = responseJsonUnsafeWithMsg (show resp) resp

{-# INLINE responseJsonUnsafeWithMsg #-}
responseJsonUnsafeWithMsg ::
Expand Down
23 changes: 23 additions & 0 deletions libs/types-common/src/Data/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ module Data.Handle
parseHandle,
parseHandleEither,
isValidHandle,
BadHandle (..),
)
where

import Cassandra qualified as C
import Control.Lens (ix, (.~))
import Data.Aeson (FromJSON (..), ToJSON (..))
import Data.Attoparsec.ByteString.Char8 qualified as Atto
import Data.Bifunctor (Bifunctor (first))
Expand Down Expand Up @@ -101,3 +103,24 @@ instance Arbitrary Handle where
Handle . Text.pack <$> do
len <- oneof [choose (2, 10), choose (2, 256)] -- prefer short handles
replicateM len (elements $ ['a' .. 'z'] <> ['0' .. '9'] <> "_-.")

-- | for testing
newtype BadHandle = BadHandle {fromBadHandle :: Text}
deriving newtype (Eq, Show)

instance Arbitrary BadHandle where
arbitrary = oneof [tooShort, tooLong, badBytes]
where
tooShort = (BadHandle . Text.pack . (: [])) <$> elements validChar
tooLong = (BadHandle . Text.pack) <$> replicateM 258 (elements validChar)
badBytes =
BadHandle <$> do
totalLen :: Int <- choose (2, 256)
invalidCharPos :: Int <- choose (0, totalLen - 1)
invalidCharContent <- elements invalidChar
good :: Text <- Text.pack <$> replicateM totalLen (elements validChar)
let bad :: Text = good & ix invalidCharPos .~ invalidCharContent
pure bad

validChar :: [Char] = ['a' .. 'z'] <> ['0' .. '9'] <> "_-."
invalidChar :: [Char] = [minBound ..] \\ validChar
7 changes: 5 additions & 2 deletions libs/types-common/test/Test/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Test.Handle
)
where

import Data.Handle (Handle (fromHandle), parseHandleEither)
import Data.Handle (BadHandle (fromBadHandle), Handle (fromHandle), parseHandleEither)
import Data.Text qualified as Text
import Imports
import Test.Tasty
Expand Down Expand Up @@ -67,5 +67,8 @@ testHandleSerialization =
Right parsed -> assertFailure $ "invalid handle parsed successfully: " <> show (h, parsed),
testProperty "roundtrip for Handle" $
\(x :: Handle) ->
parseHandleEither (fromHandle x) === Right x
parseHandleEither (fromHandle x) === Right x,
testProperty "roundtrip for BadHandle" $
\(x :: BadHandle) ->
property . isLeft . parseHandleEither $ fromBadHandle x
]
2 changes: 2 additions & 0 deletions libs/wire-api/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
, crypton
, crypton-x509
, currency-codes
, data-default
, deriving-aeson
, deriving-swagger2
, either
Expand Down Expand Up @@ -139,6 +140,7 @@ mkDerivation {
crypton
crypton-x509
currency-codes
data-default
deriving-aeson
deriving-swagger2
either
Expand Down
9 changes: 6 additions & 3 deletions libs/wire-api/src/Wire/API/Error/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ data BrigError
| UserKeyExists
| NameManagedByScim
| HandleManagedByScim
| LocaleManagedByScim
| LastIdentity
| NoPassword
| ChangePasswordMustDiffer
Expand Down Expand Up @@ -172,7 +173,7 @@ type instance MapError 'NoIdentity = 'StaticError 403 "no-identity" "The user ha

type instance MapError 'HandleExists = 'StaticError 409 "handle-exists" "The given handle is already taken"

type instance MapError 'InvalidHandle = 'StaticError 400 "invalid-handle" "The given handle is invalid"
type instance MapError 'InvalidHandle = 'StaticError 400 "invalid-handle" "The given handle is invalid (less than 2 or more than 256 characters; chars not in \"a-z0-9_.-\"; or on the blocklist)"

type instance MapError 'HandleNotFound = 'StaticError 404 "not-found" "Handle not found"

Expand Down Expand Up @@ -238,9 +239,11 @@ type instance MapError 'AccountPending = 'StaticError 403 "pending-activation" "

type instance MapError 'UserKeyExists = 'StaticError 409 "key-exists" "The given e-mail address or phone number is in use."

type instance MapError 'NameManagedByScim = 'StaticError 403 "managed-by-scim" "Updating name is not allowed, because it is managed by SCIM"
type instance MapError 'NameManagedByScim = 'StaticError 403 "managed-by-scim" "Updating name is not allowed, because it is managed by SCIM, or E2EId is enabled"

type instance MapError 'HandleManagedByScim = 'StaticError 403 "managed-by-scim" "Updating handle is not allowed, because it is managed by SCIM"
type instance MapError 'HandleManagedByScim = 'StaticError 403 "managed-by-scim" "Updating handle is not allowed, because it is managed by SCIM, or E2EId is enabled"

type instance MapError 'LocaleManagedByScim = 'StaticError 403 "managed-by-scim" "Updating locale is not allowed, because it is managed by SCIM, or E2EId is enabled"

type instance MapError 'LastIdentity = 'StaticError 403 "last-identity" "The last user identity (email or phone number) cannot be removed."

Expand Down
2 changes: 1 addition & 1 deletion libs/wire-api/src/Wire/API/Routes/Internal/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ type AccountAPI =
:> Put '[Servant.JSON] NoContent
)
:<|> Named
"iPutHandle"
"iPutUserName"
( "users"
:> Capture "uid" UserId
:> "name"
Expand Down
14 changes: 7 additions & 7 deletions libs/wire-api/src/Wire/API/Routes/Public/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ type SelfAPI =
"get-self"
( Summary "Get your own profile"
:> DescriptionOAuthScope 'ReadSelf
:> ZUser
:> ZLocalUser
:> "self"
:> Get '[JSON] SelfProfile
)
Expand Down Expand Up @@ -334,11 +334,11 @@ type SelfAPI =
"put-self"
( Summary "Update your profile."
:> MakesFederatedCall 'Brig "send-connection-action"
:> ZUser
:> ZLocalUser
:> ZConn
:> "self"
:> ReqBody '[JSON] UserUpdate
:> MultiVerb 'PUT '[JSON] PutSelfResponses (Maybe UpdateProfileError)
:> MultiVerb1 'PUT '[JSON] (RespondEmpty 200 "User updated")
)
:<|> Named
"change-phone"
Expand Down Expand Up @@ -409,24 +409,24 @@ type SelfAPI =
"change-locale"
( Summary "Change your locale."
:> MakesFederatedCall 'Brig "send-connection-action"
:> ZUser
:> ZLocalUser
:> ZConn
:> "self"
:> "locale"
:> ReqBody '[JSON] LocaleUpdate
:> MultiVerb 'PUT '[JSON] '[RespondEmpty 200 "Local Changed"] ()
:> MultiVerb1 'PUT '[JSON] (RespondEmpty 200 "Local Changed")
)
:<|> Named
"change-handle"
( Summary "Change your handle."
:> MakesFederatedCall 'Brig "send-connection-action"
:> MakesFederatedCall 'Brig "send-connection-action"
:> ZUser
:> ZLocalUser
:> ZConn
:> "self"
:> "handle"
:> ReqBody '[JSON] HandleUpdate
:> MultiVerb 'PUT '[JSON] ChangeHandleResponses (Maybe ChangeHandleError)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the error responses?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akshaymankar , Paolo replied to the same question I had. See the comments section on the main PR page.

:> MultiVerb1 'PUT '[JSON] (RespondEmpty 200 "Handle Changed")
)
:<|> Named
"change-supported-protocols"
Expand Down
26 changes: 26 additions & 0 deletions libs/wire-api/src/Wire/API/Team/Feature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import Data.Attoparsec.ByteString qualified as Parser
import Data.ByteString (fromStrict)
import Data.ByteString.Conversion
import Data.ByteString.UTF8 qualified as UTF8
import Data.Default
import Data.Domain (Domain)
import Data.Either.Extra (maybeToEither)
import Data.Id
Expand Down Expand Up @@ -1242,6 +1243,31 @@ data AllFeatureConfigs = AllFeatureConfigs
deriving stock (Eq, Show)
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema AllFeatureConfigs)

instance Default AllFeatureConfigs where
def =
AllFeatureConfigs
{ afcLegalholdStatus = defFeatureStatus,
afcSSOStatus = defFeatureStatus,
afcTeamSearchVisibilityAvailable = defFeatureStatus,
afcSearchVisibilityInboundConfig = defFeatureStatus,
afcValidateSAMLEmails = defFeatureStatus,
afcDigitalSignatures = defFeatureStatus,
afcAppLock = defFeatureStatus,
afcFileSharing = defFeatureStatus,
afcClassifiedDomains = defFeatureStatus,
afcConferenceCalling = defFeatureStatus,
afcSelfDeletingMessages = defFeatureStatus,
afcGuestLink = defFeatureStatus,
afcSndFactorPasswordChallenge = defFeatureStatus,
afcMLS = defFeatureStatus,
afcExposeInvitationURLsToTeamAdmin = defFeatureStatus,
afcOutlookCalIntegration = defFeatureStatus,
afcMlsE2EId = defFeatureStatus,
afcMlsMigration = defFeatureStatus,
afcEnforceFileDownloadLocation = defFeatureStatus,
afcLimitedEventFanout = defFeatureStatus
}

instance ToSchema AllFeatureConfigs where
schema =
object "AllFeatureConfigs" $
Expand Down
2 changes: 1 addition & 1 deletion libs/wire-api/src/Wire/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ instance ToSchema SendVerificationCode where
-- Unlike 'ProtocolTag', this does not include any transitional protocols used
-- for migration.
data BaseProtocolTag = BaseProtocolProteusTag | BaseProtocolMLSTag
deriving stock (Eq, Ord, Show, Generic)
deriving stock (Eq, Ord, Enum, Bounded, Show, Generic)
deriving (Arbitrary) via (GenericUniform BaseProtocolTag)
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema BaseProtocolTag)

Expand Down
1 change: 1 addition & 0 deletions libs/wire-api/wire-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ library
, crypton
, crypton-x509
, currency-codes >=2.0
, data-default
, deriving-aeson >=0.2
, deriving-swagger2
, either
Expand Down
7 changes: 7 additions & 0 deletions libs/wire-subsystems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
, cql
, currency-codes
, data-default
, data-timeout
, errors
, exceptions
, extended
Expand Down Expand Up @@ -56,6 +57,7 @@
, transitive-anns
, types-common
, unliftio
, unordered-containers
, uuid
, wai-utilities
, wire-api
Expand All @@ -81,6 +83,7 @@ mkDerivation {
cql
currency-codes
data-default
data-timeout
errors
exceptions
extended
Expand Down Expand Up @@ -114,6 +117,7 @@ mkDerivation {
transitive-anns
types-common
unliftio
unordered-containers
uuid
wai-utilities
wire-api
Expand All @@ -127,11 +131,13 @@ mkDerivation {
bytestring
containers
data-default
errors
extended
gundeck-types
hspec
imports
iso639
lens
polysemy
polysemy-plugin
polysemy-time
Expand All @@ -140,6 +146,7 @@ mkDerivation {
quickcheck-instances
servant-client-core
string-conversions
text
time
transformers
types-common
Expand Down
Loading
Loading