Skip to content

Commit

Permalink
WPB-11183 confirmation email after team creation and account migratio…
Browse files Browse the repository at this point in the history
…n of the team owner (#4333)
  • Loading branch information
battermann authored Nov 7, 2024
1 parent a63c044 commit 4877997
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelog.d/2-features/WPB-11183
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Welcome email for new team owner.
16 changes: 8 additions & 8 deletions libs/wire-subsystems/src/Wire/EmailSubsystem/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ data PersonalUserMemberWelcomeEmailTemplate = PersonalUserMemberWelcomeEmailTemp
personalUserMemberWelcomeEmailSenderName :: !Text
}

data PersonalUserCreatorWelcomeEmailTemplate = PersonalUserCreatorWelcomeEmailTemplate
{ personalUserCreatorWelcomeEmailUrl :: !Text,
personalUserCreatorWelcomeEmailSubject :: !Template,
personalUserCreatorWelcomeEmailBodyText :: !Template,
personalUserCreatorWelcomeEmailBodyHtml :: !Template,
personalUserCreatorWelcomeEmailSender :: !EmailAddress,
personalUserCreatorWelcomeEmailSenderName :: !Text
data NewTeamOwnerWelcomeEmailTemplate = NewTeamOwnerWelcomeEmailTemplate
{ newTeamOwnerWelcomeEmailUrl :: !Text,
newTeamOwnerWelcomeEmailSubject :: !Template,
newTeamOwnerWelcomeEmailBodyText :: !Template,
newTeamOwnerWelcomeEmailBodyHtml :: !Template,
newTeamOwnerWelcomeEmailSender :: !EmailAddress,
newTeamOwnerWelcomeEmailSenderName :: !Text
}

data TeamTemplates = TeamTemplates
Expand All @@ -234,5 +234,5 @@ data TeamTemplates = TeamTemplates
creatorWelcomeEmail :: !CreatorWelcomeEmailTemplate,
memberWelcomeEmail :: !MemberWelcomeEmailTemplate,
personalUserMemberWelcomeEmail :: !PersonalUserMemberWelcomeEmailTemplate,
personalUserCreatorWelcomeEmail :: !PersonalUserCreatorWelcomeEmailTemplate
newTeamOwnerWelcomeEmail :: !NewTeamOwnerWelcomeEmailTemplate
}
3 changes: 2 additions & 1 deletion services/brig/src/Brig/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ upgradePersonalToTeam ::
Member NotificationSubsystem r,
Member TinyLog r,
Member UserSubsystem r,
Member UserStore r
Member UserStore r,
Member EmailSending r
) =>
Local UserId ->
Public.BindingNewTeamUser ->
Expand Down
6 changes: 4 additions & 2 deletions services/brig/src/Brig/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import Wire.ActivationCodeStore qualified as ActivationCode
import Wire.AuthenticationSubsystem (AuthenticationSubsystem, internalLookupPasswordResetCode)
import Wire.BlockListStore as BlockListStore
import Wire.DeleteQueue
import Wire.EmailSending
import Wire.EmailSubsystem
import Wire.Error
import Wire.Events (Events)
Expand Down Expand Up @@ -263,7 +264,8 @@ upgradePersonalToTeam ::
Member NotificationSubsystem r,
Member (Input (Local ())) r,
Member (Input UTCTime) r,
Member (ConnectionStore InternalPaging) r
Member (ConnectionStore InternalPaging) r,
Member EmailSending r
) =>
Local UserId ->
BindingNewTeamUser ->
Expand Down Expand Up @@ -295,7 +297,7 @@ upgradePersonalToTeam luid bNewTeam = do

-- send confirmation email
for_ (userEmail user) $ \email -> do
sendPersonalUserCreatorWelcomeMail
sendNewTeamOwnerWelcomeEmail
email
tid
bNewTeam.bnuTeam.newTeamName.fromRange
Expand Down
40 changes: 31 additions & 9 deletions services/brig/src/Brig/Team/Email.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

