Skip to content

Commit a5f351a

Browse files
committed
[UNVETTED AI SLOP]
1. Wire.API.Team.Member: Removed isFullTeamMember (export + definition) — it was a temporary placeholder for the behavior change. 2. ensureAccessRole (Util.hs): Changed guard from maybe True (not . isFullTeamMember) . snd → isNothing . snd. Collaborators (Just (Left _)) now pass the TeamMemberAccessRole check, just like full members. 3. ensureConversationAccess (Util.hs): Now uses lookupTeamPrincipal instead of internalGetTeamMember + fmap Right, so collaborators get Just (Left _) instead of Nothing and pass the access role check. Added Member TeamCollaboratorsSubsystem r constraint. 4. convLocalMemberships (CreateInternal.hs): Now uses lookupTeamPrincipal for all users. The notTeamMember call is replaced with [uid | (uid, Nothing) <- allUsersWithPrincipal], exempting collaborators from the explicit connection check. 5. checkLocals (Action.hs): Now batch-fetches collaborators via internalGetTeamCollaboratorsWithIds and merges them with team members into the userMembershipMap, so collaborators appear as Just (Left _) and pass the access role check.
1 parent 272c5bc commit a5f351a

6 files changed

Lines changed: 21 additions & 20 deletions

File tree

libs/wire-api/src/Wire/API/Team/Member.hs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ module Wire.API.Team.Member
7474

7575
-- * TeamPrincipal
7676
TeamPrincipal,
77-
isFullTeamMember,
7877
)
7978
where
8079

@@ -667,16 +666,6 @@ collaboratorToTeamPermissions =
667666
-- @Left@ case.
668667
type TeamPrincipal = Either TeamCollaborator TeamMember
669668

670-
-- | True only for full team members, not for collaborators.
671-
-- Used in conversation access-role checks that enforce team-member-only
672-
-- conversations, preserving the invariant that collaborators are not
673-
-- considered equivalent to full members for access control.
674-
--
675-
-- (We probably do not want to discriminate against collaborators in
676-
-- this way, but that's a semantic change for another PR.)
677-
isFullTeamMember :: TeamPrincipal -> Bool
678-
isFullTeamMember = isRight
679-
680669
----------------------------------------------------------------------
681670

682671
makeLenses ''TeamMember'

libs/wire-subsystems/src/Wire/ConversationSubsystem/Action.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ import Wire.Sem.Now qualified as Now
136136
import Wire.Sem.Random (Random)
137137
import Wire.StoredConversation
138138
import Wire.StoredConversation qualified as Data
139+
import Wire.API.Team.Collaborator (TeamCollaborator (..))
139140
import Wire.TeamCollaboratorsSubsystem
140141
import Wire.TeamStore
141142
import Wire.TeamSubsystem (ConsentGiven (..), TeamSubsystem, consentGiven)
@@ -794,8 +795,14 @@ performConversationJoin qusr lconv (ConversationJoin invited role joinType) = do
794795
tms <-
795796
Map.fromList . map (view Wire.API.Team.Member.userId &&& Imports.id)
796797
<$> TeamSubsystem.internalSelectTeamMembers tid newUsers
797-
let userMembershipMap = map (Imports.id &&& (fmap Right . flip Map.lookup tms)) newUsers
798-
in ensureAccessRole (convAccessRoles conv) userMembershipMap
798+
collabs <-
799+
Map.fromList . map (\c -> (c.gUser, c))
800+
<$> internalGetTeamCollaboratorsWithIds (Set.singleton tid) (Set.fromList newUsers)
801+
let principalFor uid =
802+
fmap Right (Map.lookup uid tms)
803+
<|> fmap Left (Map.lookup uid collabs)
804+
userMembershipMap = map (Imports.id &&& principalFor) newUsers
805+
ensureAccessRole (convAccessRoles conv) userMembershipMap
799806
ensureConnectedToLocalsOrSameTeam lusr newUsers
800807
checkLocals lusr Nothing newUsers = do
801808
ensureAccessRole (convAccessRoles conv) (map (,Nothing) newUsers)

libs/wire-subsystems/src/Wire/ConversationSubsystem/CreateInternal.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import Wire.API.Team
5555
import Wire.API.Team.Collaborator qualified as CollaboratorPermission
5656
import Wire.API.Team.Feature
5757
import Wire.API.Team.Feature qualified as Conf
58-
import Wire.API.Team.FeatureFlags (notTeamMember)
5958
import Wire.API.Team.LegalHold (LegalholdProtectee (LegalholdPlusFederationNotImplemented))
6059
import Wire.API.Team.Member
6160
import Wire.API.Team.Permission hiding (self)
@@ -343,9 +342,10 @@ checkCreateConvPermissions lusr newConv (Just tinfo) allUsers = do
343342
GroupConversation -> checkGroup
344343
MeetingConversation -> checkGroup
345344

346-
convLocalMemberships <- mapM (flip TeamSubsystem.internalGetTeamMember convTeam) (ulLocals allUsers)
347-
ensureAccessRole (accessRoles newConv) (zip (ulLocals allUsers) (fmap (fmap Right) convLocalMemberships))
348-
ensureConnectedToLocals (tUnqualified lusr) (notTeamMember (ulLocals allUsers) (catMaybes convLocalMemberships))
345+
convLocalMemberships <- mapM (TeamSubsystem.lookupTeamPrincipal convTeam) (ulLocals allUsers)
346+
let allUsersWithPrincipal = zip (ulLocals allUsers) convLocalMemberships
347+
ensureAccessRole (accessRoles newConv) allUsersWithPrincipal
348+
ensureConnectedToLocals (tUnqualified lusr) [uid | (uid, Nothing) <- allUsersWithPrincipal]
349349
ensureConnectedToRemotes lusr (ulRemotes allUsers)
350350
where
351351
ensureCreateChannelPermissions ::

libs/wire-subsystems/src/Wire/ConversationSubsystem/Query.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ getConversationByReusableCode ::
648648
Member FeaturesConfigSubsystem r,
649649
Member HashPassword r,
650650
Member RateLimit r,
651+
Member TeamCollaboratorsSubsystem r,
651652
Member TeamSubsystem r
652653
) =>
653654
Local UserId ->

