Skip to content

Commit b26a2a5

Browse files
authored
Merge pull request #21 from umbraco/feature/zapier-migration
Migration update
2 parents d7a7e13 + fdc30c9 commit b26a2a5

File tree

15 files changed

+95
-330
lines changed

15 files changed

+95
-330
lines changed

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

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,22 @@
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.subscriptionHooks.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.subscriptionHooks.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>Identifier</span>
4949
</a>
5050
</div>
5151
<div class="umb-table-cell">
5252
<a class="umb-table-head__link" href="#" prevent-default>
53-
<span>Hook URL</span>
54-
</a>
55-
</div>
56-
</div>
57-
</div>
58-
59-
<!-- Listview body section -->
60-
<div class="umb-table-body">
61-
<div class="umb-table-row"
62-
ng-repeat="row in vm.contentConfigs track by $index">
63-
<div class="umb-table-cell"></div>
64-
<div class="umb-table-cell umb-table__name">
65-
<span ng-bind="row.contentTypeAlias"></span>
66-
</div>
67-
<div class="umb-table-cell">
68-
<span ng-bind="row.hookUrl"></span>
69-
</div>
70-
</div>
71-
</div>
72-
</div>
73-
</div>
74-
</umb-box-content>
75-
</umb-box>
76-
<umb-box ng-if="vm.formsExtensionInstalled">
77-
<umb-box-header title="Registered Form Subscription Hooks"></umb-box-header>
78-
<umb-box-content>
79-
<div>
80-
<p ng-if="vm.formConfigs.length == 0">There are no form subscription hooks.</p>
81-
</div>
82-
<div class="mt2">
83-
<div class="umb-table" ng-if="vm.formConfigs.length > 0">
84-
<!-- Listviews head section -->
85-
<div class="umb-table-head">
86-
<div class="umb-table-row">
87-
<div class="umb-table-cell"></div>
88-
<div class="umb-table-cell umb-table__name">
89-
<a class="umb-table-head__link" href="#" prevent-default>
90-
<span>Form Name</span>
53+
<span>Entity Type</span>
9154
</a>
9255
</div>
9356
<div class="umb-table-cell">
@@ -101,10 +64,13 @@
10164
<!-- Listview body section -->
10265
<div class="umb-table-body">
10366
<div class="umb-table-row"
104-
ng-repeat="row in vm.formConfigs track by $index">
67+
ng-repeat="row in vm.subscriptionHooks track by $index">
10568
<div class="umb-table-cell"></div>
10669
<div class="umb-table-cell umb-table__name">
107-
<span ng-bind="row.formName"></span>
70+
<span ng-bind="row.entityId"></span>
71+
</div>
72+
<div class="umb-table-cell">
73+
<span ng-bind="row.typeName"></span>
10874
</div>
10975
<div class="umb-table-cell">
11076
<span ng-bind="row.hookUrl"></span>

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

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

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

10-
getContentConfigs();
8+
vm.subscriptionHooks = [];
119

10+
// check if forms is installed
1211
umbracoCmsIntegrationsAutomationZapierResource.checkFormsExtension().then(function (response) {
1312
vm.formsExtensionInstalled = response;
14-
15-
if (response) {
16-
getFormConfigs();
17-
}
1813
});
1914

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-
}
15+
// load subscription hooks
16+
vm.loading = true;
17+
umbracoCmsIntegrationsAutomationZapierResource.getAll().then(function (response) {
18+
19+
vm.subscriptionHooks = response;
20+
21+
vm.loading = false;
22+
});
3523

3624
}
3725

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: 8 additions & 3 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";
@@ -25,13 +23,20 @@ public static class Configuration
2523
public const string Settings = "Umbraco:Forms:Integrations:Automation:Zapier:Settings";
2624
}
2725

28-
public static class Content
26+
public static class ContentProperties
2927
{
3028
public const string Id = "id";
3129

3230
public const string Name = "name";
3331

3432
public const string PublishDate = "publishDate";
3533
}
34+
35+
public static class EntityType
36+
{
37+
public const int Content = 1;
38+
39+
public const int Form = 2;
40+
}
3641
}
3742
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#else
1313
using System.Web.Http;
1414
using System.Configuration;
15-
15+
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
1616
using Umbraco.Web.WebApi;
1717
#endif
1818

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
1+
using System.Collections.Generic;
2+
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
23
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
34

