Skip to content

Commit ac0c809

Browse files
committed
Zapier V9 multi-target
1 parent 6bc0d05 commit ac0c809

File tree

16 files changed

+372
-58
lines changed

16 files changed

+372
-58
lines changed

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,16 @@
8181
<span ng-bind="row.webHookUrl"></span>
8282
</div>
8383
<div class="umb-table-cell">
84-
<umb-button action="vm.onTrigger(row.contentTypeName, row.webHookUrl)"
84+
<umb-button action="vm.onTrigger(row.webHookUrl, row.contentTypeName)"
8585
label="Trigger Webhook"
8686
type="button"
8787
button-style="info">
8888
</umb-button>
89-
<umb-button action="row.showDeletePrompt = true"
89+
<umb-button action="vm.onDelete(row.id)"
9090
label="Delete"
9191
type="button"
9292
button-style="danger">
9393
</umb-button>
94-
<umb-confirm-action ng-if="row.showDeletePrompt"
95-
direction="right"
96-
on-confirm="vm.onDelete(row.id)"
97-
on-cancel="row.showDeletePrompt = false">
98-
</umb-confirm-action>
9994
</div>
10095
</div>
10196
</div>

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/js/zapier.controller.js

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function zapierController($scope, notificationsService, umbracoCmsIntegrationsAutomationZapierResource, umbracoCmsIntegrationsAutomationZapierValidationService) {
1+
function zapierController(notificationsService, overlayService, localizationService, umbracoCmsIntegrationsAutomationZapierValidationService, umbracoCmsIntegrationsAutomationZapierResource) {
22

33
var vm = this;
44

@@ -19,7 +19,7 @@
1919
notificationsService.warning("Zapier Content Config", validationResult);
2020
return;
2121
}
22-
22+
2323
umbracoCmsIntegrationsAutomationZapierResource.addConfig(vm.webHookUrl, vm.selectedContentType).then(function (response) {
2424

2525
if (response.length > 0) {
@@ -35,11 +35,11 @@
3535
});
3636
}
3737

38-
vm.onTrigger = function (contentTypeName, webHookUrl) {
38+
vm.onTrigger = function (webHookUrl, contentTypeName) {
3939

4040
vm.loading = true;
4141

42-
umbracoCmsIntegrationsAutomationZapierResource.triggerWebHook(webHookUrl, contentTypeName).then(function(response) {
42+
umbracoCmsIntegrationsAutomationZapierResource.triggerWebHook(webHookUrl, contentTypeName).then(function (response) {
4343

4444
vm.loading = false;
4545

@@ -50,12 +50,33 @@
5050
});
5151
}
5252

53-
vm.onDelete = function(id) {
54-
umbracoCmsIntegrationsAutomationZapierResource.deleteConfig(id).then(function () {
55-
getContentTypes();
56-
57-
getContentConfigs();
58-
});
53+
vm.onDelete = function (id) {
54+
55+
localizationService.localizeMany(["dashboardTabs_promptDeleteTitle", "dashboardTabs_promptDeleteContent", "general_yes", "general_no"])
56+
.then(function (labels) {
57+
var overlay = {
58+
view: "confirm",
59+
title: labels[0],
60+
content: labels[1],
61+
closeButtonLabel: labels[3],
62+
submitButtonLabel: labels[2],
63+
submitButtonStyle: "danger",
64+
close: function () {
65+
overlayService.close();
66+
},
67+
submit: function () {
68+
69+
umbracoCmsIntegrationsAutomationZapierResource.deleteConfig(id).then(function () {
70+
getContentTypes();
71+
72+
getContentConfigs();
73+
});
74+
75+
overlayService.close();
76+
}
77+
};
78+
overlayService.open(overlay);
79+
});
5980
}
6081

6182
function getContentTypes() {
@@ -75,7 +96,7 @@
7596
vm.selectedContentType = "";
7697
}
7798

78-
99+
79100
}
80101

81102
angular.module("umbraco")

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/js/zapier.resource.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
return umbRequestHelper.resourcePromise(
1818
$http.get(`${apiEndpoint}/GetAll`), "Failed to get resource");
1919
},
20-
triggerWebHook: function(webHookUrl, contentTypeName) {
20+
triggerWebHook: function (webHookUrl, contentTypeName) {
2121
return umbRequestHelper.resourcePromise(
22-
$http.post(`${apiEndpoint}/TriggerAsync`, { contentTypeName: contentTypeName, webHookUrl: webHookUrl }), "Failed to get resource");
22+
$http.post(`${apiEndpoint}/TriggerWebHook`, { contentTypeName: contentTypeName, webHookUrl: webHookUrl }), "Failed to get resource");
2323
},
24-
deleteConfig: function(id) {
24+
deleteConfig: function (id) {
2525
return umbRequestHelper.resourcePromise(
2626
$http.delete(`${apiEndpoint}/Delete?id=${id}`), "Failed to get resource");
2727
}

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/lang/en-US.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
<language>
33
<area alias="dashboardTabs">
44
<key alias="zapierDashboard">Zapier Integrations</key>
5+
<key alias="promptDeleteTitle">Delete Registered Webhook</key>
6+
<key alias="promptDeleteContent">Are you sure?</key>
57
</area>
6-
</language>
8+
</language>

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

+50-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,66 @@
22
using System.Collections.Generic;
33
using System.Net.Http;
44
using System.Threading.Tasks;
5+
6+
57
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
68
using Umbraco.Core;
9+
10+
#if NETCOREAPP
11+
using Microsoft.Extensions.Logging;
12+
using Umbraco.Cms.Core.Events;
13+
using Umbraco.Cms.Core.Notifications;
14+
#else
715
using Umbraco.Core.Composing;
816
using Umbraco.Core.Events;
917
using Umbraco.Core.Logging;
10-
using Umbraco.Core.Models;
1118
using Umbraco.Core.Services;
1219
using Umbraco.Core.Services.Implement;
20+
#endif
1321

1422
namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
1523
{
24+
#if NETCOREAPP
25+
public class NewContentPublishedNotification : INotificationHandler<ContentPublishedNotification>
26+
{
27+
private readonly ZapConfigService _zapConfigService;
28+
29+
private readonly ZapierService _zapierService;
30+
31+
private readonly ILogger<NewContentPublishedNotification> _logger;
32+
33+
public NewContentPublishedNotification(ZapConfigService zapConfigService, ZapierService zapierService, ILogger<NewContentPublishedNotification> logger)
34+
{
35+
_zapConfigService = zapConfigService;
36+
37+
_zapierService = zapierService;
38+
39+
_logger = logger;
40+
}
41+
42+
public void Handle(ContentPublishedNotification notification)
43+
{
44+
foreach (var node in notification.PublishedEntities)
45+
{
46+
var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name);
47+
if (zapContentConfig == null) continue;
1648

49+
var content = new Dictionary<string, string>
50+
{
51+
{ Constants.Content.Name, node.Name },
52+
{ Constants.Content.PublishDate, DateTime.UtcNow.ToString() }
53+
};
54+
55+
var t = Task.Run(async () => await _zapierService.TriggerAsync(zapContentConfig.WebHookUrl, content));
56+
57+
var result = t.Result;
58+
59+
if (!string.IsNullOrEmpty(result))
60+
_logger.LogError(result);
61+
}
62+
}
63+
}
64+
#else
1765
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
1866
public class NewContentPublishedComposer : ComponentComposer<NewContentPublishedComponent>
1967
{ }
@@ -67,4 +115,5 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
67115
}
68116
}
69117
}
118+
#endif
70119
}

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

