Skip to content

Commit a0d9bcf

Browse files
committed
PR feedback, refactoring and code cleanup
1 parent b0ff123 commit a0d9bcf

File tree

18 files changed

+113
-316
lines changed

18 files changed

+113
-316
lines changed

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/dashboard.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
<p>
2020
Zap triggers use webhooks to execute the actions. Webhooks are automated messages sent from apps when something happens.
2121
</p>
22-
<p>
22+
<p ng-if="!vm.formsExtensionInstalled">
2323
You can initiate your automation when a content item of a particular document type is published in Umbraco.
2424
</p>
25+
<p ng-if="vm.formsExtensionInstalled">
26+
You can initiate your automation when a content item of a particular document type is published or a form is submitted in Umbraco.
27+
</p>
2528
<p>
2629
The integration uses Zapier subscription hook triggers, allowing Zapier to set up and remove hook subscriptions when Zaps are created or removed on the platform.
2730
</p>

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/NewContentPublishedComponent.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#if NETFRAMEWORK
2-
using System;
3-
using System.Collections.Generic;
4-
52
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
63
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
74
using Umbraco.Core;
@@ -10,6 +7,7 @@
107
using Umbraco.Core.Logging;
118
using Umbraco.Core.Services;
129
using Umbraco.Core.Services.Implement;
10+
using Umbraco.Cms.Integrations.Automation.Zapier.Extensions;
1311

