Browse Source

Latest fixes for emails.

pull/354/head
Sebastian Stehle 7 years ago
parent
commit
734c6a6876
  1. 4
      src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailEventConsumer.cs
  2. 6
      src/Squidex.Domain.Apps.Entities/Apps/Invitation/InvitationEmailSender.cs
  3. 2
      src/Squidex.Domain.Apps.Entities/Apps/Invitation/InviteUserCommandMiddleware.cs
  4. 2
      src/Squidex.Infrastructure/Email/IEmailSender.cs
  5. 4
      src/Squidex/appsettings.json
  6. 8
      tests/Squidex.Domain.Apps.Entities.Tests/Apps/Invitation/InvitationEmailEventConsumerTests.cs

4
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;

6
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;
}
}

2
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();

2
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);
}
}

4
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<<Start now!>> [$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<<Start now!>> [https://cloud.squidex.io]",
/*
* The email subject when an existing user is added as contributor.
*/

8
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()

Loading…
Cancel
Save