Skip to content

Commit a1e5c5b

Browse files
committed
Merge branch 'main' into feature/google-search-console
2 parents 16393c8 + 5f90b67 commit a1e5c5b

29 files changed

+557
-223
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
trigger:
2+
- feature/google-search-console
3+
4+
pool:
5+
vmImage: 'windows-latest'
6+
7+
variables:
8+
projectName: 'Umbraco.Cms.Integrations.SEO.GoogleSearchConsole.URLInspectionTool'
9+
project: 'src/$(projectName)/$(projectName).csproj'
10+
buildPlatform: 'Any CPU'
11+
buildConfiguration: 'Release'
12+
13+
steps:
14+
- task: NuGetToolInstaller@1
15+
displayName: 'Install NuGet'
16+
17+
- task: DotNetCoreCLI@2
18+
displayName: 'NuGet Restore'
19+
inputs:
20+
command: 'restore'
21+
feedsToUse: 'select'
22+
projects: '$(project)'
23+
includeNuGetOrg: true
24+
25+
- task: VSBuild@1
26+
displayName: 'Build Project'
27+
inputs:
28+
solution: '$(project)'
29+
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
30+
platform: '$(buildPlatform)'
31+
configuration: '$(buildConfiguration)'
32+
33+
- task: DotNetCoreCLI@2
34+
displayName: 'Create NuGet Package'
35+
inputs:
36+
command: 'pack'
37+
arguments: '--configuration $(buildConfiguration)'
38+
packagesToPack: '$(project)'
39+
versioningScheme: 'off'
40+
41+
- task: CmdLine@2
42+
displayName: 'Create Umbraco Package'
43+
inputs:
44+
script: |
45+
dotnet tool install --global Umbraco.Tools.Packages
46+
cd src/$(projectName)/
47+
umbpack pack .\package.xml -o $(Build.ArtifactStagingDirectory)
48+
cd ../../
49+
50+
- task: PublishBuildArtifacts@1
51+
displayName: 'Publish Build Artifacts'
52+
inputs:
53+
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
54+
ArtifactName: 'drop'
55+
publishLocation: 'Container'

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
5050
foreach (var node in e.PublishedEntities)
5151
{
5252
var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name);
53-
if (zapContentConfig == null) continue;
53+
if (zapContentConfig == null || !zapContentConfig.IsEnabled) continue;
5454