+56-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,67 @@
1-
using Umbraco.Cms.Integrations.Automation.Zapier.Migrations;
1+

2+
using Umbraco.Cms.Integrations.Automation.Zapier.Migrations;
3+
4+
#if NETCOREAPP
5+
using Umbraco.Cms.Core;
6+
using Umbraco.Cms.Core.Events;
7+
using Umbraco.Cms.Core.Migrations;
8+
using Umbraco.Cms.Core.Notifications;
9+
using Umbraco.Cms.Core.Scoping;
10+
using Umbraco.Cms.Core.Services;
11+
using Umbraco.Cms.Infrastructure.Migrations;
12+
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
13+
#else
214
using Umbraco.Core;
315
using Umbraco.Core.Composing;
416
using Umbraco.Core.Logging;
517
using Umbraco.Core.Migrations;
618
using Umbraco.Core.Migrations.Upgrade;
719
using Umbraco.Core.Scoping;
820
using Umbraco.Core.Services;
21+
#endif
922

1023
namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
1124
{
25+
#if NETCOREAPP
26+
public class ZapContentConfigMigration : INotificationHandler<UmbracoApplicationStartingNotification>
27+
{
28+
private readonly IMigrationPlanExecutor _migrationPlanExecutor;
29+
30+
private readonly IScopeProvider _scopeProvider;
31+
32+
private readonly IKeyValueService _keyValueService;
33+
34+
private readonly IRuntimeState _runtimeState;
35+
36+
public ZapContentConfigMigration(
37+
IScopeProvider scopeProvider,
38+
IMigrationPlanExecutor migrationPlanExecutor,
39+
IKeyValueService keyValueService,
40+
IRuntimeState runtimeState)
41+
{
42+
_migrationPlanExecutor = migrationPlanExecutor;
43+
44+
_scopeProvider = scopeProvider;
45+
46+
_keyValueService = keyValueService;
47+
48+
_runtimeState = runtimeState;
49+
}
50+
51+
public void Handle(UmbracoApplicationStartingNotification notification)
52+
{
53+
if(_runtimeState.Level < RuntimeLevel.Run) return;
1254

55+
var migrationPlan = new MigrationPlan(Constants.MigrationPlanName);
56+
57+
migrationPlan.From(string.Empty)
58+
.To<ZapContentConfigTable>(Constants.TargetStateName);
59+
60+
var upgrader = new Upgrader(migrationPlan);
61+
upgrader.Execute(_migrationPlanExecutor, _scopeProvider, _keyValueService);
62+
}
63+
}
64+
#else
1365
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
1466
public class ZapContentConfigComposer : ComponentComposer<ZapContentConfigComponent>
1567
{
@@ -39,10 +91,10 @@ public ZapContentConfigComponent(IScopeProvider scopeProvider, IMigrationBuilder
3991

4092
public void Initialize()
4193
{
42-
var migrationPlan = new MigrationPlan("ZapContentConfig");
94+
var migrationPlan = new MigrationPlan(Constants.MigrationPlanName);
4395

4496
migrationPlan.From(string.Empty)
45-
.To<ZapContentConfigTable>("zapiercontentconfigurations-db");
97+
.To<ZapContentConfigTable>(Constants.TargetStateName);
4698

4799
var upgrader = new Upgrader(migrationPlan);
48100
upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _logger);
@@ -52,4 +104,5 @@ public void Terminate()
52104
{
53105
}
54106
}
107+
#endif
55108
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Specialized;
2+
3+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Configuration
4+
{
5+
public class ZapierSettings
6+
{
7+
public ZapierSettings()
8+
{
9+
10+
}
11+
12+
public ZapierSettings(NameValueCollection appSettings)
13+
{
14+
UserGroup = appSettings[Constants.UmbracoCmsIntegrationsAutomationZapierUserGroup];
15+
}
16+
17+
public string UserGroup { get; set; }
18+
}
19+
}

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

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ public class Constants
55
{
66
public const string ZapContentConfigTable = "zapContentConfig";
77

8+
public const string MigrationPlanName = "ZapContentConfig";
9+
10+
public const string TargetStateName = "zapiercontentconfigurations-db";
11+
12+
public const string UmbracoCmsIntegrationsAutomationZapierUserGroup = "Umbraco.Cms.Integrations.Automation.Zapier.UserGroup";
13+
14+
public static class Configuration
15+
{
16+
public const string Settings = "Umbraco:Forms:Integrations:Automation:Zapier:Settings";
17+
}
18+
819
public static class Content
920
{
1021
public const string Name = "Name";

0 commit comments

Comments
 (0)