Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
fix (Email Handler) properly parse GUID ID properties
Browse files Browse the repository at this point in the history
Also, refactored some of the code to use the previous interface (to avoid breaking extension that rely on the interface not changing).

See: #185
  • Loading branch information
Nicholas-Westby committed Dec 11, 2020
1 parent 73858ff commit 3869f8c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
41 changes: 38 additions & 3 deletions src/formulate.app/Forms/Handlers/Email/EmailConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace formulate.app.Forms.Handlers.Email
{

// Namespaces.
using formulate.core.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;

/// <summary>
/// Configuration used by <see cref="EmailHandler"/>.
Expand All @@ -16,12 +21,32 @@ public class EmailConfiguration : IEmailSenderRecipientConfiguration
/// <summary>
/// Gets or sets the recipients of the email.
/// </summary>
public IEnumerable<Recipient> Recipients { get; set; }
[JsonProperty("recipients")]
public IEnumerable<Recipient> RecipientsData { get; set; }

/// <summary>
/// Gets the recipients of the email.
/// </summary>
/// <remarks>
/// This is a duplicate property because this version implements the interface,
/// which requires a slightly different data type.
/// </remarks>
public IEnumerable<string> Recipients => RecipientsData.MakeSafe().Select(x => x.Email).ToArray();

/// <summary>
/// Gets or sets the fields containing the recipients of the email.
/// </summary>
public IEnumerable<Guid> RecipientFields { get; set; }
[JsonProperty("recipientFields")]
public IEnumerable<GuidId> RecipientFieldsData { get; set; }

/// <summary>
/// Gets the fields containing the recipients of the email.
/// </summary>
/// <remarks>
/// This is a duplicate property because this version implements the interface,
/// which requires a slightly different data type.
/// </remarks>
public IEnumerable<Guid> RecipientFields => RecipientFieldsData.MakeSafe().Select(x => x.Id).ToArray();

/// <summary>
/// Gets or sets the type of delivery for the recipients (e.g., to, cc, bcc).
Expand All @@ -31,7 +56,17 @@ public class EmailConfiguration : IEmailSenderRecipientConfiguration
/// <summary>
/// Gets or sets the fields to include.
/// </summary>
public IEnumerable<Guid> FieldsToInclude { get; set; }
[JsonProperty("fieldsToInclude")]
public IEnumerable<GuidId> FieldsToIncludeData { get; set; }

/// <summary>
/// Gets the fields to include.
/// </summary>
/// <remarks>
/// This is a convenience property that extracts the important data
/// from the other version of this property.
/// </remarks>
public IEnumerable<Guid> FieldsToInclude => FieldsToIncludeData.MakeSafe().Select(x => x.Id).ToArray();

/// <summary>
/// Gets or sets the message.
Expand Down
1 change: 0 additions & 1 deletion src/formulate.app/Forms/Handlers/Email/EmailHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ protected MailMessage PrepareEmailMessage(

// Any allowed recipients (if not, abort early)?
var rawRecipients = config.Recipients
.Select(x => x.Email)
.Concat(fieldEmails)
.Concat(extraEmails);
var allowedRecipients = FilterEmails(rawRecipients);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface IEmailSenderRecipientConfiguration
/// <summary>
/// Gets the recipients of the email.
/// </summary>
IEnumerable<Recipient> Recipients { get; }
IEnumerable<string> Recipients { get; }

/// <summary>
/// Gets the fields containing the recipients of the email.
Expand Down
24 changes: 24 additions & 0 deletions src/formulate.app/Forms/Handlers/Email/RecipientField.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace formulate.app.Forms.Handlers.Email
{

// Namespaces.
using System;

/// <summary>
/// An object that contains an ID that is a GUID.
/// </summary>
public class GuidId
{

#region Properties

/// <summary>
/// The GUID ID.
/// </summary>
public Guid Id { get; set; }

#endregion

}

}
1 change: 1 addition & 0 deletions src/formulate.app/formulate.app.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
<Compile Include="Forms\Handlers\Email\EmailConfiguration.cs" />
<Compile Include="Forms\Handlers\Email\EmailHandler.cs" />
<Compile Include="Forms\Handlers\Email\IEmailSenderRecipientConfiguration.cs" />
<Compile Include="Forms\Handlers\Email\RecipientField.cs" />
<Compile Include="Forms\Handlers\Email\Recipient.cs" />
<Compile Include="Forms\Handlers\SendData\FieldMapping.cs" />
<Compile Include="Forms\Handlers\SendData\IHandleSendDataResult.cs" />
Expand Down

0 comments on commit 3869f8c

Please sign in to comment.