module Brig.Team.Email
( sendMemberWelcomeMail,
sendPersonalUserMemberWelcomeMail,
sendPersonalUserCreatorWelcomeMail,
sendNewTeamOwnerWelcomeEmail,
)
where

Expand All @@ -41,13 +40,11 @@ sendMemberWelcomeMail to tid teamName loc = do
branding <- asks (.templateBranding)
liftSem $ sendMail $ renderMemberWelcomeMail to tid teamName tpl branding

sendPersonalUserMemberWelcomeMail :: EmailAddress -> TeamId -> Text -> Maybe Locale -> (AppT r) ()
sendPersonalUserMemberWelcomeMail _ _ _ _ = do
pure ()

sendPersonalUserCreatorWelcomeMail :: EmailAddress -> TeamId -> Text -> Maybe Locale -> (AppT r) ()
sendPersonalUserCreatorWelcomeMail _ _ _ _ = do
pure ()
sendNewTeamOwnerWelcomeEmail :: (Member EmailSending r) => EmailAddress -> TeamId -> Text -> Maybe Locale -> (AppT r) ()
sendNewTeamOwnerWelcomeEmail to tid teamName loc = do
tpl <- newTeamOwnerWelcomeEmail . snd <$> teamTemplatesWithLocale loc
branding <- asks (.templateBranding)
liftSem $ sendMail $ renderNewTeamOwnerWelcomeEmail to tid teamName tpl branding

-------------------------------------------------------------------------------
-- Member Welcome Email
Expand All @@ -73,3 +70,28 @@ renderMemberWelcomeMail emailTo tid teamName MemberWelcomeEmailTemplate {..} bra
replace "team_id" = idToText tid
replace "team_name" = teamName
replace x = x

-------------------------------------------------------------------------------
-- New Team Owner Welcome Email

renderNewTeamOwnerWelcomeEmail :: EmailAddress -> TeamId -> Text -> NewTeamOwnerWelcomeEmailTemplate -> TemplateBranding -> Mail
renderNewTeamOwnerWelcomeEmail emailTo tid teamName NewTeamOwnerWelcomeEmailTemplate {..} branding =
(emptyMail from)
{ mailTo = [to],
mailHeaders =
[ ("Subject", toStrict subj),
("X-Zeta-Purpose", "Welcome")
],
mailParts = [[plainPart txt, htmlPart html]]
}
where
from = Address (Just newTeamOwnerWelcomeEmailSenderName) (fromEmail newTeamOwnerWelcomeEmailSender)
to = Address Nothing (fromEmail emailTo)
txt = renderTextWithBranding newTeamOwnerWelcomeEmailBodyText replace branding
html = renderHtmlWithBranding newTeamOwnerWelcomeEmailBodyHtml replace branding
subj = renderTextWithBranding newTeamOwnerWelcomeEmailSubject replace branding
replace "url" = newTeamOwnerWelcomeEmailUrl
replace "email" = fromEmail emailTo
replace "team_id" = idToText tid
replace "team_name" = teamName
replace x = x
13 changes: 6 additions & 7 deletions services/brig/src/Brig/Team/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ loadTeamTemplates o = readLocalesDir defLocale (templateDir gOptions) "team" $ \
(emailSender gOptions)
<$> readText fp "email/sender.txt"
)
<*> ( PersonalUserCreatorWelcomeEmailTemplate
""
(template "")
(template "")
(template "")
(emailSender gOptions)
<$> readText fp "email/sender.txt"
<*> ( NewTeamOwnerWelcomeEmailTemplate (tCreatorWelcomeUrl tOptions)
<$> readTemplate fp "email/new-team-owner-welcome-subject.txt"
<*> readTemplate fp "email/new-team-owner-welcome.txt"
<*> readTemplate fp "email/new-team-owner-welcome.html"
<*> pure (emailSender gOptions)
<*> readText fp "email/sender.txt"
)
where
gOptions = o.emailSMS.general
Expand Down

0 comments on commit 4877997

Please sign in to comment.