45
#if NETCOREAPP
@@ -19,25 +20,19 @@ public class SubscriptionController : ZapierAuthorizedApiController
1920
{
2021
private readonly ZapierSubscriptionHookService _zapierSubscriptionHookService;
2122

22-
private readonly ZapierFormSubscriptionHookService _zapierFormSubscriptionHookService;
23-
2423
#if NETCOREAPP
2524
public SubscriptionController(IOptions<ZapierSettings> options,
26-
ZapierSubscriptionHookService zapierSubscriptionHookService,
27-
ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
25+
ZapierSubscriptionHookService zapierSubscriptionHookService,
2826
IUserValidationService userValidationService)
2927
: base(options, userValidationService)
3028
#else
3129
public SubscriptionController(
3230
ZapierSubscriptionHookService zapierSubscriptionHookService,
33-
ZapierFormSubscriptionHookService zapierFormSubscriptionHookService,
3431
IUserValidationService userValidationService)
3532
: base(userValidationService)
3633
#endif
3734
{
3835
_zapierSubscriptionHookService = zapierSubscriptionHookService;
39-
40-
_zapierFormSubscriptionHookService = zapierFormSubscriptionHookService;
4136
}
4237

4338
[HttpPost]
@@ -46,20 +41,8 @@ public bool UpdatePreferences([FromBody] SubscriptionDto dto)
4641
if (!IsUserValid() || dto == null) return false;
4742

4843
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);
44+
? _zapierSubscriptionHookService.Add(dto.EntityId, dto.Type, dto.HookUrl)
45+
: _zapierSubscriptionHookService.Delete(dto.EntityId, dto.Type, dto.HookUrl);
6346

6447
return string.IsNullOrEmpty(result);
6548
}
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
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Extensions/ContentExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public static Dictionary<string, string> ToContentTypeDictionary(this IContentTy
1515
{
1616
var contentDict = new Dictionary<string, string>
1717
{
18-
{Constants.Content.Id, "1" },
19-
{Constants.Content.Name, contentType.Name },
20-
{Constants.Content.PublishDate, DateTime.UtcNow.ToString("s") }
18+
{Constants.ContentProperties.Id, "1" },
19+
{Constants.ContentProperties.Name, contentType.Name },
20+
{Constants.ContentProperties.PublishDate, DateTime.UtcNow.ToString("s") }
2121
};
2222

2323
foreach (var propertyType in contentType.PropertyTypes)
@@ -32,9 +32,9 @@ public static Dictionary<string, string> ToContentDictionary(this IContent conte
3232
{
3333
var contentDict = new Dictionary<string, string>
3434
{
35-
{Constants.Content.Id, contentNode.Id.ToString() },
36-
{Constants.Content.Name, contentNode.Name },
37-
{Constants.Content.PublishDate, contentNode.UpdateDate.ToString("s") }
35+
{Constants.ContentProperties.Id, contentNode.Id.ToString() },
36+
{Constants.ContentProperties.Name, contentNode.Name },
37+
{Constants.ContentProperties.PublishDate, contentNode.UpdateDate.ToString("s") }
3838
};
3939

4040
foreach (var prop in contentNode.Properties)

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

Lines changed: 11 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,30 +60,20 @@ 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; }
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; }
63+
/// <summary>
64+
/// Column stores two types of references:
65+
/// 1. content type alias for content triggers
66+
/// 2. form ID for form triggers
67+
/// </summary>
68+
[Column("EntityId")]
69+
public string EntityId { get; set; }
10070

101-
[Column("FormName")]
102-
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierFormSubscriptionHook_FormName")]
103-
public string FormName { get; set; }
71+
[Column("Type")]
72+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierSubscriptionHook_Type", ForColumns = "EntityId,Type")]
73+
public int Type { get; set; }
10474

10575
[Column("HookUrl")]
106-
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierFormSubscriptionHook_HookUrl")]
76+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapierSubscriptionHook_HookUrl")]
10777
public string HookUrl { get; set; }
10878
}
10979
}

0 commit comments

Comments
 (0)