Skip to content

Commit 0c83d76

Browse files
committed
Allow contact update flag for CRM integrations: ActiveCampaign & HubSpot
1 parent c0e7f2c commit 0c83d76

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/Umbraco.Forms.Integrations.Crm.ActiveCampaign/ActiveCampaignContactsWorkflow.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public override WorkflowExecutionStatus Execute(WorkflowExecutionContext context
6767
// Check if contact exists.
6868
var contacts = _contactService.Get(email).ConfigureAwait(false).GetAwaiter().GetResult();
6969

70+
if(contacts.Contacts.Count > 0 && !_settings.AllowContactUpdate)
71+
{
72+
_logger.LogError("ActiveCampaign contact update is not allowed.");
73+
74+
return WorkflowExecutionStatus.Cancelled;
75+
}
76+
7077
var requestDto = new ContactDetailDto { Contact = Build(context.Record) };
7178

7279
if (contacts.Contacts.Count > 0) requestDto.Contact.Id = contacts.Contacts.First().Id;

src/Umbraco.Forms.Integrations.Crm.ActiveCampaign/Configuration/ActiveCampaignSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public ActiveCampaignSettings()
1212

1313
public string ApiKey { get; set; }
1414

15+
public bool AllowContactUpdate { get; set; }
16+
1517
public List<ContactFieldSettings> ContactFields { get; set; }
1618
}
1719
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
1+

72
namespace Umbraco.Forms.Integrations.Crm.Hubspot.Configuration
83
{
94
public class HubspotSettings
105
{
116
public string ApiKey { get; set; }
7+
8+
public bool AllowContactUpdate { get; set; }
129
}
1310
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ public async Task<CommandResult> PostContactAsync(Record record, List<MappedProp
202202
// A 409 - Conflict response indicates that the contact (by email address) already exists.
203203
if (response.StatusCode == HttpStatusCode.Conflict)
204204
{
205-
return await UpdateContactAsync(record, authenticationDetails, propertiesRequestV1, emailValue);
205+
if (!_settings.AllowContactUpdate)
206+
_logger.LogError("Hubspot contact update is not allowed.");
207+
return _settings.AllowContactUpdate
208+
? await UpdateContactAsync(record, authenticationDetails, propertiesRequestV1, emailValue)
209+
: CommandResult.Failed;
206210
}
207211
else
208212
{

0 commit comments

Comments
 (0)