Skip to content

Commit b9f94f2

Browse files
committed
Update migration to merge subcriptions into a single table and update references.
1 parent d7a7e13 commit b9f94f2

File tree

13 files changed

+62
-288
lines changed

13 files changed

+62
-288
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@
3535
<umb-box-header title="Registered Subscription Hooks"></umb-box-header>
3636
<umb-box-content>
3737
<div>
38-
<p ng-if="vm.contentConfigs.length == 0">There are no subscription hooks.</p>
38+
<p ng-if="vm.contentSubscriptionHooks.length == 0">There are no subscription hooks.</p>
3939
</div>
4040
<div class="mt2">
41-
<div class="umb-table" ng-if="vm.contentConfigs.length > 0">
41+
<div class="umb-table" ng-if="vm.contentSubscriptionHooks.length > 0">
4242
<!-- Listviews head section -->
4343
<div class="umb-table-head">
4444
<div class="umb-table-row">
4545
<div class="umb-table-cell"></div>
4646
<div class="umb-table-cell umb-table__name">
4747
<a class="umb-table-head__link" href="#" prevent-default>
48-
<span>Content Type Alias</span>
48+
<span>Name</span>
4949
</a>
5050
</div>
5151
<div class="umb-table-cell">
@@ -59,10 +59,10 @@
5959
<!-- Listview body section -->
6060
<div class="umb-table-body">
6161
<div class="umb-table-row"
62-
ng-repeat="row in vm.contentConfigs track by $index">
62+
ng-repeat="row in vm.contentSubscriptionHooks track by $index">
6363
<div class="umb-table-cell"></div>
6464
<div class="umb-table-cell umb-table__name">
65-
<span ng-bind="row.contentTypeAlias"></span>
65+
<span ng-bind="row.entityId"></span>
6666
</div>
6767
<div class="umb-table-cell">
6868
<span ng-bind="row.hookUrl"></span>
@@ -77,17 +77,17 @@
7777
<umb-box-header title="Registered Form Subscription Hooks"></umb-box-header>
7878
<umb-box-content>
7979
<div>
80-
<p ng-if="vm.formConfigs.length == 0">There are no form subscription hooks.</p>
80+
<p ng-if="vm.formSubscriptionHooks.length == 0">There are no form subscription hooks.</p>
8181
</div>
8282
<div class="mt2">
83-
<div class="umb-table" ng-if="vm.formConfigs.length > 0">
83+
<div class="umb-table" ng-if="vm.formSubscriptionHooks.length > 0">
8484
<!-- Listviews head section -->
8585
<div class="umb-table-head">
8686
<div class="umb-table-row">
8787
<div class="umb-table-cell"></div>
8888
<div class="umb-table-cell umb-table__name">
8989
<a class="umb-table-head__link" href="#" prevent-default>
90-
<span>Form Name</span>
90+
<span>Form Id</span>
9191
</a>
9292
</div>
9393
<div class="umb-table-cell">
@@ -101,10 +101,10 @@
101101
<!-- Listview body section -->
102102
<div class="umb-table-body">
103103
<div class="umb-table-row"
104-
ng-repeat="row in vm.formConfigs track by $index">
104+
ng-repeat="row in vm.formSubscriptionHooks track by $index">
105105
<div class="umb-table-cell"></div>
106106
<div class="umb-table-cell umb-table__name">
107-
<span ng-bind="row.formName"></span>
107+
<span ng-bind="row.entityId"></span>
108108
</div>
109109
<div class="umb-table-cell">
110110
<span ng-bind="row.hookUrl"></span>

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,24 @@
44

55
vm.loading = false;
66
vm.formsExtensionInstalled = false;
7-
vm.contentConfigs = [];
8-
vm.formConfigs = [];
97

10-
getContentConfigs();
8+
vm.contentSubscriptionHooks = [];
9+
vm.formSubscriptionHooks = [];
1110

11+
// check if forms is installed
1212
umbracoCmsIntegrationsAutomationZapierResource.checkFormsExtension().then(function (response) {
1313
vm.formsExtensionInstalled = response;
14-
15-
if (response) {
16-
getFormConfigs();
17-
}
1814
});
1915

