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

MLS conversation limits #3468

Merged
merged 4 commits into from
Aug 3, 2023
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/2-features/mls-conv-limits
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove conversation size limit for MLS conversations
7 changes: 6 additions & 1 deletion hack/python/wire/mlscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ def mlscli(state, client_identity, args, stdin=None):
else:
args_substd.append(arg)

basedir = os.path.join(cdir, cid2str(state.client_identity) )
os.makedirs(basedir, exist_ok=True)
all_args = [
"mls-test-cli",
"--store",
os.path.join(cdir, cid2str(state.client_identity), "store"),
os.path.join(basedir, "store"),
] + args_substd

# TODO: maybe add cwd=cdir, not sure if necessary
Expand Down Expand Up @@ -154,6 +156,9 @@ def restore_backup_into(client_dir):
os.system(f'cp -r /tmp/client_state_backup {client_dir}')
return ClientState.load(client_dir)

def __repr__(self):
values = ', '.join(f'{k}={str(getattr(self, k))}' for k in self.saveable_attrs.keys())
return f'{self.__class__.__name__}({values})'

def key_package_file(state, ref):
return os.path.join(state.client_dir, cid2str(state.client_identity), ref.hex())
Expand Down
3 changes: 1 addition & 2 deletions libs/wire-api/src/Wire/API/Team/Member.hs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ instance ToSchema (TeamMember' tag) => ToSchema (TeamMemberList' tag) where
<*> _teamMemberListType
.= fieldWithDocModifier "hasMore" (description ?~ "true if 'members' doesn't contain all team members") schema

-- TODO: Revert this to 2000 before mergin 'mls' to the develop branch
type HardTruncationLimit = (100000 :: Nat)
type HardTruncationLimit = (2000 :: Nat)

hardTruncationLimit :: Integral a => a
hardTruncationLimit = fromIntegral $ natVal (Proxy @HardTruncationLimit)
Expand Down
4 changes: 2 additions & 2 deletions services/galley/src/Galley/API/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Galley.API.Teams.Features.Get
import Galley.API.Util
import Galley.Data.Conversation
import qualified Galley.Data.Conversation as Data
import Galley.Data.Conversation.Types (mlsMetadata)
import Galley.Data.Conversation.Types
import Galley.Data.Scope (Scope (ReusableCode))
import Galley.Data.Services
import Galley.Effects
Expand Down Expand Up @@ -455,7 +455,7 @@ performConversationJoin qusr lconv (ConversationJoin invited role) = do
let newMembers = ulNewMembers lconv conv . toUserList lconv $ invited

lusr <- ensureLocal lconv qusr
ensureMemberLimit (toList (convLocalMembers conv)) newMembers
ensureMemberLimit (convProtocolTag conv) (toList (convLocalMembers conv)) newMembers
ensureAccess conv InviteAccess
checkLocals lusr (convTeam conv) (ulLocals newMembers)
checkRemotes lusr (ulRemotes newMembers)
Expand Down
5 changes: 3 additions & 2 deletions services/galley/src/Galley/API/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import qualified Galley.API.Query as Query
import Galley.API.Util
import Galley.App
import qualified Galley.Data.Conversation as Data
import qualified Galley.Data.Conversation.Types as Data
import Galley.Data.Services as Data
import Galley.Data.Types hiding (Conversation)
import Galley.Effects
Expand Down Expand Up @@ -804,7 +805,7 @@ joinConversation lusr zcon conv access = do
ensureConversationAccess (tUnqualified lusr) conv access
ensureGroupConversation conv
-- FUTUREWORK: remote users?
ensureMemberLimit (toList $ Data.convLocalMembers conv) [tUnqualified lusr]
ensureMemberLimit (Data.convProtocolTag conv) (toList $ Data.convLocalMembers conv) [tUnqualified lusr]
getUpdateResult $ do
-- NOTE: When joining conversations, all users become members
-- as this is our desired behavior for these types of conversations
Expand Down Expand Up @@ -1597,7 +1598,7 @@ addBot lusr zcon b = do
ensureActionAllowed SAddConversationMember self
unless (any ((== b ^. addBotId) . botMemId) bots) $ do
let botId = qualifyAs lusr (botUserId (b ^. addBotId))
ensureMemberLimit (toList $ Data.convLocalMembers c) [tUntagged botId]
ensureMemberLimit (Data.convProtocolTag c) (toList $ Data.convLocalMembers c) [tUntagged botId]
pure (bots, users)

rmBotH ::
Expand Down
11 changes: 6 additions & 5 deletions services/galley/src/Galley/API/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Galley.Effects.MemberStore
import Galley.Effects.TeamStore
import Galley.Intra.Push
import Galley.Options
import Galley.Types.Conversations.Members (LocalMember (..), RemoteMember (..), localMemberToOther, remoteMemberQualify, remoteMemberToOther)
import Galley.Types.Conversations.Members
import Galley.Types.Conversations.Roles
import Galley.Types.Teams
import Galley.Types.UserList
Expand Down Expand Up @@ -84,8 +84,7 @@ import Wire.API.Routes.Public.Galley.Conversation
import Wire.API.Routes.Public.Util
import Wire.API.Team.Member
import Wire.API.Team.Role
import Wire.API.User (VerificationAction)
import qualified Wire.API.User as User
import Wire.API.User hiding (userId)
import Wire.API.User.Auth.ReAuth

type JSON = Media "application" "json"
Expand All @@ -107,7 +106,7 @@ ensureAccessRole roles users = do
activated <- lookupActivatedUsers (fst <$> users)
let guestsExist = length activated /= length users
unless (not guestsExist || GuestAccessRole `Set.member` roles) $ throwS @'ConvAccessDenied
let botsExist = any (isJust . User.userService) activated
let botsExist = any (isJust . userService) activated
unless (not botsExist || ServiceAccessRole `Set.member` roles) $ throwS @'ConvAccessDenied

-- | Check that the given user is either part of the same team as the other
Expand Down Expand Up @@ -995,10 +994,12 @@ ensureMemberLimit ::
Member (Input Opts) r
)
) =>
ProtocolTag ->
[LocalMember] ->
f a ->
Sem r ()
ensureMemberLimit old new = do
ensureMemberLimit ProtocolMLSTag _ _ = pure ()
ensureMemberLimit _ old new = do
o <- input
let maxSize = fromIntegral (o ^. optSettings . setMaxConvSize)
when (length old + length new > maxSize) $
Expand Down
3 changes: 3 additions & 0 deletions services/galley/src/Galley/Data/Conversation/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ data Conversation = Conversation
}
deriving (Show)

convProtocolTag :: Conversation -> ProtocolTag
convProtocolTag = protocolTag . convProtocol

data NewConversation = NewConversation
{ ncMetadata :: ConversationMetadata,
ncUsers :: UserList (UserId, RoleName),
Expand Down