Skip to content

Commit e7a1763

Browse files
committed
42318 V14 Integration Zapier
- Create management api for Zapier - Update project type - Remove .netapp checking
1 parent e2c8a6a commit e7a1763

File tree

94 files changed

+74838
-561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+74838
-561
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Umbraco.Cms.Api.Management.OpenApi;
2+
3+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Api.Configuration
4+
{
5+
public class BackOfficeSecurityRequirementsOperationFilter : BackOfficeSecurityRequirementsOperationFilterBase
6+
{
7+
protected override string ApiName => Constants.ManagementApi.ApiName;
8+
}
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Threading.Tasks;
2+
using Umbraco.Cms.Integrations.Automation.Zapier.Models;
3+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Umbraco.Cms.Web.Common.Controllers;
6+
using Asp.Versioning;
7+
using Microsoft.Extensions.Options;
8+
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
9+
10+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Api.Management.Controllers
11+
{
12+
/// <summary>
13+
/// When a Zapier user creates triggers using the Umbraco app from the Zapier App Directory, they need to provide valid credentials for a backoffice account.
14+
/// </summary>
15+
[ApiVersion("1.0")]
16+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
17+
public class AuthController : ZapierControllerBase
18+
{
19+
20+
public AuthController(IOptions<ZapierSettings> options, IUserValidationService userValidationService) : base(options, userValidationService)
21+
{
22+
}
23+
24+
[HttpPost("validate-user")]
25+
[ProducesResponseType(typeof(Task<bool>), StatusCodes.Status200OK)]
26+
public async Task<IActionResult> ValidateUser([FromBody] UserModel userModel)
27+
{
28+
var result = await _userValidationService.Validate(userModel.Username, userModel.Password, userModel.ApiKey);
29+
return Ok(result);
30+
}
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using Umbraco.Cms.Integrations.Automation.Zapier.Helpers;
3+
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
4+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Umbraco.Cms.Web.Common.Attributes;
7+
using Microsoft.Extensions.Options;
8+
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
9+
using Asp.Versioning;
10+
11+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Api.Management.Controllers
12+
{
13+
[ApiVersion("1.0")]
14+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
15+
public class ConfigController : ZapierControllerBase
16+
{
17+
private readonly ZapierSubscriptionHookService _zapierSubscriptionHookService;
18+
19+
public ConfigController(IOptions<ZapierSettings> options, IUserValidationService userValidationService, ZapierSubscriptionHookService zapierSubscriptionHookService) : base(options, userValidationService)
20+
{
21+
_zapierSubscriptionHookService = zapierSubscriptionHookService;
22+
}
23+
24+
[HttpGet("all")]
25+
[ProducesResponseType(typeof(IEnumerable<SubscriptionDto>), StatusCodes.Status200OK)]
26+
public IActionResult GetAll() => Ok(_zapierSubscriptionHookService.GetAll());
27+
28+
[HttpGet("form-extension-installed")]
29+
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
30+
public IActionResult IsFormsExtensionInstalled() => Ok(ReflectionHelper.IsFormsExtensionInstalled);
31+
}
32+
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/ContentController.cs renamed to src/Umbraco.Cms.Integrations.Automation.Zapier/Api/Management/Controllers/ContentController.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,48 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
43
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
54
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
6-
7-
#if NETCOREAPP
85
using Microsoft.Extensions.Options;
9-
106
using Umbraco.Cms.Core.Services;
117
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
12-
#else
13-
using Umbraco.Core.Services;
14-
#endif
8+
using Asp.Versioning;
9+
using Microsoft.AspNetCore.Mvc;
10+
using Microsoft.AspNetCore.Mvc.Formatters.Xml;
1511

16-
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
12+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Api.Management.Controllers
1713
{
1814
/// <summary>
1915
/// When a Zapier user creates a new "New Content Published" trigger, the API is used to provide the list of content types for handling "Published" event.
2016
/// </summary>
21-
public class ContentController : ZapierAuthorizedApiController
17+
[ApiVersion("1.0")]
18+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
19+
public class ContentController : ZapierControllerBase
2220
{
2321
private readonly IContentTypeService _contentTypeService;
24-
25-
#if NETCOREAPP
2622
public ContentController(IOptions<ZapierSettings> options, IContentTypeService contentTypeService, IUserValidationService userValidationService)
2723
: base(options, userValidationService)
28-
#else
29-
public ContentController(IContentTypeService contentTypeService, IUserValidationService userValidationService)
30-
: base(userValidationService)
31-
#endif
3224
{
3325
_contentTypeService = contentTypeService;
3426
}
3527

36-
public IEnumerable<ContentTypeDto> GetContentTypes()
28+
[HttpGet("content-types")]
29+
[ProducesResponseType(typeof(IEnumerable<ContentTypeDto>), StatusCodes.Status200OK)]
30+
[ProducesResponseType(StatusCodes.Status404NotFound)]
31+
public IActionResult GetContentTypes()
3732
{
38-
if (!IsAccessValid()) return null;
33+
if (!IsAccessValid())
34+
return NotFound();
3935

4036
var contentTypes = _contentTypeService.GetAll();
41-
42-
return contentTypes
37+
var mapToDto = contentTypes
4338
.Select(q => new ContentTypeDto
4439
{
4540
Id = q.Id,
4641
Alias = q.Alias,
4742
Name = q.Name
4843
});
44+
45+
return Ok(mapToDto);
4946
}
5047

5148
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
4+
using Microsoft.Extensions.Options;
5+
using Umbraco.Cms.Core.Models.PublishedContent;
6+
using Umbraco.Cms.Core.Services;
7+
using Umbraco.Cms.Web.Common;
8+
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
9+
using Asp.Versioning;
10+
using Microsoft.AspNetCore.Mvc;
11+
12+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Api.Management.Controllers
13+
{
14+
/// <summary>
15+
/// When a Zapier user creates a "New Content Published" triggered, they are authenticated, then select a content type, the API provides an output json with the
16+
/// structure of a content node matching the selected content type.
17+
/// For version 1.0.0 of the Umbraco Zapier App, the GetSampleContent will be used.
18+
/// </summary>
19+
[ApiVersion("1.0")]
20+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
21+
public class PollingController : ZapierControllerBase
22+
{
23+
private readonly IContentTypeService _contentTypeService;
24+
25+
private readonly IZapierContentService _zapierContentService;
26+
27+
private readonly UmbracoHelper _umbracoHelper;
28+
29+
public PollingController(
30+
IOptions<ZapierSettings> options,
31+
IContentService contentService,
32+
IContentTypeService contentTypeService,
33+
UmbracoHelper umbracoHelper,
34+
IUserValidationService userValidationService,
35+
IZapierContentService zapierContentService)
36+
: base(options, userValidationService)
37+
{
38+
_contentTypeService = contentTypeService;
39+
_zapierContentService = zapierContentService;
40+
_umbracoHelper = umbracoHelper;
41+
}
42+
43+
[HttpGet("content-by-type")]
44+
[ProducesResponseType(typeof(List<Dictionary<string, string>>), StatusCodes.Status200OK)]
45+
[ProducesResponseType(StatusCodes.Status404NotFound)]
46+
public IActionResult GetContentByType(string alias)
47+
{
48+
//if (!IsAccessValid())
49+
// return NotFound();
50+
51+
//var contentType = _contentTypeService.Get(alias);
52+
//if (contentType == null)
53+
// return Ok(new List<Dictionary<string, string>>());
54+
55+
//var contentItems = _umbracoHelper.ContentAtXPath("//" + alias)
56+
// .OrderByDescending(p => p.UpdateDate);
57+
58+
//return Ok(new List<Dictionary<string, string>>
59+
// {
60+
// _zapierContentService.GetContentTypeDictionary(contentType, contentItems.FirstOrDefault())
61+
// });
62+
63+
return Ok();
64+
}
65+
66+
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,43 @@
11
using System.Collections.Generic;
22
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
33
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
4-
5-
#if NETCOREAPP
64
using Microsoft.AspNetCore.Mvc;
75
using Microsoft.Extensions.Options;
8-
96
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
10-
#else
11-
using System.Web.Http;
12-
#endif
7+
using Asp.Versioning;
138

14-
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
9+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Api.Management.Controllers
1510
{
1611
/// <summary>
1712
/// Subscription API handling the ON/OFF trigger events in Zapier.
1813
/// </summary>
19-
public class SubscriptionController : ZapierAuthorizedApiController
14+
[ApiVersion("1.0")]
15+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
16+
public class SubscriptionController : ZapierControllerBase
2017
{
2118
private readonly ZapierSubscriptionHookService _zapierSubscriptionHookService;
2219

23-
#if NETCOREAPP
24-
public SubscriptionController(IOptions<ZapierSettings> options,
20+
public SubscriptionController(IOptions<ZapierSettings> options,
2521
ZapierSubscriptionHookService zapierSubscriptionHookService,
2622
IUserValidationService userValidationService)
2723
: base(options, userValidationService)
28-
#else
29-
public SubscriptionController(
30-
ZapierSubscriptionHookService zapierSubscriptionHookService,
31-
IUserValidationService userValidationService)
32-
: base(userValidationService)
33-
#endif
3424
{
3525
_zapierSubscriptionHookService = zapierSubscriptionHookService;
3626
}
3727

38-
[HttpPost]
39-
public bool UpdatePreferences([FromBody] SubscriptionDto dto)
28+
[HttpPost("update-preferences")]
29+
[ProducesResponseType(StatusCodes.Status404NotFound)]
30+
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
31+
public IActionResult UpdatePreferences([FromBody] SubscriptionDto dto)
4032
{
41-
if (!IsAccessValid() || dto == null) return false;
33+
if (!IsAccessValid() || dto == null)
34+
return NotFound();
4235

4336
var result = dto.SubscribeHook
4437
? _zapierSubscriptionHookService.Add(dto.EntityId, dto.Type, dto.HookUrl)
4538
: _zapierSubscriptionHookService.Delete(dto.EntityId, dto.Type, dto.HookUrl);
4639

47-
return string.IsNullOrEmpty(result);
40+
return Ok(string.IsNullOrEmpty(result));
4841
}
4942
}
5043
}

src/Umbraco.Cms.Integrations.Automation.Zapier/Controllers/ZapierAuthorizedApiController.cs renamed to src/Umbraco.Cms.Integrations.Automation.Zapier/Api/Management/Controllers/ZapierControllerBase.cs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,38 @@
1-
using System.Linq;
2-
3-
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Umbraco.Cms.Api.Common.Attributes;
4+
using Umbraco.Cms.Web.Common.Authorization;
5+
using Umbraco.Cms.Web.Common.Routing;
6+
using Umbraco.Cms.Integrations.Automation.Zapier.Models;
47
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
5-
6-
#if NETCOREAPP
78
using Microsoft.Extensions.Options;
9+
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
810

9-
using Umbraco.Cms.Web.Common.Controllers;
10-
#else
11-
using System.Configuration;
12-
13-
using Umbraco.Web.WebApi;
14-
#endif
15-
16-
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
11+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Api.Management.Controllers
1712
{
18-
public class ZapierAuthorizedApiController : UmbracoApiController
13+
[ApiController]
14+
[BackOfficeRoute($"{Constants.ManagementApi.RootPath}/v{{version:apiVersion}}")]
15+
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
16+
[MapToApi(Constants.ManagementApi.ApiName)]
17+
public class ZapierControllerBase : Controller
1918
{
2019
private readonly ZapierSettings Options;
2120

22-
private readonly IUserValidationService _userValidationService;
21+
protected IUserValidationService _userValidationService;
2322

24-
#if NETCOREAPP
25-
public ZapierAuthorizedApiController(IOptions<ZapierSettings> options, IUserValidationService userValidationService)
26-
#else
27-
public ZapierAuthorizedApiController(IUserValidationService userValidationService)
28-
#endif
23+
public ZapierControllerBase(IOptions<ZapierSettings> options, IUserValidationService userValidationService)
2924
{
30-
#if NETCOREAPP
3125
Options = options.Value;
32-
#else
33-
Options = new ZapierSettings(ConfigurationManager.AppSettings);
34-
#endif
3526

3627
_userValidationService = userValidationService;
3728
}
3829

39-
public bool IsAccessValid()
30+
protected bool IsAccessValid()
4031
{
4132
string username = string.Empty;
4233
string password = string.Empty;
4334
string apiKey = string.Empty;
4435

45-
#if NETCOREAPP
4636
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
4737
out var usernameValues))
4838
username = usernameValues.First();
@@ -52,17 +42,6 @@ public bool IsAccessValid()
5242
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.ApiKeyHeaderKey,
5343
out var apiKeyValues))
5444
apiKey = apiKeyValues.First();
55-
#else
56-
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.UsernameHeaderKey,
57-
out var usernameValues))
58-
username = usernameValues.First();
59-
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.PasswordHeaderKey,
60-
out var passwordValues))
61-
password = passwordValues.First();
62-
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.ApiKeyHeaderKey,
63-
out var apiKeyValues))
64-
apiKey = apiKeyValues.First();
65-
#endif
6645

6746
if (string.IsNullOrEmpty(apiKey) && (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))) return false;
6847

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#if NETCOREAPP
2-
using Microsoft.Extensions.Logging;
1+
using Microsoft.Extensions.Logging;
32

43
using Umbraco.Cms.Core.Events;
54
using Umbraco.Cms.Core.Notifications;
@@ -55,4 +54,3 @@ public void Handle(ContentPublishedNotification notification)
5554
}
5655
}
5756
}
58-
#endif

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ public class Constants
1717

1818
public const string UmbracoFormsIntegrationsAutomationZapierApiKey = "Umbraco.Forms.Integrations.Automation.Zapier.ApiKey";
1919

20+
public static class ManagementApi
21+
{
22+
public const string RootPath = "zapier/management/api";
23+
24+
public const string ApiName = "zapier-management";
25+
26+
public const string ApiTitle = "Zapier Management API";
27+
28+
public const string GroupName = "Zapier";
29+
}
30+
2031
public static class ZapierAppConfiguration
2132
{
2233
public const string UsernameHeaderKey = "X-USERNAME";

0 commit comments

Comments
 (0)