20-
function getContentConfigs() {
21-
vm.loading = true;
22-
umbracoCmsIntegrationsAutomationZapierResource.getAllContentConfigs().then(function (response) {
23-
vm.contentConfigs = response;
24-
vm.loading = false;
25-
});
26-
}
27-
28-
function getFormConfigs() {
29-
vm.loading = true;
30-
umbracoCmsIntegrationsAutomationZapierResource.getAllFormConfigs().then(function (response) {
31-
vm.formConfigs = response;
32-
vm.loading = false;
33-
});
34-
}
16+
// load subscription hooks
17+
vm.loading = true;
18+
umbracoCmsIntegrationsAutomationZapierResource.getAll().then(function (response) {
19+
20+
vm.contentSubscriptionHooks = response.filter(p => p.isFormSubscription === false);
21+
vm.formSubscriptionHooks = response.filter(p => p.isFormSubscription === true);
22+
23+
vm.loading = false;
24+
});
3525

3626
}
3727

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
const apiEndpoint = "backoffice/UmbracoCmsIntegrationsAutomationZapier/ZapierConfig";
55

66
return {
7-
getAllContentConfigs: function() {
7+
getAll: function() {
88
return umbRequestHelper.resourcePromise(
99
$http.get(`${apiEndpoint}/GetAll`),
1010
"Failed to get resource");
1111
},
1212
checkFormsExtension: function() {
1313
return umbRequestHelper.resourcePromise(
1414
$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");
1915
}
2016
};
2117
}

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

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

8-
public const string ZapierFormSubscriptionHookTable = "zapierFormSubscriptionHook";
9-
108
public const string MigrationPlanName = "ZapierMigrationPlan";
119

1210
public const string TargetStateName = "zapiersubscriptionhook-db";

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

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,19 @@ public class SubscriptionController : ZapierAuthorizedApiController
1919
{
2020
private readonly ZapierSubscriptionHookService _zapierSubscriptionHookService;
2121

22-
private readonly ZapierFormSubscriptionHookService _zapierFormSubscriptionHookService;
23-
2422
#if NETCOREAPP
2523
public SubscriptionController(IOptions<ZapierSettings> options,
26-
ZapierSubscriptionHookService zapierSubscriptionHookService,
27-
ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
24+
ZapierSubscriptionHookService zapierSubscriptionHookService,
2825
IUserValidationService userValidationService)
2926
: base(options, userValidationService)
3027
#else
3128
public SubscriptionController(
3229
ZapierSubscriptionHookService zapierSubscriptionHookService,
33-
ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
3430
IUserValidationService userValidationService)
3531
: base(userValidationService)
3632
#endif
3733
{
3834
_zapierSubscriptionHookService = zapierSubscriptionHookService;
39-
40-
_zapierFormSubscriptionHookService = zapierFormSubscriptionHookService;
4135
}
4236

4337
[HttpPost]
@@ -46,20 +40,8 @@ public bool UpdatePreferences([FromBody] SubscriptionDto dto)
4640
if (!IsUserValid() || dto == null) return false;
4741

4842
var result = dto.SubscribeHook
49-
? _zapierSubscriptionHookService.Add(dto.ContentType, dto.HookUrl)
50-
: _zapierSubscriptionHookService.Delete(dto.ContentType, dto.HookUrl);
51-
52-
return string.IsNullOrEmpty(result);
53-
}
54-
55-
[HttpPost]
56-
public bool UpdateFormPreferences([FromBody] FormSubscriptionDto dto)
57-
{
58-
if (!IsUserValid() || dto == null) return false;
59-
60-
var result = dto.SubscribeHook
61-
? _zapierFormSubscriptionHookService.Add(dto.FormName, dto.HookUrl)
62-
: _zapierFormSubscriptionHookService.Delete(dto.FormName, dto.HookUrl);
43+
? _zapierSubscriptionHookService.Add(dto.EntityId, dto.HookUrl)
44+
: _zapierSubscriptionHookService.Delete(dto.EntityId, dto.HookUrl);
6345

6446
return string.IsNullOrEmpty(result);
6547
}
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Threading.Tasks;
32

43
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
54
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
@@ -24,37 +23,16 @@ public class ZapierConfigController : UmbracoAuthorizedApiController
2423
{
2524
private readonly ZapierSubscriptionHookService _zapierSubscriptionHookService;
2625

27-
private readonly ZapierFormSubscriptionHookService _zapierFormSubscriptionHookService;
28-
29-
private readonly ZapierService _zapierService;
30-
3126
public ZapierConfigController(
32-
ZapierSubscriptionHookService zapierSubscriptionHookService,
33-
ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
34-
ZapierService zapierService)
27+
ZapierSubscriptionHookService zapierSubscriptionHookService)
3528
{
3629
_zapierSubscriptionHookService = zapierSubscriptionHookService;
37-
38-
_zapierFormSubscriptionHookService = zapierFormSubscriptionHookService;
39-
40-
_zapierService = zapierService;
4130
}
4231

4332
[HttpGet]
44-
public IEnumerable<ContentConfigDto> GetAll() => _zapierSubscriptionHookService.GetAll();
33+
public IEnumerable<SubscriptionDto> GetAll() => _zapierSubscriptionHookService.GetAll();
4534

4635
[HttpGet]
4736
public bool IsFormsExtensionInstalled() => ReflectionHelper.IsFormsExtensionInstalled;
48-
49-
[HttpGet]
50-
public IEnumerable<FormConfigDto> GetAllForms() => _zapierFormSubscriptionHookService.GetAll();
51-
52-
53-
[HttpPost]
54-
public async Task<string> TriggerWebHook([FromBody] ContentConfigDto dto)
55-
{
56-
return await _zapierService.TriggerAsync(dto.HookUrl,
57-
new Dictionary<string, string> { { Constants.Content.Name, dto.ContentTypeAlias } });
58-
}
5937
}
6038
}
Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using NPoco;
2-
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
32