5555
var content = new Dictionary<string, string>
5656
{
57+
{ Constants.Content.Id, node.Id.ToString() },
5758
{ Constants.Content.Name, node.Name },
5859
{ Constants.Content.PublishDate, DateTime.UtcNow.ToString() }
5960
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ public void Handle(ContentPublishedNotification notification)
3333
foreach (var node in notification.PublishedEntities)
3434
{
3535
var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name);
36-
if (zapContentConfig == null) continue;
36+
if (zapContentConfig == null || !zapContentConfig.IsEnabled) continue;
3737

3838
var content = new Dictionary<string, string>
3939
{
40+
{ Constants.Content.Id, node.Id.ToString() },
4041
{ Constants.Content.Name, node.Name },
4142
{ Constants.Content.PublishDate, DateTime.UtcNow.ToString() }
4243
};

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,22 @@ public class Constants
1111

1212
public const string UmbracoCmsIntegrationsAutomationZapierUserGroup = "Umbraco.Cms.Integrations.Automation.Zapier.UserGroup";
1313

14+
public static class ZapierAppConfiguration
15+
{
16+
public const string UsernameHeaderKey = "X-USERNAME";
17+
18+
public const string PasswordHeaderKey = "X-PASSWORD";
19+
}
20+
1421
public static class Configuration
1522
{
1623
public const string Settings = "Umbraco:Forms:Integrations:Automation:Zapier:Settings";
1724
}
1825

1926
public static class Content
2027
{
28+
public const string Id = "Id";
29+
2130
public const string Name = "Name";
2231

2332
public const string PublishDate = "PublishDate";
Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
using System.Linq;
2-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
32

43
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
54
using Umbraco.Cms.Integrations.Automation.Zapier.Models;
5+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
66

77

88
#if NETCOREAPP
99
using Microsoft.AspNetCore.Mvc;
1010
using Microsoft.Extensions.Options;
1111
using Umbraco.Cms.Web.Common.Controllers;
1212
using Umbraco.Cms.Core.Security;
13-
using Umbraco.Cms.Core.Services;
1413
#else
1514
using System.Web.Http;
1615
using System.Configuration;
1716

1817
using Umbraco.Web.WebApi;
19-
using Umbraco.Core.Services;
2018
#endif
2119

2220
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
@@ -25,49 +23,29 @@ public class AuthController : UmbracoApiController
2523
{
2624
private readonly ZapierSettings Options;
2725

28-
private readonly IUserService _userService;
26+
private readonly IUserValidationService _userValidationService;
2927

3028
#if NETCOREAPP
3129
private readonly IBackOfficeUserManager _backOfficeUserManager;
3230

33-
public AuthController(IBackOfficeUserManager backOfficeUserManager, IUserService userService, IOptions<ZapierSettings> options)
31+
public AuthController(IBackOfficeUserManager backOfficeUserManager, IUserValidationService userValidationService, IOptions<ZapierSettings> options)
3432
{
3533
_backOfficeUserManager = backOfficeUserManager;
3634

37-
_userService = userService;
35+
_userValidationService = userValidationService;
3836

3937
Options = options.Value;
4038
}
4139
#else
42-
public AuthController(IUserService userService)
40+
public AuthController(IUserValidationService userValidationService)
4341
{
4442
Options = new ZapierSettings(ConfigurationManager.AppSettings);
4543

46-
_userService = userService;
44+
_userValidationService = userValidationService;
4745
}
4846
#endif
4947

5048
[HttpPost]
51-
public async Task<bool> ValidateUser([FromBody] UserModel userModel)
52-
{
53-
#if NETCOREAPP
54-
var isUserValid =
55-
await _backOfficeUserManager.ValidateCredentialsAsync(userModel.Username, userModel.Password);
56-
#else
57-
var isUserValid = Security.ValidateBackOfficeCredentials(userModel.Username, userModel.Password);
58-
#endif
59-
60-
if (!isUserValid) return false;
61-
62-
var userGroup = Options.UserGroup;
63-
if (!string.IsNullOrEmpty(userGroup))
64-
{
65-
var user = _userService.GetByUsername(userModel.Username);
66-
67-
return user != null && user.Groups.Any(p => p.Name == userGroup);
68-
}
69-
70-
return true;
71-
}
49+
public async Task<bool> ValidateUser([FromBody] UserModel userModel) => await _userValidationService.Validate(userModel.Username, userModel.Password, Options.UserGroup);
7250
}
7351
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System.Collections.Generic;
2+
3+
using System.Linq;
4+
5+
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
6+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
7+
8+
#if NETCOREAPP
9+
using Microsoft.Extensions.Options;
10+
11+
using Umbraco.Cms.Web.Common.Controllers;
12+
using Umbraco.Cms.Core.Services;
13+
#else
14+
using System.Configuration;
15+
16+
using Umbraco.Web.WebApi;
17+
using Umbraco.Core.Services;
18+
#endif
19+
20+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
21+
{
22+
public class PollingController : UmbracoApiController
23+
{
24+
private readonly ZapierSettings Options;
25+
26+
private IContentService _contentService;
27+
28+
private readonly IUserValidationService _userValidationService;
29+
30+
#if NETCOREAPP
31+
public PollingController(IOptions<ZapierSettings> options, IContentService contentService, IUserValidationService userValidationService)
32+
#else
33+
public PollingController(IContentService contentService, IUserValidationService userValidationService)
34+
#endif
35+
{
36+
#if NETCOREAPP
37+
Options = options.Value;
38+
#else
39+
Options = new ZapierSettings(ConfigurationManager.AppSettings);
40+
#endif
41+
42+
_contentService = contentService;
43+
44+
_userValidationService = userValidationService;
45+
}
46+
47+
public List<Dictionary<string, string>> GetContent()
48+
{
49+
string username = string.Empty;
50+
string password = string.Empty;
51+
52+
#if NETCOREAPP
53+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
54+
out var usernameValues))
55+
username = usernameValues.First();
56+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.PasswordHeaderKey,
57+
out var passwordValues))
58+
password = passwordValues.First();
59+
#else
60+
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.UsernameHeaderKey,
61+
out var usernameValues))
62+
username = usernameValues.First();
63+
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.PasswordHeaderKey,
64+
out var passwordValues))
65+
password = passwordValues.First();
66+
#endif
67+
68+
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return null;
69+
70+
var isAuthorized = _userValidationService.Validate(username, password, Options.UserGroup).GetAwaiter().GetResult();
71+
if (!isAuthorized) return null;
72+
73+
var root = _contentService.GetRootContent().Where(p => p.Published)
74+
.OrderByDescending(p => p.PublishDate).FirstOrDefault();
75+
76+
return new List<Dictionary<string, string>>
77+
{
78+
new Dictionary<string, string>
79+
{
80+
{Constants.Content.Id, root?.Id.ToString()},
81+
{Constants.Content.Name, root?.Name},
82+
{Constants.Content.PublishDate, root?.PublishDate.ToString()}
83+
}
84+
};
85+
}
86+
87+
}
88+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Linq;
3+
using System.Net;
4+
using Umbraco.Cms.Integrations.Automation.Zapier.Configuration;
5+
using Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos;
6+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
7+
8+
#if NETCOREAPP
9+
using Microsoft.AspNetCore.Mvc;
10+
using Microsoft.Extensions.Options;
11+
using Umbraco.Cms.Web.Common.Controllers;
12+
#else
13+
using System.Web.Http;
14+
using System.Configuration;
15+
using Umbraco.Web.WebApi;
16+
#endif
17+
18+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
19+
{
20+
public class SubscriptionController : UmbracoApiController
21+
{
22+
private readonly ZapierSettings Options;
23+
24+
private readonly ZapConfigService _zapConfigService;
25+
26+
private readonly IUserValidationService _userValidationService;
27+
28+
#if NETCOREAPP
29+
public SubscriptionController(IOptions<ZapierSettings> options, ZapConfigService zapConfigService, IUserValidationService userValidationService)
30+
#else
31+
public SubscriptionController(ZapConfigService zapConfigService, IUserValidationService userValidationService)
32+
#endif
33+
{
34+
#if NETCOREAPP
35+
Options = options.Value;
36+
#else
37+
Options = new ZapierSettings(ConfigurationManager.AppSettings);
38+
#endif
39+
40+
_zapConfigService = zapConfigService;
41+
42+
_userValidationService = userValidationService;
43+
}
44+
45+
[HttpPost]
46+
public bool UpdatePreferences([FromBody] SubscriptionDto dto)
47+
{
48+
string username = string.Empty;
49+
string password = string.Empty;
50+
51+
#if NETCOREAPP
52+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.UsernameHeaderKey,
53+
out var usernameValues))
54+
username = usernameValues.First();
55+
if (Request.Headers.TryGetValue(Constants.ZapierAppConfiguration.PasswordHeaderKey,
56+
out var passwordValues))
57+
password = passwordValues.First();
58+
#else
59+
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.UsernameHeaderKey,
60+
out var usernameValues))
61+
username = usernameValues.First();
62+
if (Request.Headers.TryGetValues(Constants.ZapierAppConfiguration.PasswordHeaderKey,
63+
out var passwordValues))
64+
password = passwordValues.First();
65+
#endif
66+
67+
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return false;
68+
69+
var isAuthorized = _userValidationService.Validate(username, password, Options.UserGroup).GetAwaiter().GetResult();
70+
if (!isAuthorized) return false;
71+
72+
if (dto == null) return false;
73+
74+
var result = _zapConfigService.UpdatePreferences(dto.HookUrl, dto.Enable);
75+
76+
return string.IsNullOrEmpty(result);
77+
}
78+
}
79+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ public class ZapContentConfig
6363
public int Id { get; set; }
6464

6565
[Column("ContentTypeName")]
66+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapContentConfig_ContentTypeName")]
6667
public string ContentTypeName { get; set; }
6768

6869
[Column("WebHookUrl")]
70+
[Index(IndexTypes.UniqueNonClustered, Name = "IX_ZapContentConfig_WebHookUrl")]
6971
public string WebHookUrl { get; set; }
72+
73+
[Column("IsEnabled")]
74+
public bool IsEnabled { get; set; }
7075
}
7176
}
7277
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public class ContentConfigDto
1313
[JsonProperty("webHookUrl")]
1414
public string WebHookUrl { get; set; }
1515

16+
[JsonProperty("isEnabled")]
17+
public bool IsEnabled { get; set; }
18+
1619
[JsonProperty("showDeletePrompt")]
1720
public bool ShowDeletePrompt { get; set; }
1821
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Models.Dtos
4+
{
5+
public class SubscriptionDto
6+
{
7+
[JsonProperty("hookUrl")]
8+
public string HookUrl { get; set; }
9+
10+
[JsonProperty("enable")]
11+
public bool Enable { get; set; }
12+
}
13+
}

0 commit comments

Comments
 (0)