diff --git a/changelog.d/2-features/WPB-11183 b/changelog.d/2-features/WPB-11183 new file mode 100644 index 00000000000..89b69dd426d --- /dev/null +++ b/changelog.d/2-features/WPB-11183 @@ -0,0 +1 @@ +Welcome email for new team owner. diff --git a/libs/wire-subsystems/src/Wire/EmailSubsystem/Template.hs b/libs/wire-subsystems/src/Wire/EmailSubsystem/Template.hs index ca79185fccc..7c209b2972a 100644 --- a/libs/wire-subsystems/src/Wire/EmailSubsystem/Template.hs +++ b/libs/wire-subsystems/src/Wire/EmailSubsystem/Template.hs @@ -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 @@ -234,5 +234,5 @@ data TeamTemplates = TeamTemplates creatorWelcomeEmail :: !CreatorWelcomeEmailTemplate, memberWelcomeEmail :: !MemberWelcomeEmailTemplate, personalUserMemberWelcomeEmail :: !PersonalUserMemberWelcomeEmailTemplate, - personalUserCreatorWelcomeEmail :: !PersonalUserCreatorWelcomeEmailTemplate + newTeamOwnerWelcomeEmail :: !NewTeamOwnerWelcomeEmailTemplate } diff --git a/services/brig/src/Brig/API/Public.hs b/services/brig/src/Brig/API/Public.hs index 8b3b484e236..ff22f86f8d3 100644 --- a/services/brig/src/Brig/API/Public.hs +++ b/services/brig/src/Brig/API/Public.hs @@ -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 -> diff --git a/services/brig/src/Brig/API/User.hs b/services/brig/src/Brig/API/User.hs index 8c6a2e6fb67..223de6c1fac 100644 --- a/services/brig/src/Brig/API/User.hs +++ b/services/brig/src/Brig/API/User.hs @@ -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) @@ -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 -> @@ -295,7 +297,7 @@ upgradePersonalToTeam luid bNewTeam = do -- send confirmation email for_ (userEmail user) $ \email -> do - sendPersonalUserCreatorWelcomeMail + sendNewTeamOwnerWelcomeEmail email tid bNewTeam.bnuTeam.newTeamName.fromRange diff --git a/services/brig/src/Brig/Team/Email.hs b/services/brig/src/Brig/Team/Email.hs index 441cee5d7bf..e9c22b1f82a 100644 --- a/services/brig/src/Brig/Team/Email.hs +++ b/services/brig/src/Brig/Team/Email.hs @@ -19,8 +19,7 @@ module Brig.Team.Email ( sendMemberWelcomeMail, - sendPersonalUserMemberWelcomeMail, - sendPersonalUserCreatorWelcomeMail, + sendNewTeamOwnerWelcomeEmail, ) where @@ -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 @@ -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 diff --git a/services/brig/src/Brig/Team/Template.hs b/services/brig/src/Brig/Team/Template.hs index 86c409e9f62..713c1555a6f 100644 --- a/services/brig/src/Brig/Team/Template.hs +++ b/services/brig/src/Brig/Team/Template.hs @@ -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