43
#if NETCOREAPP
54
using Microsoft.Extensions.Logging;
@@ -21,9 +20,6 @@ public class ZapierMigration : MigrationBase
2120
public string ContentDbTableExistsMessage =
2221
$"The database table {Constants.ZapierSubscriptionHookTable} already exists, skipping";
2322

24-
public string FormDbTableExistsMessage =
25-
$"The database table {Constants.ZapierFormSubscriptionHookTable} already exists, skipping";
26-
2723
public ZapierMigration(IMigrationContext context) : base(context)
2824
{
2925
}
@@ -53,22 +49,6 @@ public override void Migrate()
5349
Logger.Debug<ZapierMigration>(ContentDbTableExistsMessage);
5450
#endif
5551
}
56-
57-
if (ReflectionHelper.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-
}
7252
}
7353

7454
[TableName(Constants.ZapierSubscriptionHookTable)]
@@ -80,31 +60,18 @@ public class ZapierSubscriptionHookTable
8060
[Column("Id")]
8161
public int Id { get; set; }
8262

83-
[Column("ContentTypeAlias")]
84-
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierSubscriptionHook_ContentTypeAlias")]
85-
public string ContentTypeAlias { get; set; }
63+
/// <summary>
64+
/// Column stores two types of references:
65+
/// 1. content type for content triggers
66+
/// 2. form ID for form triggers
67+
/// </summary>
68+
[Column("EntityId")]
69+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierSubscriptionHook_EntityId")]
70+
public string EntityId { get; set; }
8671

8772
[Column("HookUrl")]
8873
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierSubscriptionHook_HookUrl")]
8974
public string HookUrl { get; set; }
9075
}
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-
}
10976
}
11077
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Models/Dtos/ContentConfigDto.cs

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

src/Umbraco.Cms.Integrations.Automation.Zapier/Models/Dtos/PublishedContentDto.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
3+
using Newtonsoft.Json;
24

35
namespace Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos
46
{
7+
[Obsolete("Used only by Umbraco Zapier App v1.0.0")]
58
public class PublishedContentDto
69
{
710
[JsonProperty("id")]
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
3+
using Newtonsoft.Json;
24

35
namespace Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos
46
{
57
public class SubscriptionDto
68
{
9+
[JsonProperty("id")]
10+
public int Id { get; set; }
11+
12+
[JsonProperty("entityId")]
13+
public string EntityId { get; set; }
14+
715
[JsonProperty("hookUrl")]
816
public string HookUrl { get; set; }
917

10-
[JsonProperty("contentType")]
11-
public string ContentType { get; set; }
12-
1318
[JsonProperty("subscribeHook")]
1419
public bool SubscribeHook { get; set; }
20+
21+
[JsonProperty("isFormSubscription")]
22+
public bool IsFormSubscription => Guid.TryParse(EntityId, out _);
1523
}
1624
}

0 commit comments

Comments
 (0)