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

Prevent known domains in pipedrive #1729

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,7 @@
PIPEDRIVE_SIGN_UP_TYPE_DEAL_FIELD_KEY = env.str(
"PIPEDRIVE_SIGN_UP_TYPE_DEAL_FIELD_KEY", None
)
PIPEDRIVE_IGNORE_DOMAINS = env.list(
"PIPEDRIVE_IGNORE_DOMAINS",
["solidstategroup.com", "flagsmith.com", "bullet-train.io"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we add gmail.com, hotmail.com, etc. to this list?

)
4 changes: 4 additions & 0 deletions api/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def auth_type(self):
def full_name(self):
return self.get_full_name()

@property
def email_domain(self):
return self.email.split("@")[1]

def get_full_name(self):
if not self.first_name:
return None
Expand Down
11 changes: 8 additions & 3 deletions api/users/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ def warn_insecure(sender, **kwargs):

@receiver(post_save, sender=FFAdminUser)
def create_pipedrive_lead_signal(sender, instance, created, **kwargs):
if not (
created
and (settings.PIPEDRIVE_API_TOKEN or settings.ENABLE_PIPEDRIVE_LEAD_TRACKING)
if (
not (
created
and (
settings.PIPEDRIVE_API_TOKEN or settings.ENABLE_PIPEDRIVE_LEAD_TRACKING
)
)
or instance.email_domain in settings.PIPEDRIVE_IGNORE_DOMAINS
):
return

Expand Down
19 changes: 19 additions & 0 deletions api/users/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,22 @@ def test_user_create_calls_pipedrive_tracking(mocker, db, settings):

# Then
mocked_create_pipedrive_lead.delay.assert_called()


def test_user_create_does_not_call_pipedrive_tracking_if_ignored_domain(
mocker, db, settings
):
# Given
mocked_create_pipedrive_lead = mocker.patch("users.signals.create_pipedrive_lead")
settings.ENABLE_PIPEDRIVE_LEAD_TRACKING = True
settings.PIPEDRIVE_IGNORE_DOMAINS = ["example.com"]

# When
FFAdminUser.objects.create(email="test@example.com")

# Then
mocked_create_pipedrive_lead.delay.assert_not_called()


def test_user_email_domain_property():
assert FFAdminUser(email="test@example.com").email_domain == "example.com"