Skip to content

Commit 9339c4f

Browse files
committed
Initial draft for Zapier 2.0.0
1 parent 2dff380 commit 9339c4f

18 files changed

+233
-247
lines changed

src/Umbraco.Forms.Integrations.Automation.Zapier/Components/NewFormSubmittedComponent.cs

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

src/Umbraco.Forms.Integrations.Automation.Zapier/Components/NewFormSubmittedNotification.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NETCOREAPP
2-
using Microsoft.Extensions.Logging;
1+
using Microsoft.Extensions.Logging;
32

43
using Umbraco.Cms.Core.Events;
54
using Umbraco.Cms.Core.Models.PublishedContent;
@@ -67,5 +66,4 @@ public void Handle(RecordCreatingNotification notification)
6766
}
6867
}
6968
}
70-
}
71-
#endif
69+
}

src/Umbraco.Forms.Integrations.Automation.Zapier/Configuration/ZapierSettings.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections.Specialized;
2-
3-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration
1+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration
42
{
53
public class ZapierSettings
64
{
@@ -9,13 +7,6 @@ public ZapierSettings()
97

108
}
119

12-
public ZapierSettings(NameValueCollection appSettings)
13-
{
14-
UserGroupAlias = appSettings[Constants.UmbracoFormsIntegrationsAutomationZapierUserGroupAlias];
15-
16-
ApiKey = appSettings[Constants.UmbracoFormsIntegrationsAutomationZapierApiKey];
17-
}
18-
1910
public string UserGroupAlias { get; set; }
2011

2112
public string ApiKey { get; set; }

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ namespace Umbraco.Forms.Integrations.Automation.Zapier
33
{
44
public class Constants
55
{
6-
public const string UmbracoFormsIntegrationsAutomationZapierUserGroupAlias = "Umbraco.Forms.Integrations.Automation.Zapier.UserGroupAlias";
7-
8-
public const string UmbracoFormsIntegrationsAutomationZapierApiKey = "Umbraco.Forms.Integrations.Automation.Zapier.ApiKey";
9-
106
public static class ZapierAppConfiguration
117
{
128
public const string UsernameHeaderKey = "X-USERNAME";

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
using Umbraco.Forms.Integrations.Automation.Zapier.Models.Dtos;
55
using Umbraco.Forms.Integrations.Automation.Zapier.Services;
66

7-
#if NETCOREAPP
87
using Microsoft.Extensions.Options;
98

109
using Umbraco.Forms.Integrations.Automation.Zapier.Configuration;
11-
#endif
1210

1311
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers
1412
{
@@ -19,13 +17,8 @@ public class FormController : ZapierFormAuthorizedApiController
1917
{
2018
private readonly ZapierFormService _zapierFormService;
2119

22-
#if NETCOREAPP
2320
public FormController(IOptions<ZapierSettings> options, IUserValidationService userValidationService, ZapierFormService zapierFormService)
2421
: base(options, userValidationService)
25-
#else
26-
public FormController(ZapierFormService zapierFormService, IUserValidationService userValidationService)
27-
: base(userValidationService)
28-
#endif
2922
{
3023
_zapierFormService = zapierFormService;
3124
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
using Umbraco.Forms.Integrations.Automation.Zapier.Helpers;
66
using Umbraco.Forms.Integrations.Automation.Zapier.Services;
77

8-
#if NETCOREAPP
98
using Microsoft.Extensions.Options;
109

1110
using Umbraco.Forms.Integrations.Automation.Zapier.Configuration;
12-
#endif
1311

1412
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers
1513
{
@@ -25,17 +23,10 @@ public class FormPollingController : ZapierFormAuthorizedApiController
2523

2624
private readonly UmbUrlHelper _umbUrlHelper;
2725

28-
#if NETCOREAPP
2926
public FormPollingController(IOptions<ZapierSettings> options, ZapierFormService zapierFormService, IRecordStorage recordStorage,
3027
UmbUrlHelper umbUrlHelper,
3128
IUserValidationService userValidationService)
3229
: base(options, userValidationService)
33-
#else
34-
public FormPollingController(ZapierFormService zapierFormService, IRecordStorage recordStorage,
35-
UmbUrlHelper umbUrlHelper,
36-
IUserValidationService userValidationService)
37-
: base(userValidationService)
38-
#endif
3930
{
4031
_zapierFormService = zapierFormService;
4132

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
using Umbraco.Forms.Integrations.Automation.Zapier.Configuration;
44
using Umbraco.Forms.Integrations.Automation.Zapier.Services;
55

6-
#if NETCOREAPP
76
using Microsoft.Extensions.Options;
87

98
using Umbraco.Cms.Web.Common.Controllers;
10-
#else
11-
using System.Configuration;
12-
13-
using Umbraco.Web.WebApi;
14-
#endif
159

1610
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers
1711
{
@@ -21,17 +15,9 @@ public class ZapierFormAuthorizedApiController : UmbracoApiController
2115

2216
private readonly IUserValidationService _userValidationService;
2317

24-
#if NETCOREAPP
2518
public ZapierFormAuthorizedApiController(IOptions<ZapierSettings> options, IUserValidationService userValidationService)
26-
#else
27-
public ZapierFormAuthorizedApiController(IUserValidationService userValidationService)
28-
#endif
2919
{
30-
#if NETCOREAPP
3120
Options = options.Value;
32-
#else
33-
Options = new ZapierSettings(ConfigurationManager.AppSettings);
34-
#endif
3521

3622
_userValidationService = userValidationService;
3723
}
@@ -42,7 +28,6 @@ public bool IsAccessValid()
4228
string password = string.Empty;
4329
string apiKey = string.Empty;
4430

45-
#if NETCOREAPP
4631
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
4732
out var usernameValues))
4833
username = usernameValues.First();
@@ -52,17 +37,6 @@ public bool IsAccessValid()
5237
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.ApiKeyHeaderKey,
5338
out var apiKeyValues))
5439
apiKey = apiKeyValues.First();
55-
#else
56-
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.UsernameHeaderKey,
57-
out var usernameValues))
58-
username = usernameValues.First();
59-
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.PasswordHeaderKey,
60-
out var passwordValues))
61-
password = passwordValues.First();
62-
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.ApiKeyHeaderKey,
63-
out var apiKeyValues))
64-
apiKey = apiKeyValues.First();
65-
#endif
6640

