Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add domain to Hubspot company #3648

Merged
merged 10 commits into from
Mar 27, 2024
28 changes: 27 additions & 1 deletion api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,33 @@
ENABLE_HUBSPOT_LEAD_TRACKING = env.bool("ENABLE_HUBSPOT_LEAD_TRACKING", False)
HUBSPOT_IGNORE_DOMAINS = env.list("HUBSPOT_IGNORE_DOMAINS", [])
HUBSPOT_IGNORE_DOMAINS_REGEX = env("HUBSPOT_IGNORE_DOMAINS_REGEX", "")

HUBSPOT_IGNORE_ORGANISATION_DOMAINS = env.list(
"HUBSPOT_IGNORE_ORGANISATION_DOMAINS",
[
"gmail.com",
"hotmail.com",
"gmail.com",
"yahoo.com",
"outlook.com",
"aol.com",
"icloud.com",
"hotmail.com",
"live.com",
"mail.com",
"protonmail.com",
"yandex.com",
"gmx.com",
"zoho.com",
"qq.com",
"163.com",
"126.com",
"sina.com",
"mail.ru",
"outlook.co.uk",
"comcast.net",
"att.net",
],
)

# List of plan ids that support seat upgrades
AUTO_SEAT_UPGRADE_PLANS = env.list("AUTO_SEAT_UPGRADE_PLANS", default=[])
Expand Down
4 changes: 3 additions & 1 deletion api/integrations/lead_tracking/hubspot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def create_contact(self, user: FFAdminUser, hubspot_company_id: str) -> dict:
)
return response.to_dict()

def create_company(self, name: str) -> dict:
def create_company(self, name: str, domain: str | None) -> dict:
properties = {"name": name}
if domain:
properties["domain"] = domain
simple_public_object_input_for_create = SimplePublicObjectInputForCreate(
properties=properties,
)
Expand Down
12 changes: 9 additions & 3 deletions api/integrations/lead_tracking/hubspot/lead_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ def create_lead(self, user: FFAdminUser, organisation: Organisation) -> None:
# for an existing organisation, so return early.
return

hubspot_id = self.get_or_create_organisation_hubspot_id(organisation)
hubspot_id = self.get_or_create_organisation_hubspot_id(organisation, user)

self.client.create_contact(user, hubspot_id)

def get_or_create_organisation_hubspot_id(self, organisation: Organisation) -> str:
def get_or_create_organisation_hubspot_id(
self, organisation: Organisation, user: FFAdminUser
) -> str:
"""
Return the Hubspot API's id for an organisation.
"""
if getattr(organisation, "hubspot_organisation", None):
return organisation.hubspot_organisation.hubspot_id

response = self.client.create_company(name=organisation.name)
if user.email_domain in settings.HUBSPOT_IGNORE_ORGANISATION_DOMAINS:
domain = None
else:
domain = user.email_domain
response = self.client.create_company(name=organisation.name, domain=domain)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the unit tests for this logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok altered one existing test to capture when it is set and created a new test for when the domain name is in the filter list.

# Store the organisation data in the database since we are
# unable to look them up via a unique identifier.
HubspotOrganisation.objects.create(
Expand Down