Skip to content

Commit

Permalink
Revert "Improve global team conversation handling and self conversati…
Browse files Browse the repository at this point in the history
…on creation error. (#2862)"

This reverts commit 381bf7b.
  • Loading branch information
smatting committed Nov 28, 2022
1 parent 034401e commit c2e6e77
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 198 deletions.
3 changes: 0 additions & 3 deletions libs/wire-api/src/Wire/API/Error/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ data GalleyError
| MLSWelcomeMismatch
| MLSMissingGroupInfo
| MLSMissingSenderClient
| MLSUnexpectedSenderClient
| --
NoBindingTeamMembers
| NoBindingTeam
Expand Down Expand Up @@ -204,8 +203,6 @@ type instance MapError 'MLSGroupConversationMismatch = 'StaticError 400 "mls-gro

type instance MapError 'MLSClientSenderUserMismatch = 'StaticError 400 "mls-client-sender-user-mismatch" "User ID resolved from Client ID does not match message's sender user ID"

type instance MapError 'MLSUnexpectedSenderClient = 'StaticError 422 "mls-unexpected-sender-client-found" "Unexpected creator client set. This is a newly created conversation and it expected exactly one client."

type instance MapError 'MLSWelcomeMismatch = 'StaticError 400 "mls-welcome-mismatch" "The list of targets of a welcome message does not match the list of new clients in a group"

type instance MapError 'MLSMissingGroupInfo = 'StaticError 404 "mls-missing-group-info" "The conversation has no group information"
Expand Down
3 changes: 0 additions & 3 deletions libs/wire-api/src/Wire/API/Routes/Public/Galley/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type MLSMessagingAPI =
:> CanThrow 'MLSStaleMessage
:> CanThrow 'MLSUnsupportedMessage
:> CanThrow 'MLSUnsupportedProposal
:> CanThrow 'MLSUnexpectedSenderClient
:> CanThrow 'MLSClientSenderUserMismatch
:> CanThrow 'MLSGroupConversationMismatch
:> CanThrow 'MLSMissingSenderClient
Expand Down Expand Up @@ -89,7 +88,6 @@ type MLSMessagingAPI =
:> CanThrow 'MLSStaleMessage
:> CanThrow 'MLSUnsupportedMessage
:> CanThrow 'MLSUnsupportedProposal
:> CanThrow 'MLSUnexpectedSenderClient
:> CanThrow 'MLSClientSenderUserMismatch
:> CanThrow 'MLSGroupConversationMismatch
:> CanThrow 'MLSMissingSenderClient
Expand Down Expand Up @@ -118,7 +116,6 @@ type MLSMessagingAPI =
:> CanThrow 'MLSStaleMessage
:> CanThrow 'MLSUnsupportedMessage
:> CanThrow 'MLSUnsupportedProposal
:> CanThrow 'MLSUnexpectedSenderClient
:> CanThrow 'MLSClientSenderUserMismatch
:> CanThrow 'MLSGroupConversationMismatch
:> CanThrow 'MLSMissingSenderClient
Expand Down
14 changes: 13 additions & 1 deletion services/galley/src/Galley/API/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import Data.Singletons
import Data.Time.Clock
import Galley.API.Error
import Galley.API.MLS.Removal
import Galley.API.MLS.Util (globalTeamConvToConversation)
import Galley.API.Util
import Galley.App
import Galley.Data.Conversation
Expand Down Expand Up @@ -89,6 +90,7 @@ import Wire.API.Event.Conversation
import Wire.API.Federation.API (Component (Galley), fedClient)
import Wire.API.Federation.API.Galley
import Wire.API.Federation.Error
import Wire.API.MLS.GlobalTeamConversation
import Wire.API.Team.LegalHold
import Wire.API.Team.Member
import qualified Wire.API.User as User
Expand Down Expand Up @@ -595,7 +597,17 @@ updateLocalConversation lcnv qusr con action = do
let tag = sing @tag

-- retrieve conversation
conv <- getConversationWithError lcnv (qUnqualified qusr)
conv <- do
-- Check if global or not, if global, map it to conversation
E.getGlobalTeamConversationById lcnv >>= \case
Just gtc ->
let c = gtcCreator gtc
in case c of
Nothing ->
throwS @'ConvNotFound
Just creator ->
pure $ globalTeamConvToConversation gtc creator mempty
Nothing -> getConversationWithError lcnv

-- check that the action does not bypass the underlying protocol
unless (protocolValidAction (convProtocol conv) (fromSing tag)) $
Expand Down
166 changes: 73 additions & 93 deletions services/galley/src/Galley/API/MLS/Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ type MLSMessageStaticErrors =
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient
]
Expand All @@ -123,16 +122,15 @@ postMLSMessageFromLocalUserV1 ::
ErrorS 'ConvAccessDenied,
ErrorS 'ConvMemberNotFound,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
Resource,
Expand All @@ -159,16 +157,15 @@ postMLSMessageFromLocalUser ::
ErrorS 'ConvAccessDenied,
ErrorS 'ConvMemberNotFound,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
Resource,
Expand Down Expand Up @@ -370,16 +367,15 @@ postMLSMessage ::
ErrorS 'ConvAccessDenied,
ErrorS 'ConvMemberNotFound,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSGroupConversationMismatch,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
Resource,
Expand Down Expand Up @@ -459,15 +455,14 @@ postMLSMessageToLocalConv ::
'[ Error FederationError,
Error InternalError,
ErrorS 'ConvNotFound,
ErrorS 'MissingLegalholdConsent,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MLSUnsupportedMessage,
ErrorS 'MissingLegalholdConsent,
ProposalStore,
Resource,
TinyLog
Expand Down Expand Up @@ -544,29 +539,26 @@ postMLSMessageToRemoteConv loc qusr _senderClient con smsg rcnv = do
pure (LocalConversationUpdate e update)

