Skip to content

Commit a7f94d6

Browse files
authored
Merge pull request #121 from umbraco/feature/hubspot-remove-v8
Hubspot - remove V8 support and update unit tests
2 parents eee488a + 985c5ef commit a7f94d6

21 files changed

+249
-482
lines changed

src/Umbraco.Cms.Integrations.Crm.Hubspot.Tests/Controllers/FormsControllerTests.cs

Lines changed: 231 additions & 185 deletions
Large diffs are not rendered by default.

src/Umbraco.Cms.Integrations.Crm.Hubspot.Tests/Umbraco.Cms.Integrations.Crm.Hubspot.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net472</TargetFramework>
4+
<TargetFramework>net60</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="Moq" Version="4.16.1" />
1111
<PackageReference Include="NUnit" Version="3.12.0" />
12-
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
14-
<PackageReference Include="UmbracoCms" Version="8.4.0" />
12+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
14+
<PackageReference Include="Umbraco.Cms.Web.Website" Version="10.0.0" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/Render/HubspotForm.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels.HubspotFormViewModel>
1+
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels.HubspotFormViewModel>
22

33
<script charset="utf-8" type="text/javascript" src="@Model.ScriptPath"></script>
44
<script>

src/Umbraco.Cms.Integrations.Crm.Hubspot/App_Plugins/UmbracoCms.Integrations/Crm/Hubspot/Render/HubspotFormV9.cshtml

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

src/Umbraco.Cms.Integrations.Crm.Hubspot/Configuration/HubspotOAuthSettings.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@ namespace Umbraco.Cms.Integrations.Crm.Hubspot.Configuration
44
{
55
public class HubspotOAuthSettings
66
{
7-
public HubspotOAuthSettings() { }
8-
9-
public HubspotOAuthSettings(NameValueCollection appSettings)
10-
{
11-
ClientId = appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotClientIdKey];
12-
13-
ClientSecret = appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotClientSecretKey];
14-
15-
RedirectUri = appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotRedirectUriKey];
16-
17-
Scopes = appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotScopesKey];
18-
19-
TokenEndpoint = appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotTokenEndpointKey];
20-
}
21-
227
public string ClientId { get; set; }
238

249
public string ClientSecret { get; set; }

src/Umbraco.Cms.Integrations.Crm.Hubspot/Configuration/HubspotSettings.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
1-
using System.Collections.Specialized;
2-
1+

32
namespace Umbraco.Cms.Integrations.Crm.Hubspot.Configuration
43
{
54
public class HubspotSettings
65
{
7-
public HubspotSettings()
8-
{
9-
10-
}
11-
12-
public HubspotSettings(NameValueCollection appSettings)
13-
{
14-
ApiKey = appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotApiKey];
15-
Region = appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotRegion];
16-
UseUmbracoAuthorization =
17-
bool.TryParse(appSettings[Constants.Configuration.UmbracoCmsIntegrationsCrmHubspotUseUmbracoAuthorizationKey], out var key)
18-
? key
19-
: true;
20-
}
21-
226
public string ApiKey { get; set; }
237

248
public string Region { get; set; }

src/Umbraco.Cms.Integrations.Crm.Hubspot/Constants.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ public static class Configuration
1717
public const string Settings = "Umbraco:Cms:Integrations:Crm:Hubspot:Settings";
1818

1919
public const string OAuthSettings = "Umbraco:Cms:Integrations:Crm:Hubspot:OAuthSettings";
20-
21-
public const string UmbracoCmsIntegrationsCrmHubspotApiKey = "Umbraco.Cms.Integrations.Crm.Hubspot.ApiKey";
22-
23-
public const string UmbracoCmsIntegrationsCrmHubspotRegion = "Umbraco.Cms.Integrations.Crm.Hubspot.Region";
24-
25-
public const string UmbracoCmsIntegrationsCrmHubspotUseUmbracoAuthorizationKey =
26-
"Umbraco.Cms.Integrations.Crm.Hubspot.UseUmbracoAuthorization";
27-
28-
public const string UmbracoCmsIntegrationsCrmHubspotClientIdKey = "Umbraco.Cms.Integrations.Crm.Hubspot.ClientId";
29-
30-
public const string UmbracoCmsIntegrationsCrmHubspotClientSecretKey = "Umbraco.Cms.Integrations.Crm.Hubspot.ClientSecret";
31-
32-
public const string UmbracoCmsIntegrationsCrmHubspotRedirectUriKey = "Umbraco.Cms.Integrations.Crm.Hubspot.RedirectUri";
33-
34-
public const string UmbracoCmsIntegrationsCrmHubspotScopesKey = "Umbraco.Cms.Integrations.Crm.Hubspot.Scopes";
35-
36-
public const string UmbracoCmsIntegrationsCrmHubspotTokenEndpointKey = "Umbraco.Cms.Integrations.Crm.Hubspot.TokenEndpoint";
3720
}
3821

