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-11183 Remove wrong templates and make email sending no op #4315

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
2 changes: 1 addition & 1 deletion changelog.d/2-features/WPB-10658
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Allow an existing non-team user to migrate to a team (#4229, ##)
Allow an existing non-team user to migrate to a team (#4229, #4268, #4315)
1 change: 0 additions & 1 deletion libs/wire-subsystems/src/Wire/EmailSubsystem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ data EmailSubsystem m a where
SendAccountDeletionEmail :: EmailAddress -> Name -> Code.Key -> Code.Value -> Locale -> EmailSubsystem m ()
SendTeamActivationMail :: EmailAddress -> Name -> ActivationKey -> ActivationCode -> Maybe Locale -> Text -> EmailSubsystem m ()
SendTeamDeletionVerificationMail :: EmailAddress -> Code.Value -> Maybe Locale -> EmailSubsystem m ()
SendUpgradePersonalToTeamConfirmationEmail :: EmailAddress -> Name -> Text -> Locale -> EmailSubsystem m ()
-- | send invitation to an unknown email address.
SendTeamInvitationMail :: EmailAddress -> TeamId -> EmailAddress -> InvitationCode -> Maybe Locale -> EmailSubsystem m Text
-- | send invitation to an email address associated with a personal user account.
Expand Down
37 changes: 0 additions & 37 deletions libs/wire-subsystems/src/Wire/EmailSubsystem/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ emailSubsystemInterpreter userTpls teamTpls branding = interpret \case
SendTeamActivationMail email name key code mLocale teamName -> sendTeamActivationMailImpl userTpls branding email name key code mLocale teamName
SendNewClientEmail email name client locale -> sendNewClientEmailImpl userTpls branding email name client locale
SendAccountDeletionEmail email name key code locale -> sendAccountDeletionEmailImpl userTpls branding email name key code locale
SendUpgradePersonalToTeamConfirmationEmail email name teamName locale -> sendUpgradePersonalToTeamConfirmationEmailImpl userTpls branding email name teamName locale
SendTeamInvitationMail email tid from code loc -> sendTeamInvitationMailImpl teamTpls branding email tid from code loc
SendTeamInvitationMailPersonalUser email tid from code loc -> sendTeamInvitationMailPersonalUserImpl teamTpls branding email tid from code loc

Expand Down Expand Up @@ -399,42 +398,6 @@ renderDeletionEmail email name cKey cValue DeletionEmailTemplate {..} branding =
replace2 "code" = code
replace2 x = x

--------------------------------------------------------------------------------
-- Upgrade personal user to team owner confirmation email

sendUpgradePersonalToTeamConfirmationEmailImpl ::
(Member EmailSending r) =>
Localised UserTemplates ->
TemplateBranding ->
EmailAddress ->
Name ->
Text ->
Locale ->
Sem r ()
sendUpgradePersonalToTeamConfirmationEmailImpl userTemplates branding email name teamName locale = do
let tpl = upgradePersonalToTeamEmail . snd $ forLocale (Just locale) userTemplates
sendMail $ renderUpgradePersonalToTeamConfirmationEmail email name teamName tpl branding

renderUpgradePersonalToTeamConfirmationEmail :: EmailAddress -> Name -> Text -> UpgradePersonalToTeamEmailTemplate -> TemplateBranding -> Mail
renderUpgradePersonalToTeamConfirmationEmail email name _teamName UpgradePersonalToTeamEmailTemplate {..} branding =
(emptyMail from)
{ mailTo = [to],
mailHeaders =
[ ("Subject", toStrict subj),
("X-Zeta-Purpose", "Upgrade")
],
mailParts = [[plainPart txt, htmlPart html]]
}
where
from = Address (Just upgradePersonalToTeamEmailSenderName) (fromEmail upgradePersonalToTeamEmailSender)
to = mkMimeAddress name email
txt = renderTextWithBranding upgradePersonalToTeamEmailBodyText replace1 branding
html = renderHtmlWithBranding upgradePersonalToTeamEmailBodyHtml replace1 branding
subj = renderTextWithBranding upgradePersonalToTeamEmailSubject replace1 branding
replace1 "email" = fromEmail email
replace1 "name" = fromName name
replace1 x = x

-------------------------------------------------------------------------------
-- Invitation Email

Expand Down
31 changes: 21 additions & 10 deletions libs/wire-subsystems/src/Wire/EmailSubsystem/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ data UserTemplates = UserTemplates
loginCall :: LoginCallTemplate,
deletionSms :: DeletionSmsTemplate,
deletionEmail :: DeletionEmailTemplate,
upgradePersonalToTeamEmail :: UpgradePersonalToTeamEmailTemplate,
newClientEmail :: NewClientEmailTemplate,
verificationLoginEmail :: SecondFactorVerificationEmailTemplate,
verificationScimTokenEmail :: SecondFactorVerificationEmailTemplate,
Expand Down Expand Up @@ -138,14 +137,6 @@ data DeletionEmailTemplate = DeletionEmailTemplate
deletionEmailSenderName :: Text
}

data UpgradePersonalToTeamEmailTemplate = UpgradePersonalToTeamEmailTemplate
{ upgradePersonalToTeamEmailSubject :: Template,
upgradePersonalToTeamEmailBodyText :: Template,
upgradePersonalToTeamEmailBodyHtml :: Template,
upgradePersonalToTeamEmailSender :: EmailAddress,
upgradePersonalToTeamEmailSenderName :: Text
}

data PasswordResetEmailTemplate = PasswordResetEmailTemplate
{ passwordResetEmailUrl :: Template,
passwordResetEmailSubject :: Template,
Expand Down Expand Up @@ -219,9 +210,29 @@ data MemberWelcomeEmailTemplate = MemberWelcomeEmailTemplate
memberWelcomeEmailSenderName :: !Text
}

data PersonalUserMemberWelcomeEmailTemplate = PersonalUserMemberWelcomeEmailTemplate
{ personalUserMemberWelcomeEmailUrl :: !Text,
personalUserMemberWelcomeEmailSubject :: !Template,
personalUserMemberWelcomeEmailBodyText :: !Template,
personalUserMemberWelcomeEmailBodyHtml :: !Template,
personalUserMemberWelcomeEmailSender :: !EmailAddress,
personalUserMemberWelcomeEmailSenderName :: !Text
}

data PersonalUserCreatorWelcomeEmailTemplate = PersonalUserCreatorWelcomeEmailTemplate
{ personalUserCreatorWelcomeEmailUrl :: !Text,
personalUserCreatorWelcomeEmailSubject :: !Template,
personalUserCreatorWelcomeEmailBodyText :: !Template,
personalUserCreatorWelcomeEmailBodyHtml :: !Template,
personalUserCreatorWelcomeEmailSender :: !EmailAddress,
personalUserCreatorWelcomeEmailSenderName :: !Text
}

data TeamTemplates = TeamTemplates
{ invitationEmail :: !InvitationEmailTemplate,
existingUserInvitationEmail :: !InvitationEmailTemplate,
creatorWelcomeEmail :: !CreatorWelcomeEmailTemplate,
memberWelcomeEmail :: !MemberWelcomeEmailTemplate
memberWelcomeEmail :: !MemberWelcomeEmailTemplate,
personalUserMemberWelcomeEmail :: !PersonalUserMemberWelcomeEmailTemplate,
personalUserCreatorWelcomeEmail :: !PersonalUserCreatorWelcomeEmailTemplate
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ noopEmailSubsystemInterpreter = interpret \case
SendAccountDeletionEmail {} -> pure ()
SendTeamActivationMail {} -> pure ()
SendTeamDeletionVerificationMail {} -> pure ()
SendUpgradePersonalToTeamConfirmationEmail {} -> pure ()
SendTeamInvitationMail {} -> pure ""
SendTeamInvitationMailPersonalUser {} -> pure ""

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions services/brig/deb/opt/brig/templates/en/user/email/upgrade.txt

This file was deleted.

1 change: 0 additions & 1 deletion services/brig/src/Brig/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ createAccessToken method luid cid proof = do
upgradePersonalToTeam ::
( Member (ConnectionStore InternalPaging) r,
Member (Embed HttpClientIO) r,
Member EmailSubsystem r,
Member GalleyAPIAccess r,
Member (Input (Local ())) r,
Member (Input UTCTime) r,
Expand Down
13 changes: 6 additions & 7 deletions services/brig/src/Brig/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import Brig.Effects.UserPendingActivationStore (UserPendingActivation (..), User
import Brig.Effects.UserPendingActivationStore qualified as UserPendingActivationStore
import Brig.IO.Intra qualified as Intra
import Brig.Options hiding (internalEvents)
import Brig.Team.Email
import Brig.Types.Activation (ActivationPair)
import Brig.Types.Intra
import Brig.User.Auth.Cookie qualified as Auth
Expand Down Expand Up @@ -258,7 +259,6 @@ createUserSpar new = do
upgradePersonalToTeam ::
forall r.
( Member GalleyAPIAccess r,
Member EmailSubsystem r,
Member UserStore r,
Member UserSubsystem r,
Member TinyLog r,
Expand Down Expand Up @@ -298,12 +298,11 @@ upgradePersonalToTeam luid bNewTeam = do

-- send confirmation email
for_ (userEmail user) $ \email -> do
liftSem $
sendUpgradePersonalToTeamConfirmationEmail
email
user.userDisplayName
bNewTeam.bnuTeam.newTeamName.fromRange
user.userLocale
sendPersonalUserCreatorWelcomeMail
email
tid
bNewTeam.bnuTeam.newTeamName.fromRange
(Just user.userLocale)

pure $! createUserTeam

Expand Down
42 changes: 17 additions & 25 deletions services/brig/src/Brig/Team/Email.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
-- with this program. If not, see <https://www.gnu.org/licenses/>.

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

Expand All @@ -33,35 +33,27 @@ import Network.Mail.Mime
import Polysemy
import Wire.API.User
import Wire.EmailSending
import Wire.EmailSubsystem.Template (TemplateBranding, renderHtmlWithBranding, renderTextWithBranding)
import Wire.EmailSubsystem.Template

sendMemberWelcomeMail :: (Member EmailSending r) => EmailAddress -> TeamId -> Text -> Maybe Locale -> (AppT r) ()
sendMemberWelcomeMail to tid teamName loc = do
tpl <- memberWelcomeEmail . snd <$> teamTemplatesWithLocale loc
branding <- asks (.templateBranding)
let mail = MemberWelcomeEmail to tid teamName
liftSem $ sendMail $ renderMemberWelcomeMail mail tpl branding
liftSem $ sendMail $ renderMemberWelcomeMail to tid teamName tpl branding

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

data CreatorWelcomeEmail = CreatorWelcomeEmail
{ cwTo :: !EmailAddress,
cwTid :: !TeamId,
cwTeamName :: !Text
}
sendPersonalUserCreatorWelcomeMail :: EmailAddress -> TeamId -> Text -> Maybe Locale -> (AppT r) ()
sendPersonalUserCreatorWelcomeMail _ _ _ _ = do
pure ()

-------------------------------------------------------------------------------
-- Member Welcome Email

data MemberWelcomeEmail = MemberWelcomeEmail
{ mwTo :: !EmailAddress,
mwTid :: !TeamId,
mwTeamName :: !Text
}

renderMemberWelcomeMail :: MemberWelcomeEmail -> MemberWelcomeEmailTemplate -> TemplateBranding -> Mail
renderMemberWelcomeMail MemberWelcomeEmail {..} MemberWelcomeEmailTemplate {..} branding =
renderMemberWelcomeMail :: EmailAddress -> TeamId -> Text -> MemberWelcomeEmailTemplate -> TemplateBranding -> Mail
renderMemberWelcomeMail emailTo tid teamName MemberWelcomeEmailTemplate {..} branding =
(emptyMail from)
{ mailTo = [to],
mailHeaders =
Expand All @@ -72,12 +64,12 @@ renderMemberWelcomeMail MemberWelcomeEmail {..} MemberWelcomeEmailTemplate {..}
}
where
from = Address (Just memberWelcomeEmailSenderName) (fromEmail memberWelcomeEmailSender)
to = Address Nothing (fromEmail mwTo)
to = Address Nothing (fromEmail emailTo)
txt = renderTextWithBranding memberWelcomeEmailBodyText replace branding
html = renderHtmlWithBranding memberWelcomeEmailBodyHtml replace branding
subj = renderTextWithBranding memberWelcomeEmailSubject replace branding
replace "url" = memberWelcomeEmailUrl
replace "email" = fromEmail mwTo
replace "team_id" = idToText mwTid
replace "team_name" = mwTeamName
replace "email" = fromEmail emailTo
replace "team_id" = idToText tid
replace "team_name" = teamName
replace x = x
16 changes: 16 additions & 0 deletions services/brig/src/Brig/Team/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ loadTeamTemplates o = readLocalesDir defLocale (templateDir gOptions) "team" $ \
<*> pure (emailSender gOptions)
<*> readText fp "email/sender.txt"
)
<*> ( PersonalUserMemberWelcomeEmailTemplate
""
(template "")
(template "")
(template "")
(emailSender gOptions)
<$> readText fp "email/sender.txt"
)
<*> ( PersonalUserCreatorWelcomeEmailTemplate
""
(template "")
(template "")
(template "")
(emailSender gOptions)
<$> readText fp "email/sender.txt"
)
where
gOptions = o.emailSMS.general
tOptions = o.emailSMS.team
Expand Down
8 changes: 0 additions & 8 deletions services/brig/src/Brig/User/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module Brig.User.Template
LoginCallTemplate (..),
DeletionSmsTemplate (..),
DeletionEmailTemplate (..),
UpgradePersonalToTeamEmailTemplate (..),
NewClientEmailTemplate (..),
SecondFactorVerificationEmailTemplate (..),
loadUserTemplates,
Expand Down Expand Up @@ -110,13 +109,6 @@ loadUserTemplates o = readLocalesDir defLocale templateDir "user" $ \fp ->
<*> pure emailSender
<*> readText fp "email/sender.txt"
)
<*> ( UpgradePersonalToTeamEmailTemplate
<$> readTemplate fp "email/upgrade-subject.txt"
<*> readTemplate fp "email/upgrade.txt"
<*> readTemplate fp "email/upgrade.html"
<*> pure emailSender
<*> readText fp "email/sender.txt"
)
<*> ( NewClientEmailTemplate
<$> readTemplate fp "email/new-client-subject.txt"
<*> readTemplate fp "email/new-client.txt"
Expand Down
Loading