type HasProposalEffects r =
( Members
'[ BrigAccess,
ConversationStore,
Error InternalError,
Error MLSProposalFailure,
Error MLSProtocolError,
ErrorS 'MLSClientMismatch,
ErrorS 'MLSKeyPackageRefNotFound,
ErrorS 'MLSUnsupportedProposal,
ExternalAccess,
FederatorAccess,
GundeckAccess,
Input Env,
Input (Local ()),
Input Opts,
Input UTCTime,
LegalHoldStore,
MemberStore,
ProposalStore,
TeamStore,
TinyLog
]
r
( Member BrigAccess r,
Member ConversationStore r,
Member (Error InternalError) r,
Member (Error MLSProposalFailure) r,
Member (Error MLSProtocolError) r,
Member (ErrorS 'MLSClientMismatch) r,
Member (ErrorS 'MLSKeyPackageRefNotFound) r,
Member (ErrorS 'MLSUnsupportedProposal) r,
Member ExternalAccess r,
Member FederatorAccess r,
Member GundeckAccess r,
Member (Input Env) r,
Member (Input (Local ())) r,
Member (Input Opts) r,
Member (Input UTCTime) r,
Member LegalHoldStore r,
Member MemberStore r,
Member ProposalStore r,
Member TeamStore r,
Member TinyLog r
)

data ProposalAction = ProposalAction
Expand Down Expand Up @@ -624,24 +616,20 @@ getCommitData lconv mlsMeta epoch commit = do

processCommit ::
( HasProposalEffects r,
Members
'[ Error FederationError,
Error InternalError,
ErrorS 'ConvNotFound,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
BrigAccess,
Resource
]
r
Member (Error FederationError) r,
Member (Error InternalError) r,
Member (ErrorS 'ConvNotFound) r,
Member (ErrorS 'MLSClientSenderUserMismatch) r,
Member (ErrorS 'MLSCommitMissingReferences) r,
Member (ErrorS 'MLSMissingSenderClient) r,
Member (ErrorS 'MLSProposalNotFound) r,
Member (ErrorS 'MLSSelfRemovalNotAllowed) r,
Member (ErrorS 'MLSStaleMessage) r,
Member (ErrorS 'MissingLegalholdConsent) r,
Member (Input (Local ())) r,
Member ProposalStore r,
Member BrigAccess r,
Member Resource r
) =>
Qualified UserId ->
Maybe ClientId ->
Expand Down Expand Up @@ -770,24 +758,20 @@ processExternalCommit qusr mSenderClient lconv mlsMeta cm epoch action updatePat
processCommitWithAction ::
forall r.
( HasProposalEffects r,
Members
'[ Error FederationError,
Error InternalError,
ErrorS 'ConvNotFound,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
BrigAccess,
Resource
]
r
Member (Error FederationError) r,
Member (Error InternalError) r,
Member (ErrorS 'ConvNotFound) r,
Member (ErrorS 'MLSClientSenderUserMismatch) r,
Member (ErrorS 'MLSCommitMissingReferences) r,
Member (ErrorS 'MLSMissingSenderClient) r,
Member (ErrorS 'MLSProposalNotFound) r,
Member (ErrorS 'MLSSelfRemovalNotAllowed) r,
Member (ErrorS 'MLSStaleMessage) r,
Member (ErrorS 'MissingLegalholdConsent) r,
Member (Input (Local ())) r,
Member ProposalStore r,
Member BrigAccess r,
Member Resource r
) =>
Qualified UserId ->
Maybe ClientId ->
Expand All @@ -809,24 +793,20 @@ processCommitWithAction qusr senderClient con lconv mlsMeta cm epoch action send
processInternalCommit ::
forall r.
( HasProposalEffects r,
Members
[ Error FederationError,
Error InternalError,
ErrorS 'ConvNotFound,
ErrorS 'MLSClientSenderUserMismatch,
ErrorS 'MLSCommitMissingReferences,
ErrorS 'MLSMissingSenderClient,
ErrorS 'MLSProposalNotFound,
ErrorS 'MLSSelfRemovalNotAllowed,
ErrorS 'MLSStaleMessage,
ErrorS 'MLSUnexpectedSenderClient,
ErrorS 'MissingLegalholdConsent,
Input (Local ()),
ProposalStore,
BrigAccess,
Resource
]
r
Member (Error FederationError) r,
Member (Error InternalError) r,
Member (ErrorS 'ConvNotFound) r,
Member (ErrorS 'MLSClientSenderUserMismatch) r,
Member (ErrorS 'MLSCommitMissingReferences) r,
Member (ErrorS 'MLSMissingSenderClient) r,
Member (ErrorS 'MLSProposalNotFound) r,
Member (ErrorS 'MLSSelfRemovalNotAllowed) r,
Member (ErrorS 'MLSStaleMessage) r,
Member (ErrorS 'MissingLegalholdConsent) r,
Member (Input (Local ())) r,
Member ProposalStore r,
Member BrigAccess r,
Member Resource r
) =>
Qualified UserId ->
Maybe ClientId ->
Expand Down Expand Up @@ -863,9 +843,11 @@ processInternalCommit qusr senderClient con lconv mlsMeta cm epoch action sender
qusr
(Set.singleton (creatorClient, creatorRef))
(Left _, SelfConv, _) ->
-- this is a newly created conversation, and it should contain exactly one
-- client (the creator)
throwS @'MLSUnexpectedSenderClient
throw . InternalErrorWithDescription $
"Unexpected creator client set in a self-conversation"
-- this is a newly created conversation, and it should contain exactly one
-- client (the creator)

(Left _, GlobalTeamConv, []) -> do
creatorClient <- noteS @'MLSMissingSenderClient senderClient
creatorRef <-
Expand All @@ -876,15 +858,13 @@ processInternalCommit qusr senderClient con lconv mlsMeta cm epoch action sender
. upLeaf
)
$ cPath commit
-- add user to global conv as a member as well
lusr <- qualifyLocal (qUnqualified qusr)
void $ createMember (convId <$> lconv) lusr
addMLSClients
(cnvmlsGroupId mlsMeta)
qusr
(Set.singleton (creatorClient, creatorRef))
(Left _, GlobalTeamConv, _) ->
throwS @'MLSUnexpectedSenderClient
throw . InternalErrorWithDescription $
"Unexpected creator client set in a global teamconversation"
(Left lm, _, [(qu, (creatorClient, _))])
| qu == qUntagged (qualifyAs lconv (lmId lm)) -> do
-- use update path as sender reference and if not existing fall back to sender
Expand Down
Loading

0 comments on commit c2e6e77

Please sign in to comment.