mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-17 18:09:25 +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 typing import Union
|
||||
import logging
|
||||
|
||||
from django.template.loader import get_template
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
@ -10,7 +10,7 @@ from django.utils import timezone
|
|||
from waffle import flag_is_active
|
||||
from registrar.models.domain import Domain
|
||||
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.constants import BranchChoices
|
||||
|
||||
|
@ -864,9 +864,16 @@ class DomainRequest(TimeStampedModel):
|
|||
"""Sends out an automatic email for each valid action needed reason provided"""
|
||||
|
||||
# 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 = ""
|
||||
|
||||
# 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.
|
||||
can_send_email = True
|
||||
match self.action_needed_reason:
|
||||
|
@ -899,6 +906,22 @@ class DomainRequest(TimeStampedModel):
|
|||
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(
|
||||
field="status",
|
||||
source=[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue