Skip to content

Commit 14da187

Browse files
committed
Zapier Forms integration: migrations & subscription endpoints
1 parent 1ba1a70 commit 14da187

18 files changed

+385
-119
lines changed

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

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div ng-controller="Umbraco.Cms.Integrations.Automation.Zapier.ZapierConfigController as vm">
2+
<umb-load-indicator ng-show="vm.loading"></umb-load-indicator>
23
<umb-box>
34
<umb-box-header title="Content Properties"></umb-box-header>
45
<umb-box-content>
@@ -29,17 +30,11 @@
2930
</umb-box>
3031
<umb-box>
3132
<umb-box-header title="Registered Subscription Hooks"></umb-box-header>
32-
<umb-content>
33+
<umb-box-content>
34+
<div>
35+
<p ng-if="vm.contentConfigs.length == 0">There are no subscription hooks.</p>
36+
</div>
3337
<div class="mt2">
34-
35-
<!-- If list is empty, then display -->
36-
<umb-empty-state ng-if="vm.contentConfigs.length == 0"
37-
position="center" class="mb-3">
38-
There are no subscription hooks.
39-
</umb-empty-state>
40-
41-
<umb-load-indicator ng-show="vm.loading"></umb-load-indicator>
42-
4338
<div class="umb-table" ng-if="vm.contentConfigs.length > 0">
4439
<!-- Listviews head section -->
4540
<div class="umb-table-head">
@@ -73,6 +68,48 @@
7368
</div>
7469
</div>
7570
</div>
76-
</umb-content>
71+
</umb-box-content>
72+
</umb-box>
73+
<umb-box ng-if="vm.formsExtensionInstalled">
74+
<umb-box-header title="Registered Form Subscription Hooks"></umb-box-header>
75+
<umb-box-content>
76+
<div>
77+
<p ng-if="vm.formConfigs.length == 0">There are no form subscription hooks.</p>
78+
</div>
79+
<div class="mt2">
80+
<div class="umb-table" ng-if="vm.formConfigs.length > 0">
81+
<!-- Listviews head section -->
82+
<div class="umb-table-head">
83+
<div class="umb-table-row">
84+
<div class="umb-table-cell"></div>
85+
<div class="umb-table-cell umb-table__name">
86+
<a class="umb-table-head__link" href="#" prevent-default>
87+
<span>Form Name</span>
88+
</a>
89+
</div>
90+
<div class="umb-table-cell">
91+
<a class="umb-table-head__link" href="#" prevent-default>
92+
<span>Hook URL</span>
93+
</a>
94+
</div>
95+
</div>
96+
</div>
97+
98+
<!-- Listview body section -->
99+
<div class="umb-table-body">
100+
<div class="umb-table-row"
101+
ng-repeat="row in vm.formConfigs track by $index">
102+
<div class="umb-table-cell"></div>
103+
<div class="umb-table-cell umb-table__name">
104+
<span ng-bind="row.formName"></span>
105+
</div>
106+
<div class="umb-table-cell">
107+
<span ng-bind="row.hookUrl"></span>
108+
</div>
109+
</div>
110+
</div>
111+
</div>
112+
</div>
113+
</umb-box-content>
77114
</umb-box>
78115
</div>

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
var vm = this;
44

55
vm.loading = false;
6+
vm.formsExtensionInstalled = false;
67
vm.contentConfigs = [];
8+
vm.formConfigs = [];
79

810
getContentConfigs();
911

12+
umbracoCmsIntegrationsAutomationZapierResource.checkFormsExtension().then(function (response) {
13+
vm.formsExtensionInstalled = response;
14+
15+
if (response) {
16+
getFormConfigs();
17+
}
18+
});
19+
1020
function getContentConfigs() {
1121
vm.loading = true;
1222
umbracoCmsIntegrationsAutomationZapierResource.getAllContentConfigs().then(function (response) {
@@ -15,6 +25,14 @@
1525
});
1626
}
1727

28+
function getFormConfigs() {
29+
vm.loading = true;
30+
umbracoCmsIntegrationsAutomationZapierResource.getAllFormConfigs().then(function (response) {
31+
vm.formConfigs = response;
32+
vm.loading = false;
33+
});
34+
}
35+
1836
}
1937

2038
angular.module("umbraco")

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44
const apiEndpoint = "backoffice/UmbracoCmsIntegrationsAutomationZapier/ZapierConfig";
55