libs/wire-subsystems/src/Wire/ConversationSubsystem/Update.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ joinConversationByReusableCode ::
741741
Member FeaturesConfigSubsystem r,
742742
Member HashPassword r,
743743
Member RateLimit r,
744+
Member TeamCollaboratorsSubsystem r,
744745
Member TeamSubsystem r,
745746
Member Now r,
746747
Member (Input ConversationSubsystemConfig) r
@@ -770,6 +771,7 @@ joinConversationById ::
770771
Member NotificationSubsystem r,
771772
Member E.ExternalAccess r,
772773
Member Now r,
774+
Member TeamCollaboratorsSubsystem r,
773775
Member TeamSubsystem r
774776
) =>
775777
Local UserId ->
@@ -794,6 +796,7 @@ joinConversation ::
794796
Member ConversationStore r,
795797
Member Now r,
796798
Member NotificationSubsystem r,
799+
Member TeamCollaboratorsSubsystem r,
797800
Member TeamSubsystem r
798801
) =>
799802
Local UserId ->

libs/wire-subsystems/src/Wire/ConversationSubsystem/Util.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ ensureAccessRole ::
120120
ensureAccessRole roles users = do
121121
when (Set.null roles) $ throwS @'ConvAccessDenied
122122
unless (NonTeamMemberAccessRole `Set.member` roles) $
123-
when (any (maybe True (not . isFullTeamMember) . snd) users) $
123+
when (any (isNothing . snd) users) $
124124
throwS @'NotATeamMember
125125
unless (Set.fromList [GuestAccessRole, ServiceAccessRole] `Set.isSubsetOf` roles) $ do
126126
activated <- lookupActivatedUsers (fst <$> users)
@@ -676,6 +676,7 @@ ensureConversationAccess ::
676676
( Member BrigAPIAccess r,
677677
Member (ErrorS 'ConvAccessDenied) r,
678678
Member (ErrorS 'NotATeamMember) r,
679+
Member TeamCollaboratorsSubsystem r,
679680
Member TeamSubsystem r
680681
) =>
681682
UserId ->
@@ -684,8 +685,8 @@ ensureConversationAccess ::
684685
Sem r ()
685686
ensureConversationAccess zusr conv access = do
686687
ensureAccess conv access
687-
zusrMembership <- maybe (pure Nothing) (TeamSubsystem.internalGetTeamMember zusr) (Data.convTeam conv)
688-
ensureAccessRole (Data.convAccessRoles conv) [(zusr, fmap Right zusrMembership)]
688+
zusrPrincipal <- maybe (pure Nothing) (\tid -> TeamSubsystem.lookupTeamPrincipal tid zusr) (Data.convTeam conv)
689+
ensureAccessRole (Data.convAccessRoles conv) [(zusr, zusrPrincipal)]
689690

690691
ensureAccess ::
691692
(Member (ErrorS 'ConvAccessDenied) r) =>

0 commit comments

Comments
 (0)