Skip to content

Commit c409d41

Browse files
authored
Merge pull request #13 from umbraco/feature/zapier-v9-multi-target
Zapier V9 multi-target
2 parents 6bc0d05 + 26283a4 commit c409d41

19 files changed

+393
-69
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(["zapierDashboard_promptDeleteTitle", "zapierDashboard_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
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<language>
3-
<area alias="dashboardTabs">
4-
<key alias="zapierDashboard">Zapier Integrations</key>
3+
<area alias="zapierDashboard">
4+
<key alias="title">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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
using System;
1+
#if NETFRAMEWORK
2+
using System;
23
using System.Collections.Generic;
3-
using System.Net.Http;
44
using System.Threading.Tasks;
5+
56
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
67
using Umbraco.Core;
78
using Umbraco.Core.Composing;
89
using Umbraco.Core.Events;
910
using Umbraco.Core.Logging;
10-
using Umbraco.Core.Models;
1111
using Umbraco.Core.Services;
1212
using Umbraco.Core.Services.Implement;
1313

@@ -68,3 +68,4 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
6868
}
6969
}
7070
}
71+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#if NETCOREAPP
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
6+
using Microsoft.Extensions.Logging;
7+
8+
using Umbraco.Cms.Core.Events;
9+
using Umbraco.Cms.Core.Notifications;
10+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
11+
12+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
13+
{
14+
public class NewContentPublishedNotification : INotificationHandler<ContentPublishedNotification>
15+
{
16+
private readonly ZapConfigService _zapConfigService;
17+
18+
private readonly ZapierService _zapierService;
19+
20+
private readonly ILogger<NewContentPublishedNotification> _logger;
21+
22+
public NewContentPublishedNotification(ZapConfigService zapConfigService, ZapierService zapierService, ILogger<NewContentPublishedNotification> logger)
23+
{
24+
_zapConfigService = zapConfigService;
25+
26+
_zapierService = zapierService;
27+
28+
_logger = logger;
29+
}
30+
31+
public void Handle(ContentPublishedNotification notification)
32+
{
33+
foreach (var node in notification.PublishedEntities)
34+
{
35+
var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name);
36+
if (zapContentConfig == null) continue;
37+
38+
var content = new Dictionary<string, string>
39+
{
40+
{ Constants.Content.Name, node.Name },
41+
{ Constants.Content.PublishDate, DateTime.UtcNow.ToString() }
42+
};
43+
44+
var t = Task.Run(async () => await _zapierService.TriggerAsync(zapContentConfig.WebHookUrl, content));
45+
46+
var result = t.Result;
47+
48+
if (!string.IsNullOrEmpty(result))
49+
_logger.LogError(result);
50+
}
51+
}
52+
}
53+
}
54+
#endif
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";

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

+50-13
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,70 @@
1-
using System.Configuration;
2-
using System.Linq;
3-
using System.Web.Http;
1+
using System.Linq;
2+
using System.Threading.Tasks;
43

4+
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
55
using Umbraco.Cms.Integrations.Automation.Zapier.Models;
6-
using Umbraco.Core.Services;
6+
7+
8+
#if NETCOREAPP
9+
using Microsoft.AspNetCore.Mvc;
10+
using Microsoft.Extensions.Options;
11+
using Umbraco.Cms.Web.Common.Controllers;
12+
using Umbraco.Cms.Core.Security;
13+
using Umbraco.Cms.Core.Services;
14+
#else
15+
using System.Web.Http;
16+
using System.Configuration;
17+
718
using Umbraco.Web.WebApi;
19+
using Umbraco.Core.Services;
20+
#endif
821

