mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 18:39:21 +02:00
hash
This commit is contained in:
parent
b6a70e6d3c
commit
5815d6733c
3 changed files with 42 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import Union
|
from typing import Union
|
||||||
import logging
|
import logging
|
||||||
|
from django.template.loader import get_template
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -10,7 +10,7 @@ from django.utils import timezone
|
||||||
from waffle import flag_is_active
|
from waffle import flag_is_active
|
||||||
from registrar.models.domain import Domain
|
from registrar.models.domain import Domain
|
||||||
from registrar.models.federal_agency import FederalAgency
|
from registrar.models.federal_agency import FederalAgency
|
||||||
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper
|
from registrar.models.utility.generic_helper import CreateOrUpdateOrganizationTypeHelper, convert_string_to_sha256_hash
|
||||||
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
|
||||||
from registrar.utility.constants import BranchChoices
|
from registrar.utility.constants import BranchChoices
|
||||||
|
|
||||||
|
@ -864,9 +864,16 @@ class DomainRequest(TimeStampedModel):
|
||||||
"""Sends out an automatic email for each valid action needed reason provided"""
|
"""Sends out an automatic email for each valid action needed reason provided"""
|
||||||
|
|
||||||
# Store the filenames of the template and template subject
|
# Store the filenames of the template and template subject
|
||||||
email_template_name: str = "" if not custom_email_content else "custom_email.txt"
|
email_template_name: str = ""
|
||||||
email_template_subject_name: str = ""
|
email_template_subject_name: str = ""
|
||||||
|
|
||||||
|
# Check if the current email that we sent out is the same as our defaults.
|
||||||
|
# If these hashes differ, then that means that we're sending custom content.
|
||||||
|
default_email_hash = self._get_action_needed_reason_email_hash()
|
||||||
|
current_email_hash = convert_string_to_sha256_hash(self.action_needed_reason_email)
|
||||||
|
if default_email_hash != current_email_hash:
|
||||||
|
email_template_name = "custom_email.txt"
|
||||||
|
|
||||||
# Check for the "type" of action needed reason.
|
# Check for the "type" of action needed reason.
|
||||||
can_send_email = True
|
can_send_email = True
|
||||||
match self.action_needed_reason:
|
match self.action_needed_reason:
|
||||||
|
@ -899,6 +906,22 @@ class DomainRequest(TimeStampedModel):
|
||||||
wrap_email=True,
|
wrap_email=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO - rework this
|
||||||
|
def _get_action_needed_reason_email_hash(self):
|
||||||
|
"""Returns the default email associated with the given action needed reason"""
|
||||||
|
if self.action_needed_reason is None or self.action_needed_reason == self.ActionNeededReasons.OTHER:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Get the email body
|
||||||
|
template_path = f"emails/action_needed_reasons/{self.action_needed_reason}.txt"
|
||||||
|
template = get_template(template_path)
|
||||||
|
|
||||||
|
recipient = self.creator if flag_is_active(None, "profile_feature") else self.submitter
|
||||||
|
# Return the content of the rendered views
|
||||||
|
context = {"domain_request": self, "recipient": recipient}
|
||||||
|
body_text = template.render(context=context)
|
||||||
|
return convert_string_to_sha256_hash(body_text)
|
||||||
|
|
||||||
@transition(
|
@transition(
|
||||||
field="status",
|
field="status",
|
||||||
source=[
|
source=[
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import hashlib
|
||||||
from urllib.parse import urlparse, urlunparse, urlencode
|
from urllib.parse import urlparse, urlunparse, urlencode
|
||||||
|
|
||||||
|
|
||||||
|
@ -321,3 +322,7 @@ def convert_queryset_to_dict(queryset, is_model=True, key="id"):
|
||||||
request_dict = {value[key]: value for value in queryset}
|
request_dict = {value[key]: value for value in queryset}
|
||||||
|
|
||||||
return request_dict
|
return request_dict
|
||||||
|
|
||||||
|
|
||||||
|
def convert_string_to_sha256_hash(string_to_convert):
|
||||||
|
return hashlib.sha256(string_to_convert.encode('utf-8')).hexdigest()
|
|
@ -1540,6 +1540,17 @@ class TestDomainRequestAdmin(MockEppLib):
|
||||||
# Should be unchanged from before
|
# Should be unchanged from before
|
||||||
self.assertEqual(len(self.mock_client.EMAILS_SENT), 4)
|
self.assertEqual(len(self.mock_client.EMAILS_SENT), 4)
|
||||||
|
|
||||||
|
# Tests if an analyst can override existing email content
|
||||||
|
questionable_ao = DomainRequest.ActionNeededReasons.QUESTIONABLE_AUTHORIZING_OFFICIAL
|
||||||
|
domain_request.action_needed_reason_email = "custom email content"
|
||||||
|
domain_request.save()
|
||||||
|
self.transition_state_and_send_email(domain_request, action_needed, action_needed_reason=questionable_ao)
|
||||||
|
|
||||||
|
self.assert_email_is_accurate(
|
||||||
|
"custom email content", 4, EMAIL, bcc_email_address=BCC_EMAIL
|
||||||
|
)
|
||||||
|
self.assertEqual(len(self.mock_client.EMAILS_SENT), 5)
|
||||||
|
|
||||||
def test_save_model_sends_submitted_email(self):
|
def test_save_model_sends_submitted_email(self):
|
||||||
"""When transitioning to submitted from started or withdrawn on a domain request,
|
"""When transitioning to submitted from started or withdrawn on a domain request,
|
||||||
an email is sent out.
|
an email is sent out.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue