Skip to content

Commit 7d28d02

Browse files
committed
Code cleanup, indenting and namespaces updates.
1 parent e95300d commit 7d28d02

File tree

100 files changed

+2381
-2548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2381
-2548
lines changed

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

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,56 @@
77
using Umbraco.Forms.Integrations.Automation.Zapier.Helpers;
88
using Umbraco.Forms.Integrations.Automation.Zapier.Services;
99

10-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Components
10+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Components;
11+
12+
public class NewFormSubmittedNotification : INotificationHandler<RecordCreatingNotification>
1113
{
12-
public class NewFormSubmittedNotification : INotificationHandler<RecordCreatingNotification>
13-
{
14-
private readonly UmbUrlHelper _umbUrlHelper;
14+
private readonly UmbUrlHelper _umbUrlHelper;
1515

16-
private readonly IFormService _formService;
16+
private readonly IFormService _formService;
1717

18-
private readonly ZapierService _zapierService;
18+
private readonly ZapierService _zapierService;
1919

20-
private readonly ZapierFormSubscriptionHookService _zapierFormSubscriptionHookService;
20+
private readonly ZapierFormSubscriptionHookService _zapierFormSubscriptionHookService;
2121

22-
private readonly ILogger<NewFormSubmittedNotification> _logger;
22+
private readonly ILogger<NewFormSubmittedNotification> _logger;
2323

24-
public NewFormSubmittedNotification(
25-
UmbUrlHelper umbUrlHelper,
26-
IFormService formService,
27-
ZapierService zapierService, ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
28-
ILogger<NewFormSubmittedNotification> logger)
29-
{
30-
_umbUrlHelper = umbUrlHelper;
24+
public NewFormSubmittedNotification(
25+
UmbUrlHelper umbUrlHelper,
26+
IFormService formService,
27+
ZapierService zapierService, ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
28+
ILogger<NewFormSubmittedNotification> logger)
29+
{
30+
_umbUrlHelper = umbUrlHelper;
3131

32-
_formService = formService;
32+
_formService = formService;
3333

34-
_zapierService = zapierService;
34+
_zapierService = zapierService;
3535

36-
_zapierFormSubscriptionHookService = zapierFormSubscriptionHookService;
36+
_zapierFormSubscriptionHookService = zapierFormSubscriptionHookService;
3737

38-
_logger = logger;
39-
}
38+
_logger = logger;
39+
}
40+
41+
public void Handle(RecordCreatingNotification notification)
42+
{
43+
var triggerHelper = new TriggerHelper(_zapierService);
4044

41-
public void Handle(RecordCreatingNotification notification)
45+
foreach (var notificationSavedEntity in notification.SavedEntities)
4246
{
43-
var triggerHelper = new TriggerHelper(_zapierService);
47+
var form = _formService.Get(notificationSavedEntity.Form);
4448

45-
foreach (var notificationSavedEntity in notification.SavedEntities)
49+
if (_zapierFormSubscriptionHookService.TryGetById(form.Id.ToString(), out var subscriptionHooks))
4650
{
47-
var form = _formService.Get(notificationSavedEntity.Form);
51+
var content = form.ToFormDictionary(notificationSavedEntity, _umbUrlHelper.GetPageUrl(notificationSavedEntity.UmbracoPageId));
4852

49-
if (_zapierFormSubscriptionHookService.TryGetById(form.Id.ToString(), out var subscriptionHooks))
53+
foreach (var subscriptionHook in subscriptionHooks)
5054
{
51-
var content = form.ToFormDictionary(notificationSavedEntity, _umbUrlHelper.GetPageUrl(notificationSavedEntity.UmbracoPageId));
52-
53-
foreach (var subscriptionHook in subscriptionHooks)
54-
{
55-
var result =
56-
triggerHelper.FormExecute(subscriptionHook.HookUrl, content);
55+
var result =
56+
triggerHelper.FormExecute(subscriptionHook.HookUrl, content);
5757

58-
if (!string.IsNullOrEmpty(result))
59-
_logger.LogError(result);
60-
}
58+
if (!string.IsNullOrEmpty(result))
59+
_logger.LogError(result);
6160
}
6261
}
6362
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration
1+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration;
2+
3+
public class AppSettings
24
{
3-
public class AppSettings
4-
{
5-
public string UserGroupAlias { get; set; }
5+
public string UserGroupAlias { get; set; }
66

7-
public string ApiKey { get; set; }
8-
}
7+
public string ApiKey { get; set; }
98
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration
1+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration;
2+
3+
public class ZapierCmsSettings : AppSettings
24
{
3-
public class ZapierCmsSettings : AppSettings
4-
{
5-
}
65
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration
1+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Configuration;
2+
3+
public class ZapierFormsSettings : AppSettings
24
{
3-
public class ZapierFormsSettings : AppSettings
4-
{
5-
}
65
}
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11

2-
namespace Umbraco.Forms.Integrations.Automation.Zapier
2+
namespace Umbraco.Forms.Integrations.Automation.Zapier;
3+
4+
public class Constants
35
{
4-
public class Constants
6+
public static class ZapierAppConfiguration
57
{
6-
public static class ZapierAppConfiguration
7-
{
8-
public const string UsernameHeaderKey = "X-USERNAME";
8+
public const string UsernameHeaderKey = "X-USERNAME";
99

10-
public const string PasswordHeaderKey = "X-PASSWORD";
10+
public const string PasswordHeaderKey = "X-PASSWORD";
1111

12-
public const string ApiKeyHeaderKey = "X-APIKEY";
13-
}
12+
public const string ApiKeyHeaderKey = "X-APIKEY";
13+
}
1414

15-
public static class Configuration
16-
{
17-
public const string CmsSettings = "Umbraco:CMS:Integrations:Automation:Zapier:Settings";
15+
public static class Configuration
16+
{
17+
public const string CmsSettings = "Umbraco:CMS:Integrations:Automation:Zapier:Settings";
1818

19-
public const string Settings = "Umbraco:Forms:Integrations:Automation:Zapier:Settings";
20-
}
19+
public const string Settings = "Umbraco:Forms:Integrations:Automation:Zapier:Settings";
20+
}
2121

22-
public static class FormProperties
23-
{
24-
public const string Id = "formId";
22+
public static class FormProperties
23+
{
24+
public const string Id = "formId";
2525

26-
public const string Name = "formName";
26+
public const string Name = "formName";
2727

28-
public const string SubmissionDate = "submissionDate";
28+
public const string SubmissionDate = "submissionDate";
2929

30-
public const string PageUrl = "pageUrl";
31-
}
30+
public const string PageUrl = "pageUrl";
31+
}
3232

33-
public static class EntityType
34-
{
35-
public const int Form = 2;
36-
}
33+
public static class EntityType
34+
{
35+
public const int Form = 2;
3736
}
3837
}

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,23 @@
44
using Umbraco.Forms.Integrations.Automation.Zapier.Models.Dtos;
55
using Umbraco.Forms.Integrations.Automation.Zapier.Services;
66

7-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers
8-
{
9-
/// <summary>
10-
/// When a Zapier user creates a new "New Form Submitted" trigger, the API is used to provide them with the list of forms.
11-
/// </summary>
12-
public class FormController : ZapierFormAuthorizedApiController
13-
{
14-
private readonly ZapierFormService _zapierFormService;
7+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers;
158

16-
public FormController(
17-
IUserValidationService userValidationService, ZapierFormService zapierFormService)
18-
: base(userValidationService) => _zapierFormService = zapierFormService;
9+
/// <summary>
10+
/// When a Zapier user creates a new "New Form Submitted" trigger, the API is used to provide them with the list of forms.
11+
/// </summary>
12+
public class FormController : ZapierFormAuthorizedApiController
13+
{
14+
private readonly ZapierFormService _zapierFormService;
1915

20-
public IEnumerable<FormDto> GetForms()
21-
{
22-
if (!IsAccessValid()) return Enumerable.Empty<FormDto>();
16+
public FormController(
17+
IUserValidationService userValidationService, ZapierFormService zapierFormService)
18+
: base(userValidationService) => _zapierFormService = zapierFormService;
2319

24-
return _zapierFormService.GetAll();
25-
}
20+
public IEnumerable<FormDto> GetForms()
21+
{
22+
if (!IsAccessValid()) return Enumerable.Empty<FormDto>();
2623

24+
return _zapierFormService.GetAll();
2725
}
2826
}

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@
22
using Umbraco.Forms.Integrations.Automation.Zapier.Extensions;
33
using Umbraco.Forms.Integrations.Automation.Zapier.Services;
44

5-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers
5+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers;
6+
7+
/// <summary>
8+
/// When a Zapier user creates a "New Form Submitted" trigger, they are authenticated, they select a form, and the API provides an output json with the
9+
/// structure of the selected form.
10+
/// </summary>
11+
public class FormPollingController : ZapierFormAuthorizedApiController
612
{
7-
/// <summary>
8-
/// When a Zapier user creates a "New Form Submitted" trigger, they are authenticated, they select a form, and the API provides an output json with the
9-
/// structure of the selected form.
10-
/// </summary>
11-
public class FormPollingController : ZapierFormAuthorizedApiController
12-
{
13-
private readonly ZapierFormService _zapierFormService;
13+
private readonly ZapierFormService _zapierFormService;
1414

15-
public FormPollingController(
16-
ZapierFormService zapierFormService,
17-
IUserValidationService userValidationService)
18-
: base(userValidationService) => _zapierFormService = zapierFormService;
15+
public FormPollingController(
16+
ZapierFormService zapierFormService,
17+
IUserValidationService userValidationService)
18+
: base(userValidationService) => _zapierFormService = zapierFormService;
1919

20-
public List<Dictionary<string, string>> GetFormPropertiesById(string id)
21-
{
22-
if (!IsAccessValid()) return new List<Dictionary<string, string>>();
20+
public List<Dictionary<string, string>> GetFormPropertiesById(string id)
21+
{
22+
if (!IsAccessValid()) return new List<Dictionary<string, string>>();
2323

24-
var form = _zapierFormService.GetById(id);
24+
var form = _zapierFormService.GetById(id);
2525

26-
if (form == null) return new List<Dictionary<string, string>>();
26+
if (form == null) return new List<Dictionary<string, string>>();
2727

28-
return new List<Dictionary<string, string>> { form.ToEmptyFormDictionary() };
29-
}
28+
return new List<Dictionary<string, string>> { form.ToEmptyFormDictionary() };
3029
}
3130
}

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

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,38 @@
22
using Umbraco.Cms.Web.Common.Controllers;
33
using Umbraco.Forms.Integrations.Automation.Zapier.Services;
44

5-
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers
5+
namespace Umbraco.Forms.Integrations.Automation.Zapier.Controllers;
6+
7+
public class ZapierFormAuthorizedApiController : UmbracoApiController
68
{
7-
public class ZapierFormAuthorizedApiController : UmbracoApiController
9+
private readonly IUserValidationService _userValidationService;
10+
11+
public ZapierFormAuthorizedApiController(
12+
IUserValidationService userValidationService) =>
13+
_userValidationService = userValidationService;
14+
15+
public bool IsAccessValid()
816
{
9-
private readonly IUserValidationService _userValidationService;
10-
11-
public ZapierFormAuthorizedApiController(
12-
IUserValidationService userValidationService) =>
13-
_userValidationService = userValidationService;
14-
15-
public bool IsAccessValid()
16-
{
17-
string username = string.Empty;
18-
string password = string.Empty;
19-
string apiKey = string.Empty;
20-
21-
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
22-
out var usernameValues))
23-
username = usernameValues.First();
24-
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.PasswordHeaderKey,
25-
out var passwordValues))
26-
password = passwordValues.First();
27-
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.ApiKeyHeaderKey,
28-
out var apiKeyValues))
29-
apiKey = apiKeyValues.First();
30-
31-
if (string.IsNullOrEmpty(apiKey) && (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))) return false;
32-
33-
var isAuthorized = _userValidationService.Validate(username, password, apiKey).GetAwaiter()
34-
.GetResult();
35-
if (!isAuthorized) return false;
36-
37-
return true;
38-
}
17+
string username = string.Empty;
18+
string password = string.Empty;
19+
string apiKey = string.Empty;
20+
21+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
22+
out var usernameValues))
23+
username = usernameValues.First();
24+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.PasswordHeaderKey,
25+
out var passwordValues))
26+
password = passwordValues.First();
27+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.ApiKeyHeaderKey,
28+
out var apiKeyValues))
29+
apiKey = apiKeyValues.First();
30+
31+
if (string.IsNullOrEmpty(apiKey) && (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))) return false;
32+
33+
var isAuthorized = _userValidationService.Validate(username, password, apiKey).GetAwaiter()
34+
.GetResult();
35+
if (!isAuthorized) return false;
36+
37+
return true;
3938
}
4039
}

0 commit comments

Comments
 (0)