Skip to content

Commit

Permalink
Merge pull request #4299 from mozilla/Put-permanent-domain-address-de…
Browse files Browse the repository at this point in the history
…lete-logic-behind-flag

Put permanent domain address delete logic behind flag
  • Loading branch information
say-yawn authored Jan 12, 2024
2 parents 1630cef + f0de410 commit a904a6e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
10 changes: 7 additions & 3 deletions emails/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,13 @@ def valid_address_pattern(address):
def valid_address(address: str, domain: str, subdomain: str | None = None) -> bool:
address_pattern_valid = valid_address_pattern(address)
address_contains_badword = has_bad_words(address)
address_already_deleted = DeletedAddress.objects.filter(
address_hash=address_hash(address, domain=domain, subdomain=subdomain)
).count()
address_already_deleted = 0
if not subdomain or flag_is_active_in_task(
"custom_domain_management_redesign", None
):
address_already_deleted = DeletedAddress.objects.filter(
address_hash=address_hash(address, domain=domain, subdomain=subdomain)
).count()
if (
address_already_deleted > 0
or address_contains_badword
Expand Down
47 changes: 33 additions & 14 deletions emails/tests/models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.test import override_settings, TestCase

from allauth.socialaccount.models import SocialAccount
from waffle.testutils import override_flag
import pytest

from model_bakery import baker
Expand Down Expand Up @@ -348,20 +349,6 @@ def test_valid_address_dupe_of_deleted_invalid(self):
relay_address.delete()
assert not valid_address(relay_address.address, relay_address.domain_value)

def test_dupe_domain_address_of_deleted_invalid(self):
user = make_premium_test_user()
user_profile = user.profile
user_profile.subdomain = "test"
user_profile.save()
address = "same-address"
domain_address = DomainAddress.make_domain_address(
user_profile, address=address
)
domain_address.delete()
assert not valid_address(
address, domain_address.domain_value, user_profile.subdomain
)

@patch.object(emails_config, "blocklist", ["blocked-word"])
def test_address_contains_blocklist_invalid(self) -> None:
blocked_word = "blocked-word"
Expand Down Expand Up @@ -1122,6 +1109,38 @@ def test_make_domain_address_valid_premium_user_with_no_subdomain(self) -> None:
DomainAddress.make_domain_address(user_profile, "test-nosubdomain")
assert exc_info.value.get_codes() == "need_subdomain"

@override_flag("custom_domain_management_redesign", active=False)
def test_make_domain_address_can_make_dupe_of_deleted(self):
address = "same-address"
domain_address = DomainAddress.make_domain_address(
self.user_profile, address=address
)
domain_address_hash = address_hash(
domain_address.address,
domain_address.user_profile.subdomain,
domain_address.domain_value,
)
domain_address.delete()
dupe_domain_address = DomainAddress.make_domain_address(
self.user_profile, address=address
)
assert (
DeletedAddress.objects.filter(address_hash=domain_address_hash).count() == 1
)
assert dupe_domain_address.full_address == domain_address.full_address

@override_flag("custom_domain_management_redesign", active=True)
def test_valid_address_dupe_domain_address_of_deleted_is_not_valid(self):
address = "same-address"
domain_address = DomainAddress.make_domain_address(
self.user_profile, address=address
)
domain_address.delete()
assert not valid_address(
address, domain_address.domain_value, self.user_profile.subdomain
)

@override_flag("custom_domain_management_redesign", active=True)
def test_make_domain_address_cannot_make_dupe_of_deleted(self):
address = "same-address"
domain_address = DomainAddress.make_domain_address(
Expand Down

0 comments on commit a904a6e

Please sign in to comment.