3922
public static class ErrorMessages

src/Umbraco.Cms.Integrations.Crm.Hubspot/Controllers/FormsController.cs

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,12 @@
66
using System.Net.Http.Headers;
77
using System.Threading.Tasks;
88

9-
#if NETCOREAPP
109
using Microsoft.Extensions.Options;
1110
using Microsoft.AspNetCore.Mvc;
1211
using Microsoft.Extensions.Logging;
12+
1313
using Umbraco.Cms.Web.BackOffice.Controllers;
1414
using Umbraco.Cms.Web.Common.Attributes;
15-
#else
16-
using System.Web.Http;
17-
using System.Configuration;
18-
19-
using Umbraco.Core.Logging;
20-
using Umbraco.Web.Mvc;
21-
using Umbraco.Web.WebApi;
22-
#endif
23-
24-
using Newtonsoft.Json;
25-
2615
using Umbraco.Cms.Integrations.Crm.Hubspot.Resources;
2716
using Umbraco.Cms.Integrations.Crm.Hubspot.Configuration;
2817
using Umbraco.Cms.Integrations.Crm.Hubspot.Models;
@@ -53,13 +42,8 @@ public class FormsController : UmbracoAuthorizedApiController
5342

5443
private const string HubspotFormsApiEndpoint = "https://api.hubapi.com/forms/v2/forms";
5544

56-
#if NETCOREAPP
5745
private readonly ILogger<FormsController> _logger;
58-
#else
59-
private readonly ILogger _logger;
60-
#endif
6146

62-
#if NETCOREAPP
6347
public FormsController(
6448
IOptions<HubspotSettings> options,
6549
IOptions<HubspotOAuthSettings> oauthOptions,
@@ -77,32 +61,14 @@ public FormsController(
7761

7862
_authorizationService = authorizationImplementationFactory(Options.UseUmbracoAuthorization);
7963
}
80-
#else
81-
public FormsController(ITokenService tokenService, ILogger logger, AuthorizationImplementationFactory authorizationImplementationFactory)
82-
{
83-
Options = new HubspotSettings(ConfigurationManager.AppSettings);
84-
85-
OAuthOptions = new HubspotOAuthSettings(ConfigurationManager.AppSettings);
86-
87-
_tokenService = tokenService;
88-
89-
_logger = logger;
90-
91-
_authorizationService = authorizationImplementationFactory(Options.UseUmbracoAuthorization);
92-
}
93-
#endif
9464

9565
public async Task<ResponseDto> GetAll()
9666
{
9767
var hubspotApiKey = Options.ApiKey;
9868

9969
if (string.IsNullOrEmpty(hubspotApiKey))
10070
{
101-
#if NETCOREAPP
10271
_logger.LogInformation(message: Constants.ErrorMessages.ApiKeyMissing);
103-
#else
104-
_logger.Info<FormsController>(message: Constants.ErrorMessages.ApiKeyMissing);
105-
#endif
10672

10773
return new ResponseDto { IsValid = false, Error = Constants.ErrorMessages.ApiKeyMissing };
10874
}
@@ -128,30 +94,19 @@ public async Task<ResponseDto> GetAll()
12894
}
12995
catch (HttpRequestException ex) when (ex.Message.Contains(HttpStatusCode.Forbidden.ToString()))
13096
{
131-
#if NETCOREAPP
13297
_logger.LogError(string.Format(LoggingResources.ApiFetchFormsFailed, responseContent));
133-
#else
134-
_logger.Error<FormsController>(string.Format(LoggingResources.ApiFetchFormsFailed, responseContent));
135-
#endif
98+
13699
return new ResponseDto { IsValid = false, Error = Constants.ErrorMessages.TokenPermissions };
137100
}
138101
catch (HttpRequestException ex) when (ex.Message.Contains(HttpStatusCode.Unauthorized.ToString()))
139102
{
140-
#if NETCOREAPP
141103
_logger.LogError(string.Format(LoggingResources.ApiFetchFormsFailed, responseContent));
142-
#else
143-
_logger.Error<FormsController>(string.Format(LoggingResources.ApiFetchFormsFailed, responseContent));
144-
#endif
145104

146105
return new ResponseDto { IsExpired = true, Error = Constants.ErrorMessages.InvalidApiKey };
147106
}
148107
catch
149108
{
150-
#if NETCOREAPP
151109
_logger.LogError(string.Format(LoggingResources.ApiFetchFormsFailed, responseContent));
152-
#else
153-
_logger.Error<FormsController>(string.Format(LoggingResources.ApiFetchFormsFailed, responseContent));
154-
#endif
155110

156111
return new ResponseDto();
157112
}
@@ -162,11 +117,7 @@ public async Task<ResponseDto> GetAllOAuth()
162117
_tokenService.TryGetParameters(Constants.AccessTokenDbKey, out string accessToken);
163118
if (string.IsNullOrEmpty(accessToken))
164119
{
165-
#if NETCOREAPP
166120
_logger.LogInformation(Constants.ErrorMessages.AccessTokenMissing);
167-
#else
168-
_logger.Info<FormsController>(Constants.ErrorMessages.AccessTokenMissing);
169-
#endif
170121

171122
return new ResponseDto
172123
{
@@ -196,20 +147,13 @@ public async Task<ResponseDto> GetAllOAuth()
196147
}
197148
catch(HttpRequestException ex) when (ex.Message.Contains(HttpStatusCode.Unauthorized.ToString()))
198149
{
199-
#if NETCOREAPP
200150
_logger.LogError(string.Format(LoggingResources.OAuthFetchFormsFailed, responseContent));
201-
#else
202-
_logger.Error<FormsController>(string.Format(LoggingResources.OAuthFetchFormsFailed, responseContent));
203-
#endif
151+
204152
return new ResponseDto { IsExpired = true, Error = Constants.ErrorMessages.InvalidApiKey };
205153
}
206154
catch
207155
{
208-
#if NETCOREAPP
209156
_logger.LogError(string.Format(LoggingResources.OAuthFetchFormsFailed, responseContent));
210-
#else
211-
_logger.Error<FormsController>(string.Format(LoggingResources.OAuthFetchFormsFailed, responseContent));
212-
#endif
213157

214158
return new ResponseDto();
215159
}
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
using Umbraco.Cms.Integrations.Crm.Hubspot.Models;
2-
3-
#if NETCOREAPP
4-
using Microsoft.AspNetCore.Mvc;
5-
62
using Umbraco.Cms.Web.Common.Controllers;
7-
#else
8-
using System.Web.Http;
9-
using System.Net.Http;
10-
using System.Net.Http.Headers;
113

12-
using Umbraco.Web.WebApi;
13-
#endif
4+
using Microsoft.AspNetCore.Mvc;
145

156
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Controllers
167
{
178
public class HubspotAuthorizationController : UmbracoApiController
189
{
1910
[HttpGet]
20-
#if NETCOREAPP
2111
public IActionResult OAuth(string code)
2212
{
2313
return new ContentResult
@@ -28,16 +18,5 @@ public IActionResult OAuth(string code)
2818
ContentType = "text/html"
2919
};
3020
}
31-
#else
32-
public HttpResponseMessage OAuth(string code)
33-
{
34-
var response = new HttpResponseMessage();
35-
response.Content = new StringContent(string.IsNullOrEmpty(code)
36-
? JavascriptResponse.Fail("Authorization process failed.")
37-
: JavascriptResponse.Ok(code));
38-
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
39-
return response;
40-
}
41-
#endif
4221
}
4322
}

src/Umbraco.Cms.Integrations.Crm.Hubspot/Editors/FormPickerValueConverter.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
using System;
44

55
using Umbraco.Cms.Integrations.Crm.Hubspot.Models.ViewModels;
6-
7-
#if NETCOREAPP
86
using Umbraco.Cms.Core.PropertyEditors;
97
using Umbraco.Cms.Core.Models.PublishedContent;
10-
#else
11-
using Umbraco.Core.Models.PublishedContent;
12-
using Umbraco.Core.PropertyEditors;
13-
#endif
148

159
namespace Umbraco.Cms.Integrations.Crm.Hubspot.Editors
1610
{

0 commit comments

Comments
 (0)