66
return {
7-
getAllContentConfigs: function () {
7+
getAllContentConfigs: function() {
88
return umbRequestHelper.resourcePromise(
9-
$http.get(`${apiEndpoint}/GetAll`), "Failed to get resource");
9+
$http.get(`${apiEndpoint}/GetAll`),
10+
"Failed to get resource");
11+
},
12+
checkFormsExtension: function() {
13+
return umbRequestHelper.resourcePromise(
14+
$http.get(`${apiEndpoint}/IsFormsExtensionInstalled`), "Failed to get resource");
15+
},
16+
getAllFormConfigs: function() {
17+
return umbRequestHelper.resourcePromise(
18+
$http.get(`${apiEndpoint}/GetAllForms`), "Failed to get resource");
1019
}
1120
};
1221
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ public class Constants
55
{
66
public const string ZapierSubscriptionHookTable = "zapierSubscriptionHook";
77

8-
public const string MigrationPlanName = "ZapierSubscriptionHook";
8+
public const string ZapierFormSubscriptionHookTable = "zapierFormSubscriptionHook";
9+
10+
public const string MigrationPlanName = "ZapierMigrationPlan";
911

1012
public const string TargetStateName = "zapiersubscriptionhook-db";
1113

@@ -30,7 +32,6 @@ public static class Content
3032
public const string Name = "Name";
3133

3234
public const string PublishDate = "PublishDate";
33-
3435
}
3536
}
3637
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ public bool UpdateFormPreferences([FromBody] FormSubscriptionDto dto)
107107

108108
if (dto == null) return false;
109109

110-
return true;
110+
var result = dto.SubscribeHook
111+
? _zapierSubscriptionHookService.Add(dto.FormName, dto.HookUrl)
112+
: _zapierSubscriptionHookService.Delete(dto.FormName, dto.HookUrl);
113+
114+
return string.IsNullOrEmpty(result);
111115
}
112116
}
113117
}

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Threading.Tasks;
4-
4+
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
55
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
66
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
77

@@ -25,31 +25,31 @@ public class ZapierConfigController : UmbracoAuthorizedApiController
2525
{
2626
private readonly ZapierSubscriptionHookService _zapierSubscriptionHookService;
2727

28+
private readonly ZapierFormSubscriptionHookService _zapierFormSubscriptionHookService;
29+
2830
private readonly ZapierService _zapierService;
2931

30-
public ZapierConfigController(ZapierSubscriptionHookService zapierSubscriptionHookService, ZapierService zapierService)
32+
public ZapierConfigController(
33+
ZapierSubscriptionHookService zapierSubscriptionHookService,
34+
ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
35+
ZapierService zapierService)
3136
{
3237
_zapierSubscriptionHookService = zapierSubscriptionHookService;
3338

39+
_zapierFormSubscriptionHookService = zapierFormSubscriptionHookService;
40+
3441
_zapierService = zapierService;
3542
}
3643

37-
[HttpPost]
38-
public string Add([FromBody] ContentConfigDto dto)
39-
{
40-
var getByAliasResult = _zapierSubscriptionHookService.TryGetByAlias(dto.ContentTypeAlias, out _);
41-
if (getByAliasResult) return "A record for this content type already exists.";
44+
[HttpGet]
45+
public IEnumerable<ContentConfigDto> GetAll() => _zapierSubscriptionHookService.GetAll();
4246

43-
var result = _zapierSubscriptionHookService.Add(dto.ContentTypeAlias, dto.HookUrl);
44-
45-
return result;
46-
}
47+
[HttpGet]
48+
public bool IsFormsExtensionInstalled() => FormsHelper.IsFormsExtensionInstalled;
4749

4850
[HttpGet]
49-
public IEnumerable<ContentConfigDto> GetAll() => _zapierSubscriptionHookService.GetAll();
51+
public IEnumerable<FormConfigDto> GetAllForms() => _zapierFormSubscriptionHookService.GetAll();
5052

51-
[HttpDelete]
52-
public string Delete(string contentTypeAlias, string hookUrl) => _zapierSubscriptionHookService.Delete(contentTypeAlias, hookUrl);
5353

5454
[HttpPost]
5555
public async Task<string> TriggerWebHook([FromBody] ContentConfigDto dto)

src/Umbraco.Cms.Integrations.Automation.Zapier/Helpers/FormHelper.cs renamed to src/Umbraco.Cms.Integrations.Automation.Zapier/Helpers/FormsHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
namespace Umbraco.Cms.Integrations.Automation.Zapier.Helpers
77
{
8-
public class FormHelper
8+
public class FormsHelper
99
{
10+
public static bool IsFormsExtensionInstalled => Type.GetType("Umbraco.Forms.Core.Services.IFormService, Umbraco.Forms.Core") != null;
11+
1012
public static IEnumerable<MethodInfo> GetMethodsForType(Type type)
1113
{
1214
foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))

src/Umbraco.Cms.Integrations.Automation.Zapier/Migrations/UmbracoAppStartingHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using Umbraco.Cms.Core.Notifications;
66
using Umbraco.Cms.Core.Scoping;
77
using Umbraco.Cms.Core.Services;
8-
using Umbraco.Cms.Infrastructure.Migrations;
98
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
9+
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
1010

1111
namespace Umbraco.Cms.Integrations.Automation.Zapier.Migrations
1212
{
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using NPoco;
2+
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
3+
4+
#if NETCOREAPP
5+
using Microsoft.Extensions.Logging;
6+
7+
using Umbraco.Cms.Infrastructure.Migrations;
8+
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations;
9+
#else
10+
using Umbraco.Core.Migrations;
11+
using Umbraco.Core.Persistence.DatabaseAnnotations;
12+
using Umbraco.Core.Logging;
13+
#endif
14+
15+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Migrations
16+
{
17+
public class ZapierMigration : MigrationBase
18+
{
19+
public string MigrationLoggingMessage = $"Running migration {Constants.MigrationPlanName}";
20+
21+
public string ContentDbTableExistsMessage =
22+
$"The database table {Constants.ZapierSubscriptionHookTable} already exists, skipping";
23+
24+
public string FormDbTableExistsMessage =
25+
$"The database table {Constants.ZapierFormSubscriptionHookTable} already exists, skipping";
26+
27+
public ZapierMigration(IMigrationContext context) : base(context)
28+
{
29+
}
30+
31+
#if NETCOREAPP
32+
protected override void Migrate()
33+
#else
34+
public override void Migrate()
35+
#endif
36+
{
37+
#if NETCOREAPP
38+
Logger.LogDebug(MigrationLoggingMessage);
39+
40+
#else
41+
Logger.Debug<ZapierMigration>(MigrationLoggingMessage);
42+
#endif
43+
44+
if (TableExists(Constants.ZapierSubscriptionHookTable) == false)
45+
{
46+
Create.Table<ZapierSubscriptionHookTable>().Do();
47+
}
48+
else
49+
{
50+
#if NETCOREAPP
51+
Logger.LogDebug(ContentDbTableExistsMessage);
52+
#else
53+
Logger.Debug<ZapierMigration>(ContentDbTableExistsMessage);
54+
#endif
55+
}
56+
57+
if (FormsHelper.IsFormsExtensionInstalled)
58+
{
59+
if (TableExists(Constants.ZapierFormSubscriptionHookTable) == false)
60+
{
61+
Create.Table<ZapierFormSubscriptionHookTable>().Do();
62+
}
63+
else
64+
{
65+
#if NETCOREAPP
66+
Logger.LogDebug(FormDbTableExistsMessage);
67+
#else
68+
Logger.Debug<ZapierMigration>(FormDbTableExistsMessage);
69+
#endif
70+
}
71+
}
72+
}
73+
74+
[TableName(Constants.ZapierSubscriptionHookTable)]
75+
[PrimaryKey("Id", AutoIncrement = true)]
76+
[ExplicitColumns]
77+
public class ZapierSubscriptionHookTable
78+
{
79+
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
80+
[Column("Id")]
81+
public int Id { get; set; }
82+
83+
[Column("ContentTypeAlias")]
84+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierSubscriptionHook_ContentTypeAlias")]
85+
public string ContentTypeAlias { get; set; }
86+
87+
[Column("HookUrl")]
88+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierSubscriptionHook_HookUrl")]
89+
public string HookUrl { get; set; }
90+
}
91+
92+
[TableName(Constants.ZapierFormSubscriptionHookTable)]
93+
[PrimaryKey("Id", AutoIncrement = true)]
94+
[ExplicitColumns]
95+
public class ZapierFormSubscriptionHookTable
96+
{
97+
[PrimaryKeyColumn(AutoIncrement = true, IdentitySeed = 1)]
98+
[Column("Id")]
99+
public int Id { get; set; }
100+
101+
[Column("FormName")]
102+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierFormSubscriptionHook_FormName")]
103+
public string FormName { get; set; }
104+
105+
[Column("HookUrl")]
106+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierFormSubscriptionHook_HookUrl")]
107+
public string HookUrl { get; set; }
108+
}
109+
}
110+
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Migrations/ZapContentConfigComponent.cs renamed to src/Umbraco.Cms.Integrations.Automation.Zapier/Migrations/ZapierMigrationComponent.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
using Umbraco.Core.Scoping;
88
using Umbraco.Core.Services;
99

10-
1110
namespace Umbraco.Cms.Integrations.Automation.Zapier.Migrations
1211
{
1312
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
14-
public class ZapContentConfigComposer : ComponentComposer<ZapContentConfigComponent>
13+
public class ZapierMigrationComposer : ComponentComposer<ZapierMigrationComponent>
1514
{
1615

1716
}
1817

19-
public class ZapContentConfigComponent : IComponent
18+
public class ZapierMigrationComponent : IComponent
2019
{
2120
private IScopeProvider _scopeProvider;
2221

@@ -26,7 +25,7 @@ public class ZapContentConfigComponent : IComponent
2625

2726
private ILogger _logger;
2827

29-
public ZapContentConfigComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
28+
public ZapierMigrationComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
3029
{
3130
_scopeProvider = scopeProvider;
3231

0 commit comments

Comments
 (0)