6741
if (string.IsNullOrEmpty(apiKey) && (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))) return false;
6842

src/Umbraco.Forms.Integrations.Automation.Zapier/Helpers/UmbUrlHelper.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
#if NETCOREAPP
2-
using Umbraco.Cms.Core.Models.PublishedContent;
1+
using Umbraco.Cms.Core.Models.PublishedContent;
32
using Umbraco.Cms.Core.Routing;
43
using Umbraco.Cms.Web.Common;
54
using Umbraco.Extensions;
6-
#else
7-
using Umbraco.Core.Models.PublishedContent;
8-
using Umbraco.Web;
9-
#endif
105

116
namespace Umbraco.Forms.Integrations.Automation.Zapier.Helpers
127
{
138
public class UmbUrlHelper
149
{
15-
#if NETCOREAPP
1610
private readonly IUmbracoHelperAccessor _umbracoHelperAccessor;
1711

1812
private readonly IPublishedUrlProvider _publishedUrlProvider;
@@ -23,18 +17,9 @@ public UmbUrlHelper(IUmbracoHelperAccessor umbracoHelperAccessor, IPublishedUrlP
2317

2418
_publishedUrlProvider = publishedUrlProvider;
2519
}
26-
#else
27-
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
28-
29-
public UmbUrlHelper(IUmbracoContextAccessor umbracoContextAccessor)
30-
{
31-
_umbracoContextAccessor = umbracoContextAccessor;
32-
}
33-
#endif
3420

3521
public string GetPageUrl(int umbracoPageId)
3622
{
37-
#if NETCOREAPP
3823
string pageUrl = string.Empty;
3924
if (_umbracoHelperAccessor.TryGetUmbracoHelper(out UmbracoHelper umbracoHelper))
4025
{
@@ -44,11 +29,6 @@ public string GetPageUrl(int umbracoPageId)
4429
pageUrl = publishedContent.Url(_publishedUrlProvider, mode: UrlMode.Absolute);
4530
}
4631
}
47-
#else
48-
UmbracoContext umbracoContext = _umbracoContextAccessor.UmbracoContext;
49-
50-
var pageUrl = umbracoContext.UrlProvider.GetUrl(umbracoPageId, UrlMode.Absolute);
51-
#endif
5232

5333
return pageUrl;
5434
}

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

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,24 @@
22
using System.Collections.Generic;
33
using System.Linq;
44

5-
#if NETCOREAPP
5+
using Umbraco.Forms.Core.Models;
66
using Umbraco.Forms.Core.Services;
7-
#else
8-
using Umbraco.Forms.Core.Data.Storage;
9-
#endif
10-
117
using Umbraco.Forms.Integrations.Automation.Zapier.Models.Dtos;
12-
using Umbraco.Forms.Core.Models;
138

149
namespace Umbraco.Forms.Integrations.Automation.Zapier.Services
1510
{
1611
public class ZapierFormService
1712
{
18-
#if NETCOREAPP
1913
private readonly IFormService _formService;
2014

2115
public ZapierFormService(IFormService formService)
2216
{
2317
_formService = formService;
2418
}
25-
#else
26-
private readonly IFormStorage _formStorage;
27-
28-
public ZapierFormService(IFormStorage formStorage)
29-
{
30-
_formStorage = formStorage;
31-
}
32-
#endif
3319

34-
/// <summary>
35-
/// for V8 use IFormStorage to retrieve forms saved on disk also
36-
/// </summary>
37-
/// <returns></returns>
3820
public IEnumerable<FormDto> GetAll()
3921
{
40-
#if NETCOREAPP
4122
var forms = _formService.Get();
42-
#else
43-
var forms = _formStorage.GetAll();
44-
#endif
4523

4624
return forms.Select(p => new FormDto
4725
{
@@ -50,13 +28,6 @@ public IEnumerable<FormDto> GetAll()
5028
});
5129
}
5230

53-
public Form GetById(string id)
54-
{
55-
#if NETCOREAPP
56-
return _formService.Get().FirstOrDefault(p => p.Id == Guid.Parse(id));
57-
#else
58-
return _formStorage.GetAll().FirstOrDefault(p => p.Id == Guid.Parse(id));
59-
#endif
60-
}
31+
public Form GetById(string id) => _formService.Get().FirstOrDefault(p => p.Id == Guid.Parse(id));
6132
}
6233
}

0 commit comments

Comments
 (0)