From 734c6a6876d6093684a8590233b33b8970c09f18 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 23 Apr 2019 18:58:41 +0200 Subject: [PATCH] Latest fixes for emails. --- .../Apps/Invitation/InvitationEmailEventConsumer.cs | 4 +--- .../Apps/Invitation/InvitationEmailSender.cs | 6 +++--- .../Apps/Invitation/InviteUserCommandMiddleware.cs | 2 +- src/Squidex.Infrastructure/Email/IEmailSender.cs | 2 +- src/Squidex/appsettings.json | 4 ++-- .../Apps/Invitation/InvitationEmailEventConsumerTests.cs | 8 ++++---- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailEventConsumer.cs b/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailEventConsumer.cs index 35fa0e12f..01211fcd2 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailEventConsumer.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailEventConsumer.cs @@ -60,9 +60,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation return; } - if (@event.Payload is AppContributorAssigned appContributorAssigned && - appContributorAssigned.IsCreated && - appContributorAssigned.Actor.IsSubject) + if (@event.Payload is AppContributorAssigned appContributorAssigned && appContributorAssigned.Actor.IsSubject) { var assignerId = appContributorAssigned.Actor.Identifier; var assigneeId = appContributorAssigned.ContributorId; diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailSender.cs b/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailSender.cs index c4ad43977..21ffd7c0b 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailSender.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailSender.cs @@ -45,7 +45,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation public Task SendExistingUserEmailAsync(IUser assigner, IUser assignee, string appName) { - return SendEmailAsync(texts.ExistingUserBody, texts.ExistingUserSubject, assigner, assignee, appName); + return SendEmailAsync(texts.ExistingUserSubject, texts.ExistingUserBody, assigner, assignee, appName); } public Task SendNewUserEmailAsync(IUser assigner, IUser assignee, string appName) @@ -87,8 +87,6 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation { text = text.Replace("$APP_NAME", appName); - text = text.Replace("$UI_URL", uiUrl); - if (assigner != null) { text = text.Replace("$ASSIGNER_EMAIL", assigner.Email); @@ -101,6 +99,8 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation text = text.Replace("$ASSIGNEE_NAME", assignee.DisplayName()); } + text = text.Replace("$UI_URL", uiUrl); + return text; } } diff --git a/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs b/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs index a7d6007c9..0bf99f271 100644 --- a/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs +++ b/src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs @@ -31,7 +31,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation { if (assignContributor.IsInviting && assignContributor.ContributorId.IsEmail()) { - assignContributor.IsCreated = await userResolver.CreateUserIfNotExists(assignContributor.ContributorId); + assignContributor.IsCreated = await userResolver.CreateUserIfNotExists(assignContributor.ContributorId, true); await next(); diff --git a/src/Squidex.Infrastructure/Email/IEmailSender.cs b/src/Squidex.Infrastructure/Email/IEmailSender.cs index dbacfd19d..6fa4e5cd8 100644 --- a/src/Squidex.Infrastructure/Email/IEmailSender.cs +++ b/src/Squidex.Infrastructure/Email/IEmailSender.cs @@ -11,6 +11,6 @@ namespace Squidex.Infrastructure.Email { public interface IEmailSender { - Task SendAsync(string recipient, string subject, string text); + Task SendAsync(string recipient, string subject, string body); } } diff --git a/src/Squidex/appsettings.json b/src/Squidex/appsettings.json index cc836887c..c244a8b2b 100644 --- a/src/Squidex/appsettings.json +++ b/src/Squidex/appsettings.json @@ -100,11 +100,11 @@ /* * The email subject when a new user is added as contributor. */ - "newUserSubject": "Welcome to Squidex, you have been invited to join Project $APP_NAME", + "newUserSubject": "You have been invited to join Project $APP_NAME at Squidex CMS", /* * The email body when a new user is added as contributor. */ - "newUserBody": "You have been invited to join a Project at Squidex CMS\n\nWelcome to Squidex\n$ASSIGNER_NAME ($ASSIGNER_EMAIL) has invited you to join app $APP_NAME at Squidex Headless CMS.\nLogin with your Github, Google or Microsoft credentials to create a new user account and start editing content now.\n\nThank you very much,\nThe Squidex Team\n<> [$UI_URL]", + "newUserBody": "Welcome to Squidex\r\nDear User,\r\n\r\n{{var:assigner_name}} ($ASSIGNER_EMAIL) has invited you to join Project (also called an App) {{var:app_name}} at Squidex Headless CMS. Login with your Github, Google or Microsoft credentials to create a new user account and start editing content now.\r\n\r\nThank you very much,\r\nThe Squidex Team\r\n\r\n<> [https://cloud.squidex.io]", /* * The email subject when an existing user is added as contributor. */ diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Invitation/InvitationEmailEventConsumerTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Invitation/InvitationEmailEventConsumerTests.cs index 90d799c39..a5e94c8f7 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Invitation/InvitationEmailEventConsumerTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Apps/Invitation/InvitationEmailEventConsumerTests.cs @@ -109,7 +109,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation [Fact] public async Task Should_send_email_for_new_user() { - var @event = Envelope.Create(CreateEvent(RefTokenType.Subject, false)); + var @event = Envelope.Create(CreateEvent(RefTokenType.Subject, true)); A.CallTo(() => userResolver.FindByIdOrEmailAsync(assignerId)) .Returns(assigner); @@ -120,13 +120,13 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation await sut.On(@event); A.CallTo(() => emailSender.SendNewUserEmailAsync(assigner, assignee, appName)) - .MustNotHaveHappened(); + .MustHaveHappened(); } [Fact] public async Task Should_send_email_for_existing_user() { - var @event = Envelope.Create(CreateEvent(RefTokenType.Subject, true)); + var @event = Envelope.Create(CreateEvent(RefTokenType.Subject, false)); A.CallTo(() => userResolver.FindByIdOrEmailAsync(assignerId)) .Returns(assigner); @@ -137,7 +137,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Invitation await sut.On(@event); A.CallTo(() => emailSender.SendExistingUserEmailAsync(assigner, assignee, appName)) - .MustNotHaveHappened(); + .MustHaveHappened(); } private void MustLogWarning()