922
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
1023
{
1124
public class AuthController : UmbracoApiController
1225
{
13-
private const string UmbracoCmsIntegrationsAutomationZapierUserGroup = "Umbraco.Cms.Integrations.Automation.Zapier.UserGroup";
26+
private readonly ZapierSettings Options;
27+
28+
private readonly IUserService _userService;
29+
30+
#if NETCOREAPP
31+
private readonly IBackOfficeUserManager _backOfficeUserManager;
32+
33+
public AuthController(IBackOfficeUserManager backOfficeUserManager, IUserService userService, IOptions<ZapierSettings> options)
34+
{
35+
_backOfficeUserManager = backOfficeUserManager;
36+
37+
_userService = userService;
38+
39+
Options = options.Value;
40+
}
41+
#else
42+
public AuthController(IUserService userService)
43+
{
44+
Options = new ZapierSettings(ConfigurationManager.AppSettings);
45+
46+
_userService = userService;
47+
}
48+
#endif
1449

1550
[HttpPost]
16-
public bool ValidateUser([FromBody] UserModel userModel)
51+
public async Task<bool> ValidateUser([FromBody] UserModel userModel)
1752
{
53+
#if NETCOREAPP
54+
var isUserValid =
55+
await _backOfficeUserManager.ValidateCredentialsAsync(userModel.Username, userModel.Password);
56+
#else
1857
var isUserValid = Security.ValidateBackOfficeCredentials(userModel.Username, userModel.Password);
58+
#endif
59+
1960
if (!isUserValid) return false;
2061

21-
var userGroup = ConfigurationManager.AppSettings[UmbracoCmsIntegrationsAutomationZapierUserGroup];
62+
var userGroup = Options.UserGroup;
2263
if (!string.IsNullOrEmpty(userGroup))
2364
{
24-
IUserService userService = Services.UserService;
25-
26-
var user = userService.GetByUsername(userModel.Username);
27-
28-
var isValid = user != null && user.Groups.Any(p => p.Name == userGroup);
65+
var user = _userService.GetByUsername(userModel.Username);
2966

30-
return isValid;
67+
return user != null && user.Groups.Any(p => p.Name == userGroup);
3168
}
3269

3370
return true;

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

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Threading.Tasks;
4-
using System.Web.Http;
54

65
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
76
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
7+
8+
#if NETCOREAPP
9+
using Microsoft.AspNetCore.Mvc;
10+
11+
using Umbraco.Cms.Web.BackOffice.Controllers;
12+
using Umbraco.Cms.Web.Common.Attributes;
13+
using Umbraco.Cms.Core.Services;
14+
#else
15+
using System.Web.Http;
16+
817
using Umbraco.Core.Services;
918
using Umbraco.Web.Mvc;
1019
using Umbraco.Web.WebApi;
20+
#endif
1121

1222
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
1323
{
1424
[PluginController("UmbracoCmsIntegrationsAutomationZapier")]
1525
public class ZapConfigController : UmbracoAuthorizedApiController
1626
{
27+
private readonly IContentTypeService _contentTypeService;
28+
1729
private readonly ZapConfigService _zapConfigService;
1830

1931
private readonly ZapierService _zapierService;
2032

21-
public ZapConfigController(ZapConfigService zapConfigService, ZapierService zapierService)
33+
public ZapConfigController(IContentTypeService contentTypeService, ZapConfigService zapConfigService, ZapierService zapierService)
2234
{
35+
_contentTypeService = contentTypeService;
36+
2337
_zapConfigService = zapConfigService;
2438

2539
_zapierService = zapierService;
@@ -28,9 +42,7 @@ public ZapConfigController(ZapConfigService zapConfigService, ZapierService zapi
2842
[HttpGet]
2943
public IEnumerable<ContentTypeDto> GetContentTypes()
3044
{
31-
IContentTypeService contentTypeService = Services.ContentTypeService;
32-
33-
var contentTypes = contentTypeService.GetAll();
45+
var contentTypes = _contentTypeService.GetAll();
3446

3547
var configEntities = _zapConfigService.GetAll().Select(p => p.ContentTypeName);
3648

@@ -61,7 +73,7 @@ public string Add([FromBody] ContentConfigDto dto)
6173
public string Delete(int id) => _zapConfigService.Delete(id);
6274

6375
[HttpPost]
64-
public async Task<string> TriggerAsync([FromBody] ContentConfigDto dto)
76+
public async Task<string> TriggerWebHook([FromBody] ContentConfigDto dto)
6577
{
6678
return await _zapierService.TriggerAsync(dto.WebHookUrl,
6779
new Dictionary<string, string> { { Constants.Content.Name, dto.ContentTypeName } });

0 commit comments

Comments
 (0)