mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-31 01:33:56 +02:00
minor fixes + add notes
This commit is contained in:
parent
7fb186e24b
commit
c1378acd2c
4 changed files with 51 additions and 4 deletions
|
@ -1923,9 +1923,11 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
recipient = obj.creator
|
recipient = obj.creator
|
||||||
elif not profile_flag and hasattr(obj, "submitter"):
|
elif not profile_flag and hasattr(obj, "submitter"):
|
||||||
recipient = obj.submitter
|
recipient = obj.submitter
|
||||||
else
|
else:
|
||||||
recipient = None
|
recipient = None
|
||||||
|
|
||||||
|
# Displays a warning in admin when an email cannot be sent,
|
||||||
|
# Or a success message if it was.
|
||||||
if recipient and recipient.email:
|
if recipient and recipient.email:
|
||||||
self._check_for_valid_email(request, recipient.email)
|
self._check_for_valid_email(request, recipient.email)
|
||||||
|
|
||||||
|
@ -1949,8 +1951,11 @@ class DomainRequestAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
|
|
||||||
allowed = models.AllowedEmail.is_allowed_email(email)
|
allowed = models.AllowedEmail.is_allowed_email(email)
|
||||||
error_message = f"Could not send email. The email '{email}' does not exist within the whitelist."
|
error_message = f"Could not send email. The email '{email}' does not exist within the whitelist."
|
||||||
|
success_message = f"An email to '{email}' was sent!"
|
||||||
if not allowed:
|
if not allowed:
|
||||||
messages.warning(request, error_message)
|
messages.warning(request, error_message)
|
||||||
|
else:
|
||||||
|
messages.success(request, success_message)
|
||||||
|
|
||||||
def _handle_status_change(self, request, obj, original_obj):
|
def _handle_status_change(self, request, obj, original_obj):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -241,7 +241,8 @@ class UserFixture:
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
# Additional emails to add to the AllowedEmail whitelist
|
# Additional emails to add to the AllowedEmail whitelist.
|
||||||
|
# The format should be as follows: ["email@igorville.gov", "email2@igorville.gov"]
|
||||||
ADDITIONAL_ALLOWED_EMAILS = [
|
ADDITIONAL_ALLOWED_EMAILS = [
|
||||||
"zander.adkinson@ecstech.com"
|
"zander.adkinson@ecstech.com"
|
||||||
]
|
]
|
||||||
|
@ -286,7 +287,7 @@ class UserFixture:
|
||||||
else:
|
else:
|
||||||
first_name = user_data.get("first_name")
|
first_name = user_data.get("first_name")
|
||||||
last_name = user_data.get("last_name")
|
last_name = user_data.get("last_name")
|
||||||
logger.warning(f"Could not load email for {first_name} {last_name}: No email exists.")
|
logger.warning(f"Could add email to whitelist for {first_name} {last_name}: No email exists.")
|
||||||
|
|
||||||
# Load additional emails
|
# Load additional emails
|
||||||
for email in additional_emails:
|
for email in additional_emails:
|
||||||
|
|
|
@ -31,7 +31,10 @@ class AllowedEmail(TimeStampedModel):
|
||||||
if "+" in local:
|
if "+" in local:
|
||||||
base_local = local.split("+")[0]
|
base_local = local.split("+")[0]
|
||||||
base_email = f"{base_local}@{domain}"
|
base_email = f"{base_local}@{domain}"
|
||||||
allowed_emails = cls.objects.filter(email__iexact=base_email)
|
allowed_emails = cls.objects.filter(
|
||||||
|
Q(email__iexact=base_email) |
|
||||||
|
Q(email__iexact=email)
|
||||||
|
)
|
||||||
|
|
||||||
# The string must start with the local, and the plus must be a digit
|
# The string must start with the local, and the plus must be a digit
|
||||||
# and occur immediately after the local. The domain should still exist in the email.
|
# and occur immediately after the local. The domain should still exist in the email.
|
||||||
|
|
|
@ -2320,3 +2320,41 @@ class TestPortfolio(TestCase):
|
||||||
|
|
||||||
self.assertEqual(portfolio.urbanization, "test123")
|
self.assertEqual(portfolio.urbanization, "test123")
|
||||||
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.PUERTO_RICO)
|
self.assertEqual(portfolio.state_territory, DomainRequest.StateTerritoryChoices.PUERTO_RICO)
|
||||||
|
|
||||||
|
|
||||||
|
class TestAllowedEmail(TestCase):
|
||||||
|
"""Tests our allowed email whitelist"""
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def setUp(self):
|
||||||
|
self.email = "mayor@igorville.gov"
|
||||||
|
self.domain_name = "igorvilleInTransition.gov"
|
||||||
|
self.domain, _ = Domain.objects.get_or_create(name="igorville.gov")
|
||||||
|
self.user, _ = User.objects.get_or_create(email=self.email)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
|
Domain.objects.all().delete()
|
||||||
|
DomainInvitation.objects.all().delete()
|
||||||
|
DomainInformation.objects.all().delete()
|
||||||
|
DomainRequest.objects.all().delete()
|
||||||
|
DraftDomain.objects.all().delete()
|
||||||
|
TransitionDomain.objects.all().delete()
|
||||||
|
Portfolio.objects.all().delete()
|
||||||
|
User.objects.all().delete()
|
||||||
|
UserDomainRole.objects.all().delete()
|
||||||
|
|
||||||
|
|
||||||
|
# Test for a normal email defined in the whitelist
|
||||||
|
# Test for a normal email NOT defined in the whitelist
|
||||||
|
|
||||||
|
# Test for a +1 email defined in the whitelist
|
||||||
|
# Test for a +1 email NOT defined in the whitelist
|
||||||
|
|
||||||
|
# Test for a +1 email NOT defined in the whitelist, but the normal is defined
|
||||||
|
# Test for a +1 email defined in the whitelist, but the normal is NOT defined
|
||||||
|
# Test for a +1 email NOT defined in the whitelist and NOT defined in the normal
|
||||||
|
|
||||||
|
# Test for an invalid email that contains a '+'
|
||||||
|
|
||||||
|
# TODO: We need a small test for domain request admin
|
Loading…
Add table
Add a link
Reference in a new issue