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

#2355: Custom rejection reason emails - [BACKUP] - MIGRATION #2869

Merged
merged 39 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
61b1cee
Refactor
zandercymatics Sep 24, 2024
48b9206
migration
zandercymatics Sep 27, 2024
9b23262
Initial architecture for rejection reason
zandercymatics Sep 27, 2024
1ce0724
Cleanup + send email logic
zandercymatics Sep 27, 2024
e37a95e
Typo
zandercymatics Sep 27, 2024
c084ec6
check for page
zandercymatics Sep 27, 2024
ff5212f
Remove unhelpful logic
zandercymatics Sep 30, 2024
7a5eda0
Fix back button bug
zandercymatics Sep 30, 2024
cfa1879
cleanup
zandercymatics Sep 30, 2024
7cc5231
cleanup
zandercymatics Sep 30, 2024
6bb907c
Simplify backend logic
zandercymatics Sep 30, 2024
5a96855
Simplify PR
zandercymatics Oct 1, 2024
47d226f
Update domain_request.py
zandercymatics Oct 1, 2024
62156ac
Merge branch 'main' into hotgov/2355-rejection-reason-emails
zandercymatics Oct 1, 2024
162369f
add migration
zandercymatics Oct 1, 2024
0a7d4e4
Exclude other reason for now
zandercymatics Oct 1, 2024
06e4dae
lint
zandercymatics Oct 1, 2024
ad43fab
fix unit tests
zandercymatics Oct 1, 2024
997fc1b
Remove no longer relevant test + linting
zandercymatics Oct 2, 2024
db0d4a1
Update admin.py
zandercymatics Oct 2, 2024
2766202
toggle email wrap
zandercymatics Oct 2, 2024
1424197
Fix remaining tests
zandercymatics Oct 2, 2024
b30e017
rename
zandercymatics Oct 2, 2024
02e18a3
Update get-gov-admin.js
zandercymatics Oct 2, 2024
5fc8d0d
Merge branch 'main' into hotgov/2355-rejection-reason-emails
zandercymatics Oct 7, 2024
ade6733
Remove bad import
zandercymatics Oct 8, 2024
e3d2dc0
Remove old migrations (merging)
zandercymatics Oct 8, 2024
c76e27f
Merge branch 'main' into hotgov/2355-rejection-reason-emails
zandercymatics Oct 8, 2024
081c762
Revert "Remove old migrations (merging)"
zandercymatics Oct 8, 2024
a4ffc75
Fix migrations
zandercymatics Oct 8, 2024
fc8090d
Merge branch 'main' into hotgov/2355-rejection-reason-emails
zandercymatics Oct 9, 2024
7c69205
Update test_models.py
zandercymatics Oct 9, 2024
3ba4293
Update test_models.py
zandercymatics Oct 9, 2024
bd603f6
Remove space
zandercymatics Oct 9, 2024
ec1df25
remove bad test + lint
zandercymatics Oct 9, 2024
dbfc548
Fix test + some minor cleanup stuff
zandercymatics Oct 10, 2024
3e54bb1
simplify javascript
zandercymatics Oct 10, 2024
3fb9ab5
lint
zandercymatics Oct 10, 2024
8b70554
Merge branch 'main' into hotgov/2355-rejection-reason-emails
zandercymatics Oct 10, 2024
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
43 changes: 20 additions & 23 deletions src/registrar/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from django.db.models import Value, CharField, Q
from django.db.models.functions import Concat, Coalesce
from django.http import HttpResponseRedirect
from registrar.utility.admin_helpers import (
get_action_needed_reason_default_email,
get_rejection_reason_default_email,
get_field_links_as_list,
)
from django.conf import settings
from django.shortcuts import redirect
from django_fsm import get_available_FIELD_transitions, FSMField
Expand All @@ -20,11 +25,6 @@
from registrar.models.user_domain_role import UserDomainRole
from waffle.admin import FlagAdmin
from waffle.models import Sample, Switch
from registrar.utility.admin_helpers import (
get_all_action_needed_reason_emails,
get_action_needed_reason_default_email,
get_field_links_as_list,
)
from registrar.models import Contact, Domain, DomainRequest, DraftDomain, User, Website, SeniorOfficial
from registrar.utility.constants import BranchChoices
from registrar.utility.errors import FSMDomainRequestError, FSMErrorCodes
Expand Down Expand Up @@ -237,6 +237,7 @@ class Meta:
}
labels = {
"action_needed_reason_email": "Email",
"rejection_reason_email": "Email",
}

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -1750,6 +1751,7 @@ def status_history(self, obj):
"status_history",
"status",
"rejection_reason",
"rejection_reason_email",
"action_needed_reason",
"action_needed_reason_email",
"investigator",
Expand Down Expand Up @@ -1905,25 +1907,11 @@ def save_model(self, request, obj, form, change):
# Get the original domain request from the database.
original_obj = models.DomainRequest.objects.get(pk=obj.pk)

# == Handle action_needed_reason == #

reason_changed = obj.action_needed_reason != original_obj.action_needed_reason
if reason_changed:
# Track the fact that we sent out an email
request.session["action_needed_email_sent"] = True

# Set the action_needed_reason_email to the default if nothing exists.
# Since this check occurs after save, if the user enters a value then we won't update.

default_email = get_action_needed_reason_default_email(request, obj, obj.action_needed_reason)
if obj.action_needed_reason_email:
emails = get_all_action_needed_reason_emails(request, obj)
is_custom_email = obj.action_needed_reason_email not in emails.values()
if not is_custom_email:
obj.action_needed_reason_email = default_email
else:
obj.action_needed_reason_email = default_email
# == Handle action needed and rejected emails == #
# Edge case: this logic is handled by javascript, so contexts outside that must be handled
obj = self._handle_custom_emails(obj)

# == Handle allowed emails == #
if obj.status in DomainRequest.get_statuses_that_send_emails() and not settings.IS_PRODUCTION:
self._check_for_valid_email(request, obj)

Expand All @@ -1939,6 +1927,15 @@ def save_model(self, request, obj, form, change):
if should_save:
return super().save_model(request, obj, form, change)

def _handle_custom_emails(self, obj):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much cleaner

if obj.status == DomainRequest.DomainRequestStatus.ACTION_NEEDED:
if obj.action_needed_reason and not obj.action_needed_reason_email:
obj.action_needed_reason_email = get_action_needed_reason_default_email(obj, obj.action_needed_reason)
elif obj.status == DomainRequest.DomainRequestStatus.REJECTED:
if obj.rejection_reason and not obj.rejection_reason_email:
obj.rejection_reason_email = get_rejection_reason_default_email(obj, obj.rejection_reason)
return obj

def _check_for_valid_email(self, request, obj):
"""Certain emails are whitelisted in non-production environments,
so we should display that information using this function.
Expand Down
Loading
Loading