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

fix: Remove mailer lite #4705

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 0 additions & 7 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,13 +917,6 @@
GITHUB_APP_ID: int = env.int("GITHUB_APP_ID", default=0)
GITHUB_WEBHOOK_SECRET = env.str("GITHUB_WEBHOOK_SECRET", default="")

# MailerLite
MAILERLITE_BASE_URL = env.str(
"MAILERLITE_BASE_URL", default="https://api.mailerlite.com/api/v2/"
)
MAILERLITE_API_KEY = env.str("MAILERLITE_API_KEY", None)
MAILERLITE_NEW_USER_GROUP_ID = env.int("MAILERLITE_NEW_USER_GROUP_ID", None)

# Additional functionality for using SAML in Flagsmith SaaS
SAML_INSTALLED = importlib.util.find_spec("saml") is not None

Expand Down
8 changes: 0 additions & 8 deletions api/organisations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
)
from organisations.subscriptions.metadata import BaseSubscriptionMetadata
from organisations.subscriptions.xero.metadata import XeroSubscriptionMetadata
from users.utils.mailer_lite import MailerLite
from webhooks.models import AbstractBaseExportableWebhookModel

environment_cache = caches[settings.ENVIRONMENT_CACHE_NAME]
Expand Down Expand Up @@ -280,13 +279,6 @@ def update_hubspot_active_subscription(self):

update_hubspot_active_subscription.delay(args=(self.id,))

@hook(AFTER_SAVE, when="cancellation_date", has_changed=True)
@hook(AFTER_SAVE, when="subscription_id", has_changed=True)
def update_mailer_lite_subscribers(self):
if settings.MAILERLITE_API_KEY:
mailer_lite = MailerLite()
mailer_lite.update_organisation_users(self.organisation.id)

def save_as_free_subscription(self):
"""
Wipes a subscription to a normal free plan.
Expand Down
58 changes: 0 additions & 58 deletions api/tests/unit/organisations/test_unit_organisations_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.conf import settings
from django.utils import timezone
from pytest_mock import MockerFixture
from rest_framework.test import override_settings

from environments.models import Environment
from organisations.chargebee.metadata import ChargebeeObjMetadata
Expand Down Expand Up @@ -194,63 +193,6 @@ def test_organisation_default_subscription_have_one_max_seat(
assert subscription.max_seats == 1


@override_settings(MAILERLITE_API_KEY="some-test-key")
def test_updating_subscription_id_calls_mailer_lite_update_organisation_users(
mocker, db, organisation, subscription
):
# Given
mocked_mailer_lite = mocker.MagicMock()
mocker.patch("organisations.models.MailerLite", return_value=mocked_mailer_lite)

# When
subscription.subscription_id = "some-id"
subscription.save()

# Then
mocked_mailer_lite.update_organisation_users.assert_called_with(organisation.id)


@override_settings(MAILERLITE_API_KEY="some-test-key")
def test_updating_a_cancelled_subscription_calls_mailer_lite_update_organisation_users(
mocker, db, organisation, subscription
):
# Given
mocked_mailer_lite = mocker.MagicMock()
mocker.patch("organisations.models.MailerLite", return_value=mocked_mailer_lite)

subscription.cancellation_date = datetime.now()
subscription.save()

# reset the mock to remove the call by saving the subscription above
mocked_mailer_lite.reset_mock()

# When
subscription.cancellation_date = None
subscription.save()

# Then
mocked_mailer_lite.update_organisation_users.assert_called_with(organisation.id)


@override_settings(MAILERLITE_API_KEY="some-test-key")
def test_cancelling_a_subscription_calls_mailer_lite_update_organisation_users(
mocker, db, organisation, subscription
):
# Given

mocked_mailer_lite = mocker.MagicMock()
mocker.patch("organisations.models.MailerLite", return_value=mocked_mailer_lite)

# When
subscription.cancellation_date = datetime.now()
subscription.save()

# Then
mocked_mailer_lite.update_organisation_users.assert_called_once_with(
organisation.id
)


def test_organisation_is_paid_returns_false_if_subscription_does_not_exists(db):
# Given
organisation = Organisation.objects.create(name="Test org")
Expand Down
52 changes: 0 additions & 52 deletions api/tests/unit/users/test_unit_users_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from unittest import mock

import pytest
from django.db.utils import IntegrityError

Expand Down Expand Up @@ -156,56 +154,6 @@ def test_has_organisation_permission_is_false_when_user_does_not_have_permission
)


@pytest.mark.django_db
def test_creating_a_user_calls_mailer_lite_subscribe(mocker):
# Given
mailer_lite_mock = mocker.patch("users.models.mailer_lite")
# When
user = FFAdminUser.objects.create(
email="test@mail.com",
)
# Then
mailer_lite_mock.subscribe.assert_called_with(user)


@pytest.mark.django_db
def test_user_add_organisation_does_not_call_mailer_lite_subscribe_for_unpaid_organisation(
mocker,
):
user = FFAdminUser.objects.create(email="test@example.com")
organisation = Organisation.objects.create(name="Test Organisation")
mailer_lite_mock = mocker.patch("users.models.mailer_lite")
mocker.patch(
"organisations.models.Organisation.is_paid",
new_callable=mock.PropertyMock,
return_value=False,
)
# When
user.add_organisation(organisation, OrganisationRole.USER)

# Then
mailer_lite_mock.subscribe.assert_not_called()


@pytest.mark.django_db
def test_user_add_organisation_calls_mailer_lite_subscribe_for_paid_organisation(
mocker,
):
mailer_lite_mock = mocker.patch("users.models.mailer_lite")
user = FFAdminUser.objects.create(email="test@example.com")
organisation = Organisation.objects.create(name="Test Organisation")
mocker.patch(
"organisations.models.Organisation.is_paid",
new_callable=mock.PropertyMock,
return_value=True,
)
# When
user.add_organisation(organisation, OrganisationRole.USER)

# Then
mailer_lite_mock.subscribe.assert_called_with(user)


def test_user_add_organisation_adds_user_to_the_default_user_permission_group(
test_user, organisation, default_user_permission_group, user_permission_group
):
Expand Down
140 changes: 0 additions & 140 deletions api/tests/unit/users/utils/test_unit_users_mailer_lite.py

This file was deleted.

9 changes: 0 additions & 9 deletions api/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from users.auth_type import AuthType
from users.constants import DEFAULT_DELETE_ORPHAN_ORGANISATIONS_VALUE
from users.exceptions import InvalidInviteError
from users.utils.mailer_lite import MailerLite

if typing.TYPE_CHECKING:
from environments.models import Environment
Expand All @@ -47,7 +46,6 @@
)

logger = logging.getLogger(__name__)
mailer_lite = MailerLite()


class SignUpType(models.TextChoices):
Expand Down Expand Up @@ -125,10 +123,6 @@ class Meta:
def __str__(self):
return self.email

@hook(AFTER_CREATE)
def subscribe_to_mailing_list(self):
mailer_lite.subscribe(self)

@hook(AFTER_CREATE)
def schedule_hubspot_tracking(self) -> None:
if settings.ENABLE_HUBSPOT_LEAD_TRACKING:
Expand Down Expand Up @@ -223,9 +217,6 @@ def get_admin_organisations(self):
)

def add_organisation(self, organisation, role=OrganisationRole.USER):
if organisation.is_paid:
mailer_lite.subscribe(self)

UserOrganisation.objects.create(
user=self, organisation=organisation, role=role.name
)
Expand Down
Loading
Loading