Skip to content

Commit 1a6b034

Browse files
committed
PR feedback updates: min version for Umbraco Forms, fluent mapping builder; mapping updates.
1 parent ccd4a0b commit 1a6b034

File tree

8 files changed

+48
-42
lines changed

8 files changed

+48
-42
lines changed

src/Umbraco.Forms.Integrations.Automation.Zapier/Controllers/AuthController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public bool ValidateUser([FromBody] UserModel userModel)
1919

2020
var user = userService.GetByUsername(userModel.Username);
2121

22-
return user != null && user.Groups.Any(p => p.Alias == "admin");
22+
return user != null && user.Groups.Any(p => p.Name == userModel.UserGroup);
2323
}
2424
}
2525
}

src/Umbraco.Forms.Integrations.Automation.Zapier/Models/UserModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ public class UserModel
66
public string Username { get; set; }
77

88
public string Password { get; set; }
9+
10+
public string UserGroup { get; set; }
911
}
1012
}

src/Umbraco.Forms.Integrations.Automation.Zapier/Services/MappingService.cs renamed to src/Umbraco.Forms.Integrations.Automation.Zapier/Services/FieldMappingBuilder.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@
1111

1212
namespace Umbraco.Forms.Integrations.Automation.Zapier.Services
1313
{
14-
public class MappingService: IMappingService
14+
public class FieldMappingBuilder: IFieldMappingBuilder
1515
{
1616
private readonly Dictionary<string, string> _content;
1717

1818
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
1919

20-
public MappingService(IUmbracoContextAccessor umbracoContextAccessor)
20+
public FieldMappingBuilder(IUmbracoContextAccessor umbracoContextAccessor)
2121
{
2222
_umbracoContextAccessor = umbracoContextAccessor;
2323

2424
_content = new Dictionary<string, string>();
2525
}
2626

27-
public IMappingService IncludeFieldsMappings(string mappings, RecordEventArgs e)
27+
/// <summary>
28+
/// Add form fields to the request content sent to Zapier. If no propery is mapped, all fields will be included by their alias.
29+
/// </summary>
30+
/// <param name="mappings">Serialized details of the form fields</param>
31+
/// <param name="e">Form record details</param>
32+
/// <returns></returns>
33+
public IFieldMappingBuilder IncludeFieldsMappings(string mappings, RecordEventArgs e)
2834
{
2935
var mappingsList = JsonConvert.DeserializeObject<List<FieldMapping>>(mappings);
3036
if (mappingsList.Any())
@@ -35,17 +41,29 @@ public IMappingService IncludeFieldsMappings(string mappings, RecordEventArgs e)
3541
_content.Add(mapping.Alias, string.IsNullOrEmpty(mapping.StaticValue) ? fieldRecord.ValuesAsString() : mapping.StaticValue);
3642
}
3743
}
44+
else
45+
{
46+
foreach (var recordField in e.Record.RecordFields)
47+
{
48+
_content.Add(recordField.Value.Alias, recordField.Value.ValuesAsString());
49+
}
50+
}
3851

3952
return this;
4053
}
4154

42-
public IMappingService IncludeStandardFieldsMappings(string mappings, RecordEventArgs e)
55+
/// <summary>
56+
/// Add form standard fields - that are set as Included in the settings of the workflow - to the request content sent to Zapier.
57+
/// </summary>
58+
/// <param name="mappings">Serialized details of the form standard fields</param>
59+
/// <param name="e">Form record details</param>
60+
/// <returns></returns>
61+
public IFieldMappingBuilder IncludeStandardFieldsMappings(string mappings, RecordEventArgs e)
4362
{
4463
if (!string.IsNullOrEmpty(mappings))
4564
{
4665
var standardFieldMappings =
47-
JsonConvert.DeserializeObject<IEnumerable<StandardFieldMapping>>(mappings,
48-
FormsJsonSerializerSettings.Default).ToList();
66+
JsonConvert.DeserializeObject<IEnumerable<StandardFieldMapping>>(mappings).ToList();
4967

5068
foreach (StandardFieldMapping fieldMapping in standardFieldMappings.Where(x => x.Include))
5169
{
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
3+
using Umbraco.Forms.Core;
4+
5+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Services
6+
{
7+
public interface IFieldMappingBuilder
8+
{
9+
IFieldMappingBuilder IncludeFieldsMappings(string mappings, RecordEventArgs e);
10+
11+
IFieldMappingBuilder IncludeStandardFieldsMappings(string mappings, RecordEventArgs e);
12+
13+
Dictionary<string, string> Map();
14+
}
15+
}

src/Umbraco.Forms.Integrations.Automation.Zapier/Services/IMappingService.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Umbraco.Forms.Integrations.Automation.Zapier/Umbraco.Forms.Integrations.Automation.Zapier.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<ItemGroup>
2020
<PackageReference Include="UmbracoCms.Web" Version="8.1.0" />
2121
<PackageReference Include="UmbracoCms.Core" Version="8.1.0" />
22-
<PackageReference Include="UmbracoForms.Core" Version="8.11.0" />
22+
<PackageReference Include="UmbracoForms.Core" Version="8.9.1" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

src/Umbraco.Forms.Integrations.Automation.Zapier/ZapierComposer.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Umbraco.Forms.Integrations.Automation.Zapier/ZapierWorkflow.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public ZapierWorkflow(IUmbracoContextAccessor umbracoContextAccessor)
2626
}
2727

2828
[Core.Attributes.Setting("Fields Mappings",
29-
Description = "Please map fields of the form against Zap ones",
29+
Description = "Please map form information to the Zap ones.",
3030
View = "FieldMapper")]
3131
public string Mappings { get; set; }
3232

3333
[Core.Attributes.Setting("Standard Fields Mappings",
34-
Description = "Please map fields of the form against Zap ones",
34+
Description = "Please map any standard form information to send.",
3535
View = "StandardFieldMapper")]
3636
public string StandardFieldsMappings { get; set; }
3737

@@ -50,14 +50,14 @@ public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e
5050
{
5151
try
5252
{
53-
IMappingService mappingService = new MappingService(_umbracoContextAccessor);
53+
IFieldMappingBuilder builder = new FieldMappingBuilder(_umbracoContextAccessor);
5454

55-
var content = mappingService
55+
var content = builder
5656
.IncludeFieldsMappings(Mappings, e)
5757
.IncludeStandardFieldsMappings(StandardFieldsMappings, e)
5858
.Map();
5959

60-
var result = ClientFactory().PostAsync(WebHookUri, new FormUrlEncodedContent(content)).Result;
60+
var result = ClientFactory().PostAsync(WebHookUri, new FormUrlEncodedContent(content)).GetAwaiter().GetResult();
6161

6262
return result.IsSuccessStatusCode ? WorkflowExecutionStatus.Completed : WorkflowExecutionStatus.Failed;
6363
}

0 commit comments

Comments
 (0)