1412
namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
1513
{
@@ -51,19 +49,11 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
5149

5250
foreach (var node in e.PublishedEntities)
5351
{
52+
var x = node.ToContentDictionary();
53+
5454
if (_zapierSubscriptionHookService.TryGetByAlias(node.ContentType.Alias, out var zapContentConfigList))
5555
{
56-
var content = new Dictionary<string, string>
57-
{
58-
{Constants.Content.Id, node.Id.ToString() },
59-
{Constants.Content.Name, node.Name },
60-
{Constants.Content.PublishDate, DateTime.UtcNow.ToString("s") }
61-
};
62-
63-
foreach (var nodeProperty in node.Properties)
64-
{
65-
content.Add(nodeProperty.Alias, nodeProperty.Id == 0 || nodeProperty.Values.Count == 0 ? string.Empty : nodeProperty.GetValue().ToString());
66-
}
56+
var content = node.ToContentDictionary();
6757

6858
foreach (var zapContentConfig in zapContentConfigList)
6959
{

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/NewContentPublishedNotification.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#if NETCOREAPP
2-
using System;
3-
using System.Collections.Generic;
42
using Microsoft.Extensions.Logging;
53

64
using Umbraco.Cms.Core.Events;
75
using Umbraco.Cms.Core.Notifications;
6+
using Umbraco.Cms.Integrations.Automation.Zapier.Extensions;
87
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
98
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
109

@@ -35,12 +34,7 @@ public void Handle(ContentPublishedNotification notification)
3534
{
3635
if (_zapierSubscriptionHookService.TryGetByAlias(node.ContentType.Alias, out var zapContentConfigList))
3736
{
38-
var content = new Dictionary<string, string>
39-
{
40-
{Constants.Content.Id, node.Id.ToString() },
41-
{Constants.Content.Name, node.Name },
42-
{Constants.Content.PublishDate, DateTime.UtcNow.ToString("s") }
43-
};
37+
var content = node.ToContentDictionary();
4438

4539
foreach (var zapContentConfig in zapContentConfigList)
4640
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
2121
{
22+
/// <summary>
23+
/// When a Zapier user creates triggers using the Umbraco app from the Zapier App Directory, he needs to provide valid credentials for a backoffice account.
24+
/// </summary>
2225
public class AuthController : UmbracoApiController
2326
{
2427
private readonly ZapierSettings Options;
@@ -31,7 +34,7 @@ public class AuthController : UmbracoApiController
3134
public AuthController(IBackOfficeUserManager backOfficeUserManager, IUserValidationService userValidationService, IOptions<ZapierSettings> options)
3235
{
3336
_backOfficeUserManager = backOfficeUserManager;
34-
37+
3538
_userValidationService = userValidationService;
3639

3740
Options = options.Value;

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/ContentController.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32

43
using System.Linq;
54

@@ -21,6 +20,9 @@
2120

2221
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
2322
{
23+
/// <summary>
24+
/// When a Zapier user creates a new "New Content Published" trigger, the API is used to provide him with the list of content types for handling "Published" event.
25+
/// </summary>
2426
public class ContentController : UmbracoApiController
2527
{
2628
private readonly ZapierSettings Options;
@@ -29,12 +31,10 @@ public class ContentController : UmbracoApiController
2931

3032
private readonly IUserValidationService _userValidationService;
3133

32-
private readonly ZapierSubscriptionHookService _zapierSubscriptionHookService;
33-
3434
#if NETCOREAPP
35-
public ContentController(IOptions<ZapierSettings> options, IContentTypeService contentTypeService, IUserValidationService userValidationService, ZapierSubscriptionHookService zapierSubscriptionHookService)
35+
public ContentController(IOptions<ZapierSettings> options, IContentTypeService contentTypeService, IUserValidationService userValidationService)
3636
#else
37-
public ContentController(IContentTypeService contentTypeService, IUserValidationService userValidationService, ZapierSubscriptionHookService zapierSubscriptionHookService)
37+
public ContentController(IContentTypeService contentTypeService, IUserValidationService userValidationService)
3838
#endif
3939
{
4040
#if NETCOREAPP
@@ -46,8 +46,6 @@ public ContentController(IContentTypeService contentTypeService, IUserValidation
4646
_contentTypeService = contentTypeService;
4747

4848
_userValidationService = userValidationService;
49-
50-
_zapierSubscriptionHookService = zapierSubscriptionHookService;
5149
}
5250

5351
public IEnumerable<ContentTypeDto> GetContentTypes()

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

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using System.Collections.Generic;
2-
1+
using System;
2+
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Runtime.CompilerServices;
4+
55
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
6+
using Umbraco.Cms.Integrations.Automation.Zapier.Extensions;
67
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
78
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
89

@@ -12,20 +13,21 @@
1213
using Umbraco.Cms.Core.Web;
1314
using Umbraco.Cms.Web.Common.Controllers;
1415
using Umbraco.Cms.Core.Services;
15-
using Umbraco.Cms.Core.Models.PublishedContent;
16-
using Umbraco.Extensions;
1716
#else
1817
using System.Configuration;
1918

2019
using Umbraco.Web;
2120
using Umbraco.Web.WebApi;
2221
using Umbraco.Core.Services;
23-
using Umbraco.Core.Models.PublishedContent;
24-
2522
#endif
2623

2724
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
2825
{
26+
/// <summary>
27+
/// When a Zapier user creates a "New Content Published" triggered, he is authenticated, then selects a content type, the API provides an output json with the
28+
/// structure of a content node matching the selected content type.
29+
/// For version 1.0.0 of the Umbraco Zapier App, the GetSampleContent will be used.
30+
/// </summary>
2931
public class PollingController : UmbracoApiController
3032
{
3133
private IUmbracoContextFactory _umbracoContextFactory;
@@ -34,14 +36,12 @@ public class PollingController : UmbracoApiController
3436

3537
private readonly ZapierSettings Options;
3638

37-
private ZapierFormService _zapierFormService;
38-
3939
private readonly IUserValidationService _userValidationService;
4040

4141
#if NETCOREAPP
42-
public PollingController(IOptions<ZapierSettings> options, IUmbracoContextFactory umbracoContextFactory, IContentService contentService, ZapierFormService zapierFormService, IUserValidationService userValidationService)
42+
public PollingController(IOptions<ZapierSettings> options, IUmbracoContextFactory umbracoContextFactory, IContentService contentService, IUserValidationService userValidationService)
4343
#else
44-
public PollingController(IUmbracoContextFactory umbracoContextFactory, IContentService contentService, ZapierFormService zapierFormService, IUserValidationService userValidationService)
44+
public PollingController(IUmbracoContextFactory umbracoContextFactory, IContentService contentService, IUserValidationService userValidationService)
4545
#endif
4646
{
4747
#if NETCOREAPP
@@ -54,11 +54,10 @@ public PollingController(IUmbracoContextFactory umbracoContextFactory, IContentS
5454

5555
_contentService = contentService;
5656

57-
_zapierFormService = zapierFormService;
58-
5957
_userValidationService = userValidationService;
6058
}
6159

60+
[Obsolete("Used only for Umbraco Zapier app v1.0.0. For updated versions use GetContentByType")]
6261
public IEnumerable<PublishedContentDto> GetSampleContent()
6362
{
6463
string username = string.Empty;
@@ -97,43 +96,25 @@ public IEnumerable<PublishedContentDto> GetSampleContent()
9796
});
9897
}
9998

100-
public List<Dictionary<string, string>> GetContentByAlias(string contentTypeAlias)
99+
public List<Dictionary<string, string>> GetContentByType(string alias)
101100
{
102101
var list = new List<Dictionary<string, string>>();
103102

104103
using (var cref = _umbracoContextFactory.EnsureUmbracoContext())
105104
{
106105
var cache = cref.UmbracoContext.Content;
107106

108-
var nodes = cache.GetByXPath($"//{contentTypeAlias}")
107+
var node = cache.GetByXPath($"//{alias}")
109108
.Where(p => p.IsPublished())
110-
.OrderByDescending(p => p.UpdateDate);
111-
112-
foreach (var node in nodes)
113-
{
114-
var content = new Dictionary<string, string>
115-
{
116-
{Constants.Content.Id, node.Id.ToString() },
117-
{Constants.Content.Name, node.Name },
118-
{Constants.Content.PublishDate, node.UpdateDate.ToString("s") }
119-
};
120-
121-
foreach (var prop in node.Properties)
122-
{
123-
content.Add(prop.Alias, prop.GetValue().ToString());
124-
}
125-
126-
127-
list.Add(content);
128-
}
109+
.OrderByDescending(p => p.UpdateDate)
110+
.FirstOrDefault();
111+
112+
if (node == null) return list;
113+
114+
list.Add(node.ToContentDictionary());
129115

130116
return list;
131117
}
132118
}
133-
134-
public IEnumerable<FormDto> GetSampleForm()
135-
{
136-
return _zapierFormService.GetAll();
137-
}
138119
}
139120
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/SubscriptionController.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
using System.Net;
1+
using System.Linq;
42
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
53
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
64
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
@@ -17,6 +15,9 @@
1715

1816
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
1917
{
18+
/// <summary>
19+
/// Subscription API handling the ON/OFF trigger events in Zapier.
20+
/// </summary>
2021
public class SubscriptionController : UmbracoApiController
2122
{
2223
private readonly ZapierSettings Options;

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/ZapierConfigController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
2-
using System.Linq;
32
using System.Threading.Tasks;
3+
44
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
55
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
66
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
@@ -45,7 +45,7 @@ public ZapierConfigController(
4545
public IEnumerable<ContentConfigDto> GetAll() => _zapierSubscriptionHookService.GetAll();
4646

4747
[HttpGet]
48-
public bool IsFormsExtensionInstalled() => FormsHelper.IsFormsExtensionInstalled;
48+
public bool IsFormsExtensionInstalled() => ReflectionHelper.IsFormsExtensionInstalled;
4949

5050
[HttpGet]
5151
public IEnumerable<FormConfigDto> GetAllForms() => _zapierFormSubscriptionHookService.GetAll();

0 commit comments

Comments
 (0)