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

[WPB-11297] extend team invitations sybsystem #4270

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions libs/wire-subsystems/src/Wire/TeamInvitationSubsystem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import Wire.API.User.EmailAddress

data TeamInvitationSubsystem m a where
InviteUser :: Local UserId -> TeamId -> InvitationRequest -> TeamInvitationSubsystem m (Invitation, InvitationLocation)
AcceptInvitation :: UserId -> InvitationId -> InvitationCode -> TeamInvitationSubsystem m ()
GetInvitationCode :: TeamId -> InvitationId -> TeamInvitationSubsystem m InvitationCode
RevokeInvitation :: TeamId -> InvitationId -> TeamInvitationSubsystem m ()
GetInvitationByCode :: InvitationCode -> TeamInvitationSubsystem m Invitation
GetInvitationByEmail :: EmailAddress -> TeamInvitationSubsystem m Invitation
CheckInvitationsByEmail :: EmailAddress -> TeamInvitationSubsystem m HeadInvitationByEmailResult
DeleteAllInvitationsFor :: TeamId -> TeamInvitationSubsystem m ()
-- | This function exists to support migration in this susbystem, after the
-- migration this would just be an internal detail of the subsystem
InternalCreateInvitation :: TeamId -> Maybe InvitationId -> Role -> Local (Maybe UserId) -> EmailAddress -> InvitationRequest -> TeamInvitationSubsystem m (Invitation, InvitationCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ runTeamInvitationSubsystem ::
InterpreterFor TeamInvitationSubsystem r
runTeamInvitationSubsystem cfg = interpret $ \case
InviteUser luid tid request -> runInputConst cfg $ inviteUserImpl luid tid request
AcceptInvitation uid invitationId invitationCode -> acceptInvitationImpl uid invitationId invitationCode
GetInvitationCode tid iid -> getInvitationCodeImpl tid iid
RevokeInvitation tid invitationId -> revokeInvitationImpl tid invitationId
GetInvitationByCode invitationCode -> getInvitationByCodeImpl invitationCode
GetInvitationByEmail email -> getInvitationByEmailImpl email
CheckInvitationsByEmail email -> checkInvitationsByEmailImpl email
DeleteAllInvitationsFor tid -> deleteAllInvitationsForImpl tid
InternalCreateInvitation tid mExpectedInvId role mbInviterUid inviterEmail invRequest ->
runInputConst cfg $ createInvitation' tid mExpectedInvId role mbInviterUid inviterEmail invRequest

Expand Down Expand Up @@ -241,6 +248,33 @@ logInvitationRequest context action =
. logInvitationCode code
pure res

acceptInvitationImpl :: UserId -> InvitationId -> InvitationCode -> Sem r ()
acceptInvitationImpl = undefined

getInvitationCodeImpl ::
(Member Store.InvitationCodeStore r, Member (Error UserSubsystemError) r) =>
TeamId ->
InvitationId ->
Sem r FoundInvitationCode
getInvitationCodeImpl t r = do
inv <- Store.lookupInvitation t r
maybe (throw UserSubsystemInvalidInvitationCode) (pure . FoundInvitationCode . (.code)) inv

revokeInvitationImpl :: TeamId -> InvitationId -> Sem r ()
revokeInvitationImpl = undefined

getInvitationByCodeImpl :: InvitationCode -> Sem r Invitation
getInvitationByCodeImpl = undefined

getInvitationByEmailImpl :: EmailAddress -> Sem r Invitation
getInvitationByEmailImpl = undefined

checkInvitationsByEmailImpl :: EmailAddress -> Sem r HeadInvitationByEmailResult
checkInvitationsByEmailImpl = undefined

deleteAllInvitationsForImpl :: TeamId -> Sem r ()
deleteAllInvitationsForImpl = undefined

-- | Privilege escalation detection (make sure no `RoleMember` user creates a `RoleOwner`).
--
-- There is some code duplication with 'Galley.API.Teams.ensureNotElevated'.
Expand Down
12 changes: 0 additions & 12 deletions services/brig/src/Brig/Team/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
module Brig.Team.API
( servantAPI,
getInvitationByEmail,
getInvitationCode,
suspendTeam,
unsuspendTeam,
createInvitationViaScim,
Expand Down Expand Up @@ -117,17 +116,6 @@ teamSizePublic uid tid = do
ensurePermissions uid tid [AddTeamMember]
getTeamSize tid

getInvitationCode ::
( Member Store.InvitationCodeStore r,
Member (Error UserSubsystemError) r
) =>
TeamId ->
InvitationId ->
Sem r FoundInvitationCode
getInvitationCode t r = do
inv <- Store.lookupInvitation t r
maybe (throw UserSubsystemInvalidInvitationCode) (pure . FoundInvitationCode . (.code)) inv

data CreateInvitationInviter = CreateInvitationInviter
{ inviterUid :: UserId,
inviterEmail :: EmailAddress
Expand Down
Loading