Skip to content

Commit 5ea97b6

Browse files
committed
Allow contact update flag for CRM
1 parent e3efedf commit 5ea97b6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+

2+
using System.Collections.Specialized;
3+
4+
namespace Umbraco.Forms.Integrations.Crm.Hubspot.Configuration
5+
{
6+
public class HubspotSettings
7+
{
8+
public HubspotSettings(NameValueCollection appSettings)
9+
{
10+
var settings = appSettings["Umbraco.Forms.Integrations.Crm.Hubspot.AllowContactUpdate"];
11+
AllowContactUpdate = bool.TryParse(settings, out var result)
12+
? result : false;
13+
}
14+
15+
public bool AllowContactUpdate { get; set; }
16+
}
17+
}

src/Umbraco.Forms.Integrations.Crm.Hubspot/Services/HubspotContactService.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Newtonsoft.Json;
22
using System;
33
using System.Collections.Generic;
4+
using System.Configuration;
45
using System.Linq;
56
using System.Net;
67
using System.Net.Http;
@@ -12,6 +13,7 @@
1213
using Umbraco.Core.Services;
1314
using Umbraco.Forms.Core;
1415
using Umbraco.Forms.Core.Persistence.Dtos;
16+
using Umbraco.Forms.Integrations.Crm.Hubspot.Configuration;
1517
using Umbraco.Forms.Integrations.Crm.Hubspot.Extensions;
1618
using Umbraco.Forms.Integrations.Crm.Hubspot.Models;
1719
using Umbraco.Forms.Integrations.Crm.Hubspot.Models.Dtos;
@@ -31,6 +33,7 @@ public class HubspotContactService : IContactService
3133
private readonly ILogger _logger;
3234
private readonly AppCaches _appCaches;
3335
private readonly IKeyValueService _keyValueService;
36+
private readonly HubspotSettings _settings;
3437

3538
private const string CrmApiHost = "https://api.hubapi.com";
3639
private static readonly string CrmV3ApiBaseUrl = $"{CrmApiHost}/crm/v3/";
@@ -53,6 +56,8 @@ public HubspotContactService(IFacadeConfiguration configuration, ILogger logger,
5356
_logger = logger;
5457
_appCaches = appCaches;
5558
_keyValueService = keyValueService;
59+
60+
_settings = new HubspotSettings(ConfigurationManager.AppSettings);
5661
}
5762

5863
public AuthenticationMode IsAuthorizationConfigured() => GetConfiguredAuthenticationDetails().Mode;
@@ -194,7 +199,12 @@ public async Task<CommandResult> PostContactAsync(Record record, List<MappedProp
194199
// A 409 - Conflict response indicates that the contact (by email address) already exists.
195200
if (response.StatusCode == HttpStatusCode.Conflict)
196201
{
197-
return await UpdateContactAsync(record, authenticationDetails, propertiesRequestV1, emailValue);
202+
if (!_settings.AllowContactUpdate)
203+
_logger.Error<HubspotContactService>("Hubspot contact update is not allowed.");
204+
205+
return _settings.AllowContactUpdate
206+
? await UpdateContactAsync(record, authenticationDetails, propertiesRequestV1, emailValue)
207+
: CommandResult.Failed;
198208
}
199209
else
200210
{

0 commit comments

Comments
 (0)