1
1
using Newtonsoft . Json ;
2
2
using System ;
3
3
using System . Collections . Generic ;
4
+ using System . Configuration ;
4
5
using System . Linq ;
5
6
using System . Net ;
6
7
using System . Net . Http ;
12
13
using Umbraco . Core . Services ;
13
14
using Umbraco . Forms . Core ;
14
15
using Umbraco . Forms . Core . Persistence . Dtos ;
16
+ using Umbraco . Forms . Integrations . Crm . Hubspot . Configuration ;
15
17
using Umbraco . Forms . Integrations . Crm . Hubspot . Extensions ;
16
18
using Umbraco . Forms . Integrations . Crm . Hubspot . Models ;
17
19
using Umbraco . Forms . Integrations . Crm . Hubspot . Models . Dtos ;
@@ -31,6 +33,7 @@ public class HubspotContactService : IContactService
31
33
private readonly ILogger _logger ;
32
34
private readonly AppCaches _appCaches ;
33
35
private readonly IKeyValueService _keyValueService ;
36
+ private readonly HubspotSettings _settings ;
34
37
35
38
private const string CrmApiHost = "https://api.hubapi.com" ;
36
39
private static readonly string CrmV3ApiBaseUrl = $ "{ CrmApiHost } /crm/v3/";
@@ -53,6 +56,8 @@ public HubspotContactService(IFacadeConfiguration configuration, ILogger logger,
53
56
_logger = logger ;
54
57
_appCaches = appCaches ;
55
58
_keyValueService = keyValueService ;
59
+
60
+ _settings = new HubspotSettings ( ConfigurationManager . AppSettings ) ;
56
61
}
57
62
58
63
public AuthenticationMode IsAuthorizationConfigured ( ) => GetConfiguredAuthenticationDetails ( ) . Mode ;
@@ -194,7 +199,12 @@ public async Task<CommandResult> PostContactAsync(Record record, List<MappedProp
194
199
// A 409 - Conflict response indicates that the contact (by email address) already exists.
195
200
if ( response . StatusCode == HttpStatusCode . Conflict )
196
201
{
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 ;
198
208
}
199
209
else
200
210
{
0 commit comments