mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-18 15:34:16 +02:00
merge main
This commit is contained in:
commit
6daf32894a
15 changed files with 705 additions and 117 deletions
|
@ -1367,6 +1367,8 @@ class UserDomainRoleAdmin(ListHeaderAdmin, ImportExportModelAdmin):
|
||||||
|
|
||||||
autocomplete_fields = ["user", "domain"]
|
autocomplete_fields = ["user", "domain"]
|
||||||
|
|
||||||
|
change_form_template = "django/admin/user_domain_role_change_form.html"
|
||||||
|
|
||||||
# Fixes a bug where non-superusers are redirected to the main page
|
# Fixes a bug where non-superusers are redirected to the main page
|
||||||
def delete_view(self, request, object_id, extra_context=None):
|
def delete_view(self, request, object_id, extra_context=None):
|
||||||
"""Custom delete_view implementation that specifies redirect behaviour"""
|
"""Custom delete_view implementation that specifies redirect behaviour"""
|
||||||
|
@ -1500,7 +1502,7 @@ class DomainInvitationAdmin(BaseInvitationAdmin):
|
||||||
|
|
||||||
autocomplete_fields = ["domain"]
|
autocomplete_fields = ["domain"]
|
||||||
|
|
||||||
change_form_template = "django/admin/email_clipboard_change_form.html"
|
change_form_template = "django/admin/domain_invitation_change_form.html"
|
||||||
|
|
||||||
# Select domain invitations to change -> Domain invitations
|
# Select domain invitations to change -> Domain invitations
|
||||||
def changelist_view(self, request, extra_context=None):
|
def changelist_view(self, request, extra_context=None):
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends 'django/admin/email_clipboard_change_form.html' %}
|
||||||
|
{% load custom_filters %}
|
||||||
|
{% load i18n static %}
|
||||||
|
|
||||||
|
{% block content_subtitle %}
|
||||||
|
<div class="usa-alert usa-alert--info usa-alert--slim">
|
||||||
|
<div class="usa-alert__body margin-left-1 maxw-none">
|
||||||
|
<p class="usa-alert__text maxw-none">
|
||||||
|
If you add someone to a domain here, it will trigger emails to the invitee and all managers of the domain when you click "save." If you don't want to trigger those emails, use the <a class="usa-link" href="{% url 'admin:registrar_userdomainrole_changelist' %}">User domain roles permissions table</a> instead.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ block.super }}
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,14 @@
|
||||||
|
{% extends 'django/admin/email_clipboard_change_form.html' %}
|
||||||
|
{% load custom_filters %}
|
||||||
|
{% load i18n static %}
|
||||||
|
|
||||||
|
{% block content_subtitle %}
|
||||||
|
<div class="usa-alert usa-alert--info usa-alert--slim">
|
||||||
|
<div class="usa-alert__body margin-left-1 maxw-none">
|
||||||
|
<p class="usa-alert__text maxw-none">
|
||||||
|
If you add someone to a domain here, it will not trigger any emails. To trigger emails, use the <a class="usa-link" href="{% url 'admin:registrar_domaininvitation_changelist' %}">User Domain Role invitations table</a> instead.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{ block.super }}
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,43 @@
|
||||||
|
{% autoescape off %}{# In a text file, we don't want to have HTML entities escaped #}
|
||||||
|
Hi,{% if domain_manager and domain_manager.first_name %} {{ domain_manager.first_name }}.{% endif %}
|
||||||
|
|
||||||
|
A domain manager was invited to {{ domain.name }}.
|
||||||
|
DOMAIN: {{ domain.name }}
|
||||||
|
INVITED BY: {{ requestor_email }}
|
||||||
|
INVITED ON: {{date}}
|
||||||
|
MANAGER INVITED: {{ invited_email_address }}
|
||||||
|
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
NEXT STEPS
|
||||||
|
|
||||||
|
The person who received the invitation will become a domain manager once they log in to the
|
||||||
|
.gov registrar. They'll need to access the registrar using a Login.gov account that's
|
||||||
|
associated with the invited email address.
|
||||||
|
|
||||||
|
If you need to cancel this invitation or remove the domain manager (because they've already
|
||||||
|
logged in), you can do that by going to this domain in the .gov registrar <https://manage.get.gov/>.
|
||||||
|
|
||||||
|
|
||||||
|
WHY DID YOU RECEIVE THIS EMAIL?
|
||||||
|
|
||||||
|
You’re listed as a domain manager for {{ domain.name }}, so you’ll receive a notification whenever
|
||||||
|
someone is invited to manage that domain.
|
||||||
|
|
||||||
|
If you have questions or concerns, reach out to the person who sent the invitation or reply to this email.
|
||||||
|
|
||||||
|
|
||||||
|
THANK YOU
|
||||||
|
.Gov helps the public identify official, trusted information. Thank you for using a .gov domain.
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
|
||||||
|
The .gov team
|
||||||
|
Contact us: <https://get.gov/contact/>
|
||||||
|
Learn about .gov <https://get.gov>
|
||||||
|
|
||||||
|
The .gov registry is a part of the Cybersecurity and Infrastructure Security Agency
|
||||||
|
(CISA) <https://cisa.gov/>
|
||||||
|
{% endautoescape %}
|
|
@ -0,0 +1 @@
|
||||||
|
A domain manager was invited to {{ domain.name }}
|
|
@ -578,6 +578,13 @@ class MockDb(TestCase):
|
||||||
creator=cls.custom_superuser, federal_agency=cls.federal_agency_3, organization_type="federal"
|
creator=cls.custom_superuser, federal_agency=cls.federal_agency_3, organization_type="federal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cls.suborganization_1, _ = Suborganization.objects.get_or_create(
|
||||||
|
name="SubOrg 1",
|
||||||
|
portfolio=cls.portfolio_1,
|
||||||
|
city="Nashville",
|
||||||
|
state_territory="TN",
|
||||||
|
)
|
||||||
|
|
||||||
current_date = get_time_aware_date(datetime(2024, 4, 2))
|
current_date = get_time_aware_date(datetime(2024, 4, 2))
|
||||||
# Create start and end dates using timedelta
|
# Create start and end dates using timedelta
|
||||||
|
|
||||||
|
@ -848,6 +855,7 @@ class MockDb(TestCase):
|
||||||
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
|
status=DomainRequest.DomainRequestStatus.IN_REVIEW,
|
||||||
name="city2.gov",
|
name="city2.gov",
|
||||||
portfolio=cls.portfolio_1,
|
portfolio=cls.portfolio_1,
|
||||||
|
sub_organization=cls.suborganization_1,
|
||||||
)
|
)
|
||||||
cls.domain_request_3 = completed_domain_request(
|
cls.domain_request_3 = completed_domain_request(
|
||||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
@ -863,6 +871,9 @@ class MockDb(TestCase):
|
||||||
cls.domain_request_5 = completed_domain_request(
|
cls.domain_request_5 = completed_domain_request(
|
||||||
status=DomainRequest.DomainRequestStatus.APPROVED,
|
status=DomainRequest.DomainRequestStatus.APPROVED,
|
||||||
name="city5.gov",
|
name="city5.gov",
|
||||||
|
requested_suborganization="requested_suborg",
|
||||||
|
suborganization_city="SanFran",
|
||||||
|
suborganization_state_territory="CA",
|
||||||
)
|
)
|
||||||
cls.domain_request_6 = completed_domain_request(
|
cls.domain_request_6 = completed_domain_request(
|
||||||
status=DomainRequest.DomainRequestStatus.STARTED,
|
status=DomainRequest.DomainRequestStatus.STARTED,
|
||||||
|
|
|
@ -166,6 +166,29 @@ class TestDomainInvitationAdmin(TestCase):
|
||||||
)
|
)
|
||||||
self.assertContains(response, "Show more")
|
self.assertContains(response, "Show more")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_has_change_form_description(self):
|
||||||
|
"""Tests if this model has a model description on the change form view"""
|
||||||
|
self.client.force_login(self.superuser)
|
||||||
|
|
||||||
|
domain, _ = Domain.objects.get_or_create(name="systemofadown.com")
|
||||||
|
|
||||||
|
domain_invitation, _ = DomainInvitation.objects.get_or_create(email="toxicity@systemofadown.com", domain=domain)
|
||||||
|
|
||||||
|
response = self.client.get(
|
||||||
|
"/admin/registrar/domaininvitation/{}/change/".format(domain_invitation.pk),
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make sure that the page is loaded correctly
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Test for a description snippet
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
"If you add someone to a domain here, it will trigger emails to the invitee and all managers of the domain",
|
||||||
|
)
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_get_filters(self):
|
def test_get_filters(self):
|
||||||
"""Ensures that our filters are displaying correctly"""
|
"""Ensures that our filters are displaying correctly"""
|
||||||
|
@ -1957,6 +1980,31 @@ class TestUserDomainRoleAdmin(TestCase):
|
||||||
)
|
)
|
||||||
self.assertContains(response, "Show more")
|
self.assertContains(response, "Show more")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_has_change_form_description(self):
|
||||||
|
"""Tests if this model has a model description on the change form view"""
|
||||||
|
self.client.force_login(self.superuser)
|
||||||
|
|
||||||
|
domain, _ = Domain.objects.get_or_create(name="systemofadown.com")
|
||||||
|
|
||||||
|
user_domain_role, _ = UserDomainRole.objects.get_or_create(
|
||||||
|
user=self.superuser, domain=domain, role=[UserDomainRole.Roles.MANAGER]
|
||||||
|
)
|
||||||
|
|
||||||
|
response = self.client.get(
|
||||||
|
"/admin/registrar/userdomainrole/{}/change/".format(user_domain_role.pk),
|
||||||
|
follow=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Make sure that the page is loaded correctly
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Test for a description snippet
|
||||||
|
self.assertContains(
|
||||||
|
response,
|
||||||
|
"If you add someone to a domain here, it will not trigger any emails.",
|
||||||
|
)
|
||||||
|
|
||||||
def test_domain_sortable(self):
|
def test_domain_sortable(self):
|
||||||
"""Tests if the UserDomainrole sorts by domain correctly"""
|
"""Tests if the UserDomainrole sorts by domain correctly"""
|
||||||
with less_console_noise():
|
with less_console_noise():
|
||||||
|
@ -3442,7 +3490,7 @@ class TestTransferUser(WebTest):
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_transfer_user_transfers_user_portfolio_roles_no_error_when_duplicates(self):
|
def test_transfer_user_transfers_user_portfolio_roles_no_error_when_duplicates(self):
|
||||||
"""Assert that duplicate portfolio user roles do not throw errorsd"""
|
"""Assert that duplicate portfolio user roles do not throw errors"""
|
||||||
portfolio1 = Portfolio.objects.create(organization_name="Hotel California", creator=self.user2)
|
portfolio1 = Portfolio.objects.create(organization_name="Hotel California", creator=self.user2)
|
||||||
UserPortfolioPermission.objects.create(
|
UserPortfolioPermission.objects.create(
|
||||||
user=self.user1, portfolio=portfolio1, roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
user=self.user1, portfolio=portfolio1, roles=[UserPortfolioRoleChoices.ORGANIZATION_ADMIN]
|
||||||
|
@ -3574,7 +3622,7 @@ class TestTransferUser(WebTest):
|
||||||
with self.assertRaises(User.DoesNotExist):
|
with self.assertRaises(User.DoesNotExist):
|
||||||
self.user2.refresh_from_db()
|
self.user2.refresh_from_db()
|
||||||
|
|
||||||
@less_console_noise_decorator
|
# @less_console_noise_decorator
|
||||||
def test_transfer_user_throws_transfer_and_delete_success_messages(self):
|
def test_transfer_user_throws_transfer_and_delete_success_messages(self):
|
||||||
"""Test that success messages for data transfer and user deletion are displayed."""
|
"""Test that success messages for data transfer and user deletion are displayed."""
|
||||||
# Ensure the setup for VerifiedByStaff
|
# Ensure the setup for VerifiedByStaff
|
||||||
|
@ -3592,11 +3640,13 @@ class TestTransferUser(WebTest):
|
||||||
|
|
||||||
self.assertContains(after_submit, "<h1>Change user</h1>")
|
self.assertContains(after_submit, "<h1>Change user</h1>")
|
||||||
|
|
||||||
|
print(mock_success_message.call_args_list)
|
||||||
|
|
||||||
mock_success_message.assert_any_call(
|
mock_success_message.assert_any_call(
|
||||||
ANY,
|
ANY,
|
||||||
(
|
(
|
||||||
"Data transferred successfully for the following objects: ['Changed requestor "
|
"Data transferred successfully for the following objects: ['Changed requestor "
|
||||||
+ 'from "Furiosa Jabassa " to "Max Rokatanski " on immortan.joe@citadel.com\']'
|
+ "from Furiosa Jabassa to Max Rokatanski on immortan.joe@citadel.com']"
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3606,7 +3656,7 @@ class TestTransferUser(WebTest):
|
||||||
def test_transfer_user_throws_error_message(self):
|
def test_transfer_user_throws_error_message(self):
|
||||||
"""Test that an error message is thrown if the transfer fails."""
|
"""Test that an error message is thrown if the transfer fails."""
|
||||||
with patch(
|
with patch(
|
||||||
"registrar.views.TransferUserView.transfer_user_fields_and_log", side_effect=Exception("Simulated Error")
|
"registrar.views.TransferUserView.transfer_related_fields_and_log", side_effect=Exception("Simulated Error")
|
||||||
):
|
):
|
||||||
with patch("django.contrib.messages.error") as mock_error:
|
with patch("django.contrib.messages.error") as mock_error:
|
||||||
# Access the transfer user page
|
# Access the transfer user page
|
||||||
|
|
311
src/registrar/tests/test_email_invitations.py
Normal file
311
src/registrar/tests/test_email_invitations.py
Normal file
|
@ -0,0 +1,311 @@
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
from datetime import date
|
||||||
|
from registrar.utility.email import EmailSendingError
|
||||||
|
from registrar.utility.email_invitations import send_domain_invitation_email
|
||||||
|
|
||||||
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
|
||||||
|
|
||||||
|
class DomainInvitationEmail(unittest.TestCase):
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
@patch("registrar.utility.email_invitations.send_templated_email")
|
||||||
|
@patch("registrar.utility.email_invitations.UserDomainRole.objects.filter")
|
||||||
|
@patch("registrar.utility.email_invitations.validate_invitation")
|
||||||
|
@patch("registrar.utility.email_invitations.get_requestor_email")
|
||||||
|
@patch("registrar.utility.email_invitations.send_invitation_email")
|
||||||
|
@patch("registrar.utility.email_invitations.normalize_domains")
|
||||||
|
def test_send_domain_invitation_email(
|
||||||
|
self,
|
||||||
|
mock_normalize_domains,
|
||||||
|
mock_send_invitation_email,
|
||||||
|
mock_get_requestor_email,
|
||||||
|
mock_validate_invitation,
|
||||||
|
mock_user_domain_role_filter,
|
||||||
|
mock_send_templated_email,
|
||||||
|
):
|
||||||
|
"""Test sending domain invitation email for one domain.
|
||||||
|
Should also send emails to manager of that domain.
|
||||||
|
"""
|
||||||
|
# Setup
|
||||||
|
mock_domain = MagicMock(name="domain1")
|
||||||
|
mock_domain.name = "example.com"
|
||||||
|
mock_normalize_domains.return_value = [mock_domain]
|
||||||
|
|
||||||
|
mock_requestor = MagicMock()
|
||||||
|
mock_requestor_email = "requestor@example.com"
|
||||||
|
mock_get_requestor_email.return_value = mock_requestor_email
|
||||||
|
|
||||||
|
mock_user1 = MagicMock()
|
||||||
|
mock_user1.email = "manager1@example.com"
|
||||||
|
|
||||||
|
mock_user_domain_role_filter.return_value = [MagicMock(user=mock_user1)]
|
||||||
|
|
||||||
|
email = "invitee@example.com"
|
||||||
|
is_member_of_different_org = False
|
||||||
|
|
||||||
|
# Call the function
|
||||||
|
send_domain_invitation_email(
|
||||||
|
email=email,
|
||||||
|
requestor=mock_requestor,
|
||||||
|
domains=mock_domain,
|
||||||
|
is_member_of_different_org=is_member_of_different_org,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assertions
|
||||||
|
mock_normalize_domains.assert_called_once_with(mock_domain)
|
||||||
|
mock_get_requestor_email.assert_called_once_with(mock_requestor, [mock_domain])
|
||||||
|
mock_validate_invitation.assert_called_once_with(
|
||||||
|
email, [mock_domain], mock_requestor, is_member_of_different_org
|
||||||
|
)
|
||||||
|
mock_send_invitation_email.assert_called_once_with(email, mock_requestor_email, [mock_domain], None)
|
||||||
|
mock_user_domain_role_filter.assert_called_once_with(domain=mock_domain)
|
||||||
|
mock_send_templated_email.assert_called_once_with(
|
||||||
|
"emails/domain_manager_notification.txt",
|
||||||
|
"emails/domain_manager_notification_subject.txt",
|
||||||
|
to_address=mock_user1.email,
|
||||||
|
context={
|
||||||
|
"domain": mock_domain,
|
||||||
|
"requestor_email": mock_requestor_email,
|
||||||
|
"invited_email_address": email,
|
||||||
|
"domain_manager": mock_user1,
|
||||||
|
"date": date.today(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
@patch("registrar.utility.email_invitations.send_templated_email")
|
||||||
|
@patch("registrar.utility.email_invitations.UserDomainRole.objects.filter")
|
||||||
|
@patch("registrar.utility.email_invitations.validate_invitation")
|
||||||
|
@patch("registrar.utility.email_invitations.get_requestor_email")
|
||||||
|
@patch("registrar.utility.email_invitations.send_invitation_email")
|
||||||
|
@patch("registrar.utility.email_invitations.normalize_domains")
|
||||||
|
def test_send_domain_invitation_email_multiple_domains(
|
||||||
|
self,
|
||||||
|
mock_normalize_domains,
|
||||||
|
mock_send_invitation_email,
|
||||||
|
mock_get_requestor_email,
|
||||||
|
mock_validate_invitation,
|
||||||
|
mock_user_domain_role_filter,
|
||||||
|
mock_send_templated_email,
|
||||||
|
):
|
||||||
|
"""Test sending domain invitation email for multiple domains.
|
||||||
|
Should also send emails to managers of each domain.
|
||||||
|
"""
|
||||||
|
# Setup
|
||||||
|
# Create multiple mock domains
|
||||||
|
mock_domain1 = MagicMock(name="domain1")
|
||||||
|
mock_domain1.name = "example.com"
|
||||||
|
mock_domain2 = MagicMock(name="domain2")
|
||||||
|
mock_domain2.name = "example.org"
|
||||||
|
|
||||||
|
mock_normalize_domains.return_value = [mock_domain1, mock_domain2]
|
||||||
|
|
||||||
|
mock_requestor = MagicMock()
|
||||||
|
mock_requestor_email = "requestor@example.com"
|
||||||
|
mock_get_requestor_email.return_value = mock_requestor_email
|
||||||
|
|
||||||
|
mock_user1 = MagicMock()
|
||||||
|
mock_user1.email = "manager1@example.com"
|
||||||
|
mock_user2 = MagicMock()
|
||||||
|
mock_user2.email = "manager2@example.com"
|
||||||
|
|
||||||
|
# Configure domain roles for each domain
|
||||||
|
def filter_side_effect(domain):
|
||||||
|
if domain == mock_domain1:
|
||||||
|
return [MagicMock(user=mock_user1)]
|
||||||
|
elif domain == mock_domain2:
|
||||||
|
return [MagicMock(user=mock_user2)]
|
||||||
|
return []
|
||||||
|
|
||||||
|
mock_user_domain_role_filter.side_effect = filter_side_effect
|
||||||
|
|
||||||
|
email = "invitee@example.com"
|
||||||
|
is_member_of_different_org = False
|
||||||
|
|
||||||
|
# Call the function
|
||||||
|
send_domain_invitation_email(
|
||||||
|
email=email,
|
||||||
|
requestor=mock_requestor,
|
||||||
|
domains=[mock_domain1, mock_domain2],
|
||||||
|
is_member_of_different_org=is_member_of_different_org,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assertions
|
||||||
|
mock_normalize_domains.assert_called_once_with([mock_domain1, mock_domain2])
|
||||||
|
mock_get_requestor_email.assert_called_once_with(mock_requestor, [mock_domain1, mock_domain2])
|
||||||
|
mock_validate_invitation.assert_called_once_with(
|
||||||
|
email, [mock_domain1, mock_domain2], mock_requestor, is_member_of_different_org
|
||||||
|
)
|
||||||
|
mock_send_invitation_email.assert_called_once_with(
|
||||||
|
email, mock_requestor_email, [mock_domain1, mock_domain2], None
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check that domain manager emails were sent for both domains
|
||||||
|
mock_user_domain_role_filter.assert_any_call(domain=mock_domain1)
|
||||||
|
mock_user_domain_role_filter.assert_any_call(domain=mock_domain2)
|
||||||
|
|
||||||
|
mock_send_templated_email.assert_any_call(
|
||||||
|
"emails/domain_manager_notification.txt",
|
||||||
|
"emails/domain_manager_notification_subject.txt",
|
||||||
|
to_address=mock_user1.email,
|
||||||
|
context={
|
||||||
|
"domain": mock_domain1,
|
||||||
|
"requestor_email": mock_requestor_email,
|
||||||
|
"invited_email_address": email,
|
||||||
|
"domain_manager": mock_user1,
|
||||||
|
"date": date.today(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
mock_send_templated_email.assert_any_call(
|
||||||
|
"emails/domain_manager_notification.txt",
|
||||||
|
"emails/domain_manager_notification_subject.txt",
|
||||||
|
to_address=mock_user2.email,
|
||||||
|
context={
|
||||||
|
"domain": mock_domain2,
|
||||||
|
"requestor_email": mock_requestor_email,
|
||||||
|
"invited_email_address": email,
|
||||||
|
"domain_manager": mock_user2,
|
||||||
|
"date": date.today(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify the total number of calls to send_templated_email
|
||||||
|
self.assertEqual(mock_send_templated_email.call_count, 2)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
@patch("registrar.utility.email_invitations.validate_invitation")
|
||||||
|
def test_send_domain_invitation_email_raises_invite_validation_exception(self, mock_validate_invitation):
|
||||||
|
"""Test sending domain invitation email for one domain and assert exception
|
||||||
|
when invite validation fails.
|
||||||
|
"""
|
||||||
|
# Setup
|
||||||
|
mock_validate_invitation.side_effect = ValueError("Validation failed")
|
||||||
|
email = "invitee@example.com"
|
||||||
|
requestor = MagicMock()
|
||||||
|
domain = MagicMock()
|
||||||
|
|
||||||
|
# Call and assert exception
|
||||||
|
with self.assertRaises(ValueError) as context:
|
||||||
|
send_domain_invitation_email(email, requestor, domain, is_member_of_different_org=False)
|
||||||
|
|
||||||
|
self.assertEqual(str(context.exception), "Validation failed")
|
||||||
|
mock_validate_invitation.assert_called_once()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
@patch("registrar.utility.email_invitations.get_requestor_email")
|
||||||
|
def test_send_domain_invitation_email_raises_get_requestor_email_exception(self, mock_get_requestor_email):
|
||||||
|
"""Test sending domain invitation email for one domain and assert exception
|
||||||
|
when get_requestor_email fails.
|
||||||
|
"""
|
||||||
|
# Setup
|
||||||
|
mock_get_requestor_email.side_effect = ValueError("Validation failed")
|
||||||
|
email = "invitee@example.com"
|
||||||
|
requestor = MagicMock()
|
||||||
|
domain = MagicMock()
|
||||||
|
|
||||||
|
# Call and assert exception
|
||||||
|
with self.assertRaises(ValueError) as context:
|
||||||
|
send_domain_invitation_email(email, requestor, domain, is_member_of_different_org=False)
|
||||||
|
|
||||||
|
self.assertEqual(str(context.exception), "Validation failed")
|
||||||
|
mock_get_requestor_email.assert_called_once()
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
@patch("registrar.utility.email_invitations.validate_invitation")
|
||||||
|
@patch("registrar.utility.email_invitations.get_requestor_email")
|
||||||
|
@patch("registrar.utility.email_invitations.send_invitation_email")
|
||||||
|
@patch("registrar.utility.email_invitations.normalize_domains")
|
||||||
|
def test_send_domain_invitation_email_raises_sending_email_exception(
|
||||||
|
self,
|
||||||
|
mock_normalize_domains,
|
||||||
|
mock_send_invitation_email,
|
||||||
|
mock_get_requestor_email,
|
||||||
|
mock_validate_invitation,
|
||||||
|
):
|
||||||
|
"""Test sending domain invitation email for one domain and assert exception
|
||||||
|
when send_invitation_email fails.
|
||||||
|
"""
|
||||||
|
# Setup
|
||||||
|
mock_domain = MagicMock(name="domain1")
|
||||||
|
mock_domain.name = "example.com"
|
||||||
|
mock_normalize_domains.return_value = [mock_domain]
|
||||||
|
|
||||||
|
mock_requestor = MagicMock()
|
||||||
|
mock_requestor_email = "requestor@example.com"
|
||||||
|
mock_get_requestor_email.return_value = mock_requestor_email
|
||||||
|
|
||||||
|
mock_user1 = MagicMock()
|
||||||
|
mock_user1.email = "manager1@example.com"
|
||||||
|
|
||||||
|
email = "invitee@example.com"
|
||||||
|
is_member_of_different_org = False
|
||||||
|
|
||||||
|
mock_send_invitation_email.side_effect = EmailSendingError("Error sending email")
|
||||||
|
|
||||||
|
# Call and assert exception
|
||||||
|
with self.assertRaises(EmailSendingError) as context:
|
||||||
|
send_domain_invitation_email(
|
||||||
|
email=email,
|
||||||
|
requestor=mock_requestor,
|
||||||
|
domains=mock_domain,
|
||||||
|
is_member_of_different_org=is_member_of_different_org,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assertions
|
||||||
|
mock_normalize_domains.assert_called_once_with(mock_domain)
|
||||||
|
mock_get_requestor_email.assert_called_once_with(mock_requestor, [mock_domain])
|
||||||
|
mock_validate_invitation.assert_called_once_with(
|
||||||
|
email, [mock_domain], mock_requestor, is_member_of_different_org
|
||||||
|
)
|
||||||
|
self.assertEqual(str(context.exception), "Error sending email")
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
@patch("registrar.utility.email_invitations.send_emails_to_domain_managers")
|
||||||
|
@patch("registrar.utility.email_invitations.validate_invitation")
|
||||||
|
@patch("registrar.utility.email_invitations.get_requestor_email")
|
||||||
|
@patch("registrar.utility.email_invitations.send_invitation_email")
|
||||||
|
@patch("registrar.utility.email_invitations.normalize_domains")
|
||||||
|
def test_send_domain_invitation_email_manager_emails_send_mail_exception(
|
||||||
|
self,
|
||||||
|
mock_normalize_domains,
|
||||||
|
mock_send_invitation_email,
|
||||||
|
mock_get_requestor_email,
|
||||||
|
mock_validate_invitation,
|
||||||
|
mock_send_domain_manager_emails,
|
||||||
|
):
|
||||||
|
"""Test sending domain invitation email for one domain and assert exception
|
||||||
|
when send_emails_to_domain_managers fails.
|
||||||
|
"""
|
||||||
|
# Setup
|
||||||
|
mock_domain = MagicMock(name="domain1")
|
||||||
|
mock_domain.name = "example.com"
|
||||||
|
mock_normalize_domains.return_value = [mock_domain]
|
||||||
|
|
||||||
|
mock_requestor = MagicMock()
|
||||||
|
mock_requestor_email = "requestor@example.com"
|
||||||
|
mock_get_requestor_email.return_value = mock_requestor_email
|
||||||
|
|
||||||
|
email = "invitee@example.com"
|
||||||
|
is_member_of_different_org = False
|
||||||
|
|
||||||
|
mock_send_domain_manager_emails.side_effect = EmailSendingError("Error sending email")
|
||||||
|
|
||||||
|
# Call and assert exception
|
||||||
|
with self.assertRaises(EmailSendingError) as context:
|
||||||
|
send_domain_invitation_email(
|
||||||
|
email=email,
|
||||||
|
requestor=mock_requestor,
|
||||||
|
domains=mock_domain,
|
||||||
|
is_member_of_different_org=is_member_of_different_org,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assertions
|
||||||
|
mock_normalize_domains.assert_called_once_with(mock_domain)
|
||||||
|
mock_get_requestor_email.assert_called_once_with(mock_requestor, [mock_domain])
|
||||||
|
mock_validate_invitation.assert_called_once_with(
|
||||||
|
email, [mock_domain], mock_requestor, is_member_of_different_org
|
||||||
|
)
|
||||||
|
mock_send_invitation_email.assert_called_once_with(email, mock_requestor_email, [mock_domain], None)
|
||||||
|
self.assertEqual(str(context.exception), "Error sending email")
|
|
@ -2101,6 +2101,10 @@ class TestPatchSuborganizations(MockDbForIndividualTests):
|
||||||
1. Fewest spaces
|
1. Fewest spaces
|
||||||
2. Most leading capitals
|
2. Most leading capitals
|
||||||
"""
|
"""
|
||||||
|
# Delete any other suborganizations defined in the initial test dataset
|
||||||
|
DomainRequest.objects.all().delete()
|
||||||
|
Suborganization.objects.all().delete()
|
||||||
|
|
||||||
Suborganization.objects.create(name="Test Organization ", portfolio=self.portfolio_1)
|
Suborganization.objects.create(name="Test Organization ", portfolio=self.portfolio_1)
|
||||||
Suborganization.objects.create(name="test organization", portfolio=self.portfolio_1)
|
Suborganization.objects.create(name="test organization", portfolio=self.portfolio_1)
|
||||||
Suborganization.objects.create(name="Test Organization", portfolio=self.portfolio_1)
|
Suborganization.objects.create(name="Test Organization", portfolio=self.portfolio_1)
|
||||||
|
@ -2114,6 +2118,10 @@ class TestPatchSuborganizations(MockDbForIndividualTests):
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_hardcoded_record(self):
|
def test_hardcoded_record(self):
|
||||||
"""Tests that our hardcoded records update as we expect them to"""
|
"""Tests that our hardcoded records update as we expect them to"""
|
||||||
|
# Delete any other suborganizations defined in the initial test dataset
|
||||||
|
DomainRequest.objects.all().delete()
|
||||||
|
Suborganization.objects.all().delete()
|
||||||
|
|
||||||
# Create orgs with old and new name formats
|
# Create orgs with old and new name formats
|
||||||
old_name = "USDA/OC"
|
old_name = "USDA/OC"
|
||||||
new_name = "USDA, Office of Communications"
|
new_name = "USDA, Office of Communications"
|
||||||
|
@ -2123,7 +2131,7 @@ class TestPatchSuborganizations(MockDbForIndividualTests):
|
||||||
|
|
||||||
self.run_patch_suborganizations()
|
self.run_patch_suborganizations()
|
||||||
|
|
||||||
# Verify only the new one remains
|
# Verify only the new one of the two remains
|
||||||
self.assertEqual(Suborganization.objects.count(), 1)
|
self.assertEqual(Suborganization.objects.count(), 1)
|
||||||
remaining = Suborganization.objects.first()
|
remaining = Suborganization.objects.first()
|
||||||
self.assertEqual(remaining.name, new_name)
|
self.assertEqual(remaining.name, new_name)
|
||||||
|
|
|
@ -729,6 +729,7 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
# "Submitted at",
|
# "Submitted at",
|
||||||
"Status",
|
"Status",
|
||||||
"Domain type",
|
"Domain type",
|
||||||
|
"Portfolio",
|
||||||
"Federal type",
|
"Federal type",
|
||||||
"Federal agency",
|
"Federal agency",
|
||||||
"Organization name",
|
"Organization name",
|
||||||
|
@ -736,6 +737,10 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
"City",
|
"City",
|
||||||
"State/territory",
|
"State/territory",
|
||||||
"Region",
|
"Region",
|
||||||
|
"Suborganization",
|
||||||
|
"Requested suborg",
|
||||||
|
"Suborg city",
|
||||||
|
"Suborg state/territory",
|
||||||
"Creator first name",
|
"Creator first name",
|
||||||
"Creator last name",
|
"Creator last name",
|
||||||
"Creator email",
|
"Creator email",
|
||||||
|
@ -765,28 +770,30 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
||||||
|
|
||||||
expected_content = (
|
expected_content = (
|
||||||
# Header
|
# Header
|
||||||
"Domain request,Status,Domain type,Federal type,Federal agency,Organization name,Election office,"
|
"Domain request,Status,Domain type,Portfolio,Federal type,Federal agency,Organization name,"
|
||||||
"City,State/territory,Region,Creator first name,Creator last name,Creator email,"
|
"Election office,City,State/territory,Region,Suborganization,Requested suborg,Suborg city,"
|
||||||
|
"Suborg state/territory,Creator first name,Creator last name,Creator email,"
|
||||||
"Creator approved domains count,Creator active requests count,Alternative domains,SO first name,"
|
"Creator approved domains count,Creator active requests count,Alternative domains,SO first name,"
|
||||||
"SO last name,SO email,SO title/role,Request purpose,Request additional details,Other contacts,"
|
"SO last name,SO email,SO title/role,Request purpose,Request additional details,Other contacts,"
|
||||||
"CISA regional representative,Current websites,Investigator\n"
|
"CISA regional representative,Current websites,Investigator\n"
|
||||||
# Content
|
# Content
|
||||||
"city5.gov,Approved,Federal,Executive,,Testorg,N/A,,NY,2,,,,1,0,city1.gov,Testy,Tester,testy@town.com,"
|
"city5.gov,Approved,Federal,No,Executive,,Testorg,N/A,,NY,2,requested_suborg,SanFran,CA,,,,,1,0,"
|
||||||
"Chief Tester,Purpose of the site,There is more,Testy Tester testy2@town.com,,city.com,\n"
|
"city1.gov,Testy,Tester,testy@town.com,Chief Tester,Purpose of the site,There is more,"
|
||||||
"city2.gov,In review,Federal,Executive,Portfolio 1 Federal Agency,,N/A,,NY,2,,,,0,1,city1.gov,,,,,"
|
"Testy Tester testy2@town.com,,city.com,\n"
|
||||||
"Purpose of the site,There is more,Testy Tester testy2@town.com,,city.com,\n"
|
"city2.gov,In review,Federal,Yes,Executive,Portfolio 1 Federal Agency,,N/A,,,2,SubOrg 1,,,,,,,0,"
|
||||||
"city3.gov,Submitted,Federal,Executive,Portfolio 1 Federal Agency,,N/A,,NY,2,,,,0,1,"
|
"1,city1.gov,,,,,Purpose of the site,There is more,Testy Tester testy2@town.com,,city.com,\n"
|
||||||
|
"city3.gov,Submitted,Federal,Yes,Executive,Portfolio 1 Federal Agency,,N/A,,,2,,,,,,,,0,1,"
|
||||||
'"cheeseville.gov, city1.gov, igorville.gov",,,,,Purpose of the site,CISA-first-name CISA-last-name | '
|
'"cheeseville.gov, city1.gov, igorville.gov",,,,,Purpose of the site,CISA-first-name CISA-last-name | '
|
||||||
'There is more,"Meow Tester24 te2@town.com, Testy1232 Tester24 te2@town.com, '
|
'There is more,"Meow Tester24 te2@town.com, Testy1232 Tester24 te2@town.com, '
|
||||||
'Testy Tester testy2@town.com",'
|
'Testy Tester testy2@town.com",'
|
||||||
'test@igorville.com,"city.com, https://www.example2.com, https://www.example.com",\n'
|
'test@igorville.com,"city.com, https://www.example2.com, https://www.example.com",\n'
|
||||||
"city4.gov,Submitted,City,Executive,,Testorg,Yes,,NY,2,,,,0,1,city1.gov,Testy,"
|
"city4.gov,Submitted,City,No,Executive,,Testorg,Yes,,NY,2,,,,,,,,0,1,city1.gov,Testy,"
|
||||||
"Tester,testy@town.com,"
|
"Tester,testy@town.com,"
|
||||||
"Chief Tester,Purpose of the site,CISA-first-name CISA-last-name | There is more,"
|
"Chief Tester,Purpose of the site,CISA-first-name CISA-last-name | There is more,"
|
||||||
"Testy Tester testy2@town.com,"
|
"Testy Tester testy2@town.com,"
|
||||||
"cisaRep@igorville.gov,city.com,\n"
|
"cisaRep@igorville.gov,city.com,\n"
|
||||||
"city6.gov,Submitted,Federal,Executive,Portfolio 1 Federal Agency,,N/A,,NY,2,,,,0,1,city1.gov,,,,,"
|
"city6.gov,Submitted,Federal,Yes,Executive,Portfolio 1 Federal Agency,,N/A,,,2,,,,,,,,0,1,city1.gov,"
|
||||||
"Purpose of the site,CISA-first-name CISA-last-name | There is more,Testy Tester testy2@town.com,"
|
",,,,Purpose of the site,CISA-first-name CISA-last-name | There is more,Testy Tester testy2@town.com,"
|
||||||
"cisaRep@igorville.gov,city.com,\n"
|
"cisaRep@igorville.gov,city.com,\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ from registrar.utility.email import EmailSendingError
|
||||||
from waffle.testutils import override_flag
|
from waffle.testutils import override_flag
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices
|
from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices
|
||||||
from .common import MockEppLib, MockSESClient, create_user # type: ignore
|
from .common import MockEppLib, create_user # type: ignore
|
||||||
from django_webtest import WebTest # type: ignore
|
from django_webtest import WebTest # type: ignore
|
||||||
import boto3_mocking # type: ignore
|
import boto3_mocking # type: ignore
|
||||||
|
|
||||||
|
@ -750,11 +750,12 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
response = self.client.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
response = self.client.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
||||||
self.assertContains(response, "Add a domain manager")
|
self.assertContains(response, "Add a domain manager")
|
||||||
|
|
||||||
@boto3_mocking.patching
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_domain_user_add_form(self):
|
@patch("registrar.views.domain.send_domain_invitation_email")
|
||||||
|
def test_domain_user_add_form(self, mock_send_domain_email):
|
||||||
"""Adding an existing user works."""
|
"""Adding an existing user works."""
|
||||||
get_user_model().objects.get_or_create(email="mayor@igorville.gov")
|
get_user_model().objects.get_or_create(email="mayor@igorville.gov")
|
||||||
|
user = User.objects.filter(email="mayor@igorville.gov").first()
|
||||||
add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
add_page = self.app.get(reverse("domain-users-add", kwargs={"pk": self.domain.id}))
|
||||||
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
|
||||||
|
|
||||||
|
@ -762,11 +763,16 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
|
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
mock_client = MockSESClient()
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
|
||||||
with less_console_noise():
|
|
||||||
success_result = add_page.form.submit()
|
success_result = add_page.form.submit()
|
||||||
|
|
||||||
|
mock_send_domain_email.assert_called_once_with(
|
||||||
|
email="mayor@igorville.gov",
|
||||||
|
requestor=self.user,
|
||||||
|
domains=self.domain,
|
||||||
|
is_member_of_different_org=None,
|
||||||
|
requested_user=user,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(success_result.status_code, 302)
|
self.assertEqual(success_result.status_code, 302)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
success_result["Location"],
|
success_result["Location"],
|
||||||
|
@ -974,13 +980,13 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
success_page = success_result.follow()
|
success_page = success_result.follow()
|
||||||
self.assertContains(success_page, "Failed to send email.")
|
self.assertContains(success_page, "Failed to send email.")
|
||||||
|
|
||||||
@boto3_mocking.patching
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_domain_invitation_created(self):
|
@patch("registrar.views.domain.send_domain_invitation_email")
|
||||||
|
def test_domain_invitation_created(self, mock_send_domain_email):
|
||||||
"""Add user on a nonexistent email creates an invitation.
|
"""Add user on a nonexistent email creates an invitation.
|
||||||
|
|
||||||
Adding a non-existent user sends an email as a side-effect, so mock
|
Adding a non-existent user sends an email as a side-effect, so mock
|
||||||
out the boto3 SES email sending here.
|
out send_domain_invitation_email here.
|
||||||
"""
|
"""
|
||||||
# make sure there is no user with this email
|
# make sure there is no user with this email
|
||||||
email_address = "mayor@igorville.gov"
|
email_address = "mayor@igorville.gov"
|
||||||
|
@ -993,11 +999,12 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
add_page.form["email"] = email_address
|
add_page.form["email"] = email_address
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
mock_client = MockSESClient()
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
|
||||||
with less_console_noise():
|
|
||||||
success_result = add_page.form.submit()
|
success_result = add_page.form.submit()
|
||||||
|
|
||||||
|
mock_send_domain_email.assert_called_once_with(
|
||||||
|
email="mayor@igorville.gov", requestor=self.user, domains=self.domain, is_member_of_different_org=None
|
||||||
|
)
|
||||||
|
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
success_page = success_result.follow()
|
success_page = success_result.follow()
|
||||||
|
|
||||||
|
@ -1005,13 +1012,13 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
self.assertContains(success_page, "Cancel") # link to cancel invitation
|
self.assertContains(success_page, "Cancel") # link to cancel invitation
|
||||||
self.assertTrue(DomainInvitation.objects.filter(email=email_address).exists())
|
self.assertTrue(DomainInvitation.objects.filter(email=email_address).exists())
|
||||||
|
|
||||||
@boto3_mocking.patching
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_domain_invitation_created_for_caps_email(self):
|
@patch("registrar.views.domain.send_domain_invitation_email")
|
||||||
|
def test_domain_invitation_created_for_caps_email(self, mock_send_domain_email):
|
||||||
"""Add user on a nonexistent email with CAPS creates an invitation to lowercase email.
|
"""Add user on a nonexistent email with CAPS creates an invitation to lowercase email.
|
||||||
|
|
||||||
Adding a non-existent user sends an email as a side-effect, so mock
|
Adding a non-existent user sends an email as a side-effect, so mock
|
||||||
out the boto3 SES email sending here.
|
out send_domain_invitation_email here.
|
||||||
"""
|
"""
|
||||||
# make sure there is no user with this email
|
# make sure there is no user with this email
|
||||||
email_address = "mayor@igorville.gov"
|
email_address = "mayor@igorville.gov"
|
||||||
|
@ -1025,10 +1032,12 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
add_page.form["email"] = caps_email_address
|
add_page.form["email"] = caps_email_address
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
|
|
||||||
mock_client = MockSESClient()
|
|
||||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
|
||||||
success_result = add_page.form.submit()
|
success_result = add_page.form.submit()
|
||||||
|
|
||||||
|
mock_send_domain_email.assert_called_once_with(
|
||||||
|
email="mayor@igorville.gov", requestor=self.user, domains=self.domain, is_member_of_different_org=None
|
||||||
|
)
|
||||||
|
|
||||||
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
|
||||||
success_page = success_result.follow()
|
success_page = success_result.follow()
|
||||||
|
|
||||||
|
|
|
@ -1660,6 +1660,27 @@ class DomainRequestExport(BaseExport):
|
||||||
default=F("organization_name"),
|
default=F("organization_name"),
|
||||||
output_field=CharField(),
|
output_field=CharField(),
|
||||||
),
|
),
|
||||||
|
"converted_city": Case(
|
||||||
|
# When portfolio is present, use its value instead
|
||||||
|
When(portfolio__isnull=False, then=F("portfolio__city")),
|
||||||
|
# Otherwise, return the natively assigned value
|
||||||
|
default=F("city"),
|
||||||
|
output_field=CharField(),
|
||||||
|
),
|
||||||
|
"converted_state_territory": Case(
|
||||||
|
# When portfolio is present, use its value instead
|
||||||
|
When(portfolio__isnull=False, then=F("portfolio__state_territory")),
|
||||||
|
# Otherwise, return the natively assigned value
|
||||||
|
default=F("state_territory"),
|
||||||
|
output_field=CharField(),
|
||||||
|
),
|
||||||
|
"converted_suborganization_name": Case(
|
||||||
|
# When sub_organization is present, use its name
|
||||||
|
When(sub_organization__isnull=False, then=F("sub_organization__name")),
|
||||||
|
# Otherwise, return empty string
|
||||||
|
default=Value(""),
|
||||||
|
output_field=CharField(),
|
||||||
|
),
|
||||||
"converted_so_email": Case(
|
"converted_so_email": Case(
|
||||||
# When portfolio is present, use its value instead
|
# When portfolio is present, use its value instead
|
||||||
When(portfolio__isnull=False, then=F("portfolio__senior_official__email")),
|
When(portfolio__isnull=False, then=F("portfolio__senior_official__email")),
|
||||||
|
@ -1786,6 +1807,10 @@ class DomainRequestExport(BaseExport):
|
||||||
status = model.get("status")
|
status = model.get("status")
|
||||||
status_display = DomainRequest.DomainRequestStatus.get_status_label(status) if status else None
|
status_display = DomainRequest.DomainRequestStatus.get_status_label(status) if status else None
|
||||||
|
|
||||||
|
# Handle the portfolio field. Display as a Yes/No
|
||||||
|
portfolio = model.get("portfolio")
|
||||||
|
portfolio_display = "Yes" if portfolio is not None else "No"
|
||||||
|
|
||||||
# Handle the region field.
|
# Handle the region field.
|
||||||
state_territory = model.get("state_territory")
|
state_territory = model.get("state_territory")
|
||||||
region = get_region(state_territory) if state_territory else None
|
region = get_region(state_territory) if state_territory else None
|
||||||
|
@ -1819,6 +1844,7 @@ class DomainRequestExport(BaseExport):
|
||||||
"Election office": human_readable_election_board,
|
"Election office": human_readable_election_board,
|
||||||
"Federal type": human_readable_federal_type,
|
"Federal type": human_readable_federal_type,
|
||||||
"Domain type": human_readable_org_type,
|
"Domain type": human_readable_org_type,
|
||||||
|
"Portfolio": portfolio_display,
|
||||||
"Request additional details": additional_details,
|
"Request additional details": additional_details,
|
||||||
# Annotated fields - passed into the request dict.
|
# Annotated fields - passed into the request dict.
|
||||||
"Creator approved domains count": model.get("creator_approved_domains_count", 0),
|
"Creator approved domains count": model.get("creator_approved_domains_count", 0),
|
||||||
|
@ -1827,6 +1853,10 @@ class DomainRequestExport(BaseExport):
|
||||||
"Other contacts": model.get("all_other_contacts"),
|
"Other contacts": model.get("all_other_contacts"),
|
||||||
"Current websites": model.get("all_current_websites"),
|
"Current websites": model.get("all_current_websites"),
|
||||||
# Untouched FK fields - passed into the request dict.
|
# Untouched FK fields - passed into the request dict.
|
||||||
|
"Suborganization": model.get("converted_suborganization_name"),
|
||||||
|
"Requested suborg": model.get("requested_suborganization"),
|
||||||
|
"Suborg city": model.get("suborganization_city"),
|
||||||
|
"Suborg state/territory": model.get("suborganization_state_territory"),
|
||||||
"Federal agency": model.get("converted_federal_agency"),
|
"Federal agency": model.get("converted_federal_agency"),
|
||||||
"SO first name": model.get("converted_senior_official_first_name"),
|
"SO first name": model.get("converted_senior_official_first_name"),
|
||||||
"SO last name": model.get("converted_senior_official_last_name"),
|
"SO last name": model.get("converted_senior_official_last_name"),
|
||||||
|
@ -1838,8 +1868,8 @@ class DomainRequestExport(BaseExport):
|
||||||
"Investigator": model.get("investigator__email"),
|
"Investigator": model.get("investigator__email"),
|
||||||
# Untouched fields
|
# Untouched fields
|
||||||
"Organization name": model.get("converted_organization_name"),
|
"Organization name": model.get("converted_organization_name"),
|
||||||
"City": model.get("city"),
|
"City": model.get("converted_city"),
|
||||||
"State/territory": model.get("state_territory"),
|
"State/territory": model.get("converted_state_territory"),
|
||||||
"Request purpose": model.get("purpose"),
|
"Request purpose": model.get("purpose"),
|
||||||
"CISA regional representative": model.get("cisa_representative_email"),
|
"CISA regional representative": model.get("cisa_representative_email"),
|
||||||
"Last submitted date": model.get("last_submitted_date"),
|
"Last submitted date": model.get("last_submitted_date"),
|
||||||
|
@ -2006,6 +2036,7 @@ class DomainRequestDataFull(DomainRequestExport):
|
||||||
"Last status update",
|
"Last status update",
|
||||||
"Status",
|
"Status",
|
||||||
"Domain type",
|
"Domain type",
|
||||||
|
"Portfolio",
|
||||||
"Federal type",
|
"Federal type",
|
||||||
"Federal agency",
|
"Federal agency",
|
||||||
"Organization name",
|
"Organization name",
|
||||||
|
@ -2013,6 +2044,10 @@ class DomainRequestDataFull(DomainRequestExport):
|
||||||
"City",
|
"City",
|
||||||
"State/territory",
|
"State/territory",
|
||||||
"Region",
|
"Region",
|
||||||
|
"Suborganization",
|
||||||
|
"Requested suborg",
|
||||||
|
"Suborg city",
|
||||||
|
"Suborg state/territory",
|
||||||
"Creator first name",
|
"Creator first name",
|
||||||
"Creator last name",
|
"Creator last name",
|
||||||
"Creator email",
|
"Creator email",
|
||||||
|
|
20
src/registrar/utility/db_helpers.py
Normal file
20
src/registrar/utility/db_helpers.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from django.db import transaction, IntegrityError
|
||||||
|
from psycopg2 import errorcodes
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def ignore_unique_violation():
|
||||||
|
"""
|
||||||
|
Execute within an atomic transaction so that if a unique constraint violation occurs,
|
||||||
|
the individual transaction is rolled back without invalidating any larger transaction.
|
||||||
|
"""
|
||||||
|
with transaction.atomic():
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
except IntegrityError as e:
|
||||||
|
if e.__cause__.pgcode == errorcodes.UNIQUE_VIOLATION:
|
||||||
|
# roll back to the savepoint, effectively ignoring this transaction
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise e
|
|
@ -1,6 +1,6 @@
|
||||||
|
from datetime import date
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from registrar.models import DomainInvitation
|
from registrar.models import Domain, DomainInvitation, UserDomainRole
|
||||||
from registrar.models.domain import Domain
|
|
||||||
from registrar.utility.errors import (
|
from registrar.utility.errors import (
|
||||||
AlreadyDomainInvitedError,
|
AlreadyDomainInvitedError,
|
||||||
AlreadyDomainManagerError,
|
AlreadyDomainManagerError,
|
||||||
|
@ -41,8 +41,47 @@ def send_domain_invitation_email(
|
||||||
|
|
||||||
send_invitation_email(email, requestor_email, domains, requested_user)
|
send_invitation_email(email, requestor_email, domains, requested_user)
|
||||||
|
|
||||||
|
# send emails to domain managers
|
||||||
|
for domain in domains:
|
||||||
|
send_emails_to_domain_managers(
|
||||||
|
email=email,
|
||||||
|
requestor_email=requestor_email,
|
||||||
|
domain=domain,
|
||||||
|
requested_user=requested_user,
|
||||||
|
)
|
||||||
|
|
||||||
def normalize_domains(domains):
|
|
||||||
|
def send_emails_to_domain_managers(email: str, requestor_email, domain: Domain, requested_user=None):
|
||||||
|
"""
|
||||||
|
Notifies all domain managers of the provided domain of a change
|
||||||
|
Raises:
|
||||||
|
EmailSendingError
|
||||||
|
"""
|
||||||
|
# Get each domain manager from list
|
||||||
|
user_domain_roles = UserDomainRole.objects.filter(domain=domain)
|
||||||
|
for user_domain_role in user_domain_roles:
|
||||||
|
# Send email to each domain manager
|
||||||
|
user = user_domain_role.user
|
||||||
|
try:
|
||||||
|
send_templated_email(
|
||||||
|
"emails/domain_manager_notification.txt",
|
||||||
|
"emails/domain_manager_notification_subject.txt",
|
||||||
|
to_address=user.email,
|
||||||
|
context={
|
||||||
|
"domain": domain,
|
||||||
|
"requestor_email": requestor_email,
|
||||||
|
"invited_email_address": email,
|
||||||
|
"domain_manager": user,
|
||||||
|
"date": date.today(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
except EmailSendingError as err:
|
||||||
|
raise EmailSendingError(
|
||||||
|
f"Could not send email manager notification to {user.email} for domain: {domain.name}"
|
||||||
|
) from err
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_domains(domains: Domain | list[Domain]) -> list[Domain]:
|
||||||
"""Ensures domains is always a list."""
|
"""Ensures domains is always a list."""
|
||||||
return [domains] if isinstance(domains, Domain) else domains
|
return [domains] if isinstance(domains, Domain) else domains
|
||||||
|
|
||||||
|
@ -69,6 +108,8 @@ def validate_invitation(email, domains, requestor, is_member_of_different_org):
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
validate_existing_invitation(email, domain)
|
validate_existing_invitation(email, domain)
|
||||||
|
|
||||||
|
# NOTE: should we also be validating against existing user_domain_roles
|
||||||
|
|
||||||
|
|
||||||
def check_outside_org_membership(email, requestor, is_member_of_different_org):
|
def check_outside_org_membership(email, requestor, is_member_of_different_org):
|
||||||
"""Raise an error if the email belongs to a different organization."""
|
"""Raise an error if the email belongs to a different organization."""
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
import logging
|
import logging
|
||||||
|
from django.db import transaction
|
||||||
|
from django.db.models import ForeignKey, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel
|
||||||
|
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from registrar.models.domain import Domain
|
from registrar.models.domain import Domain
|
||||||
from registrar.models.domain_information import DomainInformation
|
|
||||||
from registrar.models.domain_request import DomainRequest
|
from registrar.models.domain_request import DomainRequest
|
||||||
from registrar.models.portfolio import Portfolio
|
|
||||||
from registrar.models.user import User
|
from registrar.models.user import User
|
||||||
from django.contrib.admin import site
|
from django.contrib.admin import site
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
|
||||||
from registrar.models.user_domain_role import UserDomainRole
|
from registrar.models.user_domain_role import UserDomainRole
|
||||||
from registrar.models.user_portfolio_permission import UserPortfolioPermission
|
from registrar.models.user_portfolio_permission import UserPortfolioPermission
|
||||||
from registrar.models.verified_by_staff import VerifiedByStaff
|
|
||||||
from typing import Any, List
|
from registrar.utility.db_helpers import ignore_unique_violation
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -21,22 +21,8 @@ logger = logging.getLogger(__name__)
|
||||||
class TransferUserView(View):
|
class TransferUserView(View):
|
||||||
"""Transfer user methods that set up the transfer_user template and handle the forms on it."""
|
"""Transfer user methods that set up the transfer_user template and handle the forms on it."""
|
||||||
|
|
||||||
JOINS = [
|
|
||||||
(DomainRequest, "creator"),
|
|
||||||
(DomainInformation, "creator"),
|
|
||||||
(Portfolio, "creator"),
|
|
||||||
(DomainRequest, "investigator"),
|
|
||||||
(UserDomainRole, "user"),
|
|
||||||
(VerifiedByStaff, "requestor"),
|
|
||||||
(UserPortfolioPermission, "user"),
|
|
||||||
]
|
|
||||||
|
|
||||||
# Future-proofing in case joined fields get added on the user model side
|
|
||||||
# This was tested in the first portfolio model iteration and works
|
|
||||||
USER_FIELDS: List[Any] = []
|
|
||||||
|
|
||||||
def get(self, request, user_id):
|
def get(self, request, user_id):
|
||||||
"""current_user referes to the 'source' user where the button that redirects to this view was clicked.
|
"""current_user refers to the 'source' user where the button that redirects to this view was clicked.
|
||||||
other_users exclude current_user and populate a dropdown, selected_user is the selection in the dropdown.
|
other_users exclude current_user and populate a dropdown, selected_user is the selection in the dropdown.
|
||||||
|
|
||||||
This also querries the relevant domains and domain requests, and the admin context needed for the sidenav."""
|
This also querries the relevant domains and domain requests, and the admin context needed for the sidenav."""
|
||||||
|
@ -70,23 +56,18 @@ class TransferUserView(View):
|
||||||
return render(request, "admin/transfer_user.html", context)
|
return render(request, "admin/transfer_user.html", context)
|
||||||
|
|
||||||
def post(self, request, user_id):
|
def post(self, request, user_id):
|
||||||
"""This handles the transfer from selected_user to current_user then deletes selected_user.
|
"""This handles the transfer from selected_user to current_user then deletes selected_user."""
|
||||||
|
|
||||||
NOTE: We have a ticket to refactor this into a more solid lookup for related fields in #2645"""
|
|
||||||
|
|
||||||
current_user = get_object_or_404(User, pk=user_id)
|
current_user = get_object_or_404(User, pk=user_id)
|
||||||
selected_user_id = request.POST.get("selected_user")
|
selected_user_id = request.POST.get("selected_user")
|
||||||
selected_user = get_object_or_404(User, pk=selected_user_id)
|
selected_user = get_object_or_404(User, pk=selected_user_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Make this atomic so that we don't get any partial transfers
|
||||||
|
with transaction.atomic():
|
||||||
change_logs = []
|
change_logs = []
|
||||||
|
|
||||||
# Transfer specific fields
|
# Dynamically handle related fields
|
||||||
self.transfer_user_fields_and_log(selected_user, current_user, change_logs)
|
self.transfer_related_fields_and_log(selected_user, current_user, change_logs)
|
||||||
|
|
||||||
# Perform the updates and log the changes
|
|
||||||
for model_class, field_name in self.JOINS:
|
|
||||||
self.update_joins_and_log(model_class, field_name, selected_user, current_user, change_logs)
|
|
||||||
|
|
||||||
# Success message if any related objects were updated
|
# Success message if any related objects were updated
|
||||||
if change_logs:
|
if change_logs:
|
||||||
|
@ -95,61 +76,102 @@ class TransferUserView(View):
|
||||||
|
|
||||||
selected_user.delete()
|
selected_user.delete()
|
||||||
messages.success(request, f"Deleted {selected_user} {selected_user.username}")
|
messages.success(request, f"Deleted {selected_user} {selected_user.username}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
messages.error(request, f"An error occurred during the transfer: {e}")
|
messages.error(request, f"An error occurred during the transfer: {e}")
|
||||||
|
logger.error(f"An error occurred during the transfer: {e}", exc_info=True)
|
||||||
|
|
||||||
return redirect("admin:registrar_user_change", object_id=user_id)
|
return redirect("admin:registrar_user_change", object_id=user_id)
|
||||||
|
|
||||||
@classmethod
|
def transfer_related_fields_and_log(self, selected_user, current_user, change_logs):
|
||||||
def update_joins_and_log(cls, model_class, field_name, selected_user, current_user, change_logs):
|
|
||||||
"""
|
"""
|
||||||
Helper function to update the user join fields for a given model and log the changes.
|
Dynamically find all related fields to the User model and transfer them from selected_user to current_user.
|
||||||
|
Handles ForeignKey, OneToOneField, ManyToManyField, and ManyToOneRel relationships.
|
||||||
"""
|
"""
|
||||||
|
user_model = User
|
||||||
|
|
||||||
filter_kwargs = {field_name: selected_user}
|
for related_field in user_model._meta.get_fields():
|
||||||
updated_objects = model_class.objects.filter(**filter_kwargs)
|
if related_field.is_relation:
|
||||||
|
# Field objects represent forward relationships
|
||||||
|
if isinstance(related_field, OneToOneField):
|
||||||
|
self._handle_one_to_one(related_field, selected_user, current_user, change_logs)
|
||||||
|
elif isinstance(related_field, ManyToManyField):
|
||||||
|
self._handle_many_to_many(related_field, selected_user, current_user, change_logs)
|
||||||
|
elif isinstance(related_field, ForeignKey):
|
||||||
|
self._handle_foreign_key(related_field, selected_user, current_user, change_logs)
|
||||||
|
# Relationship objects represent reverse relationships
|
||||||
|
elif isinstance(related_field, ManyToOneRel):
|
||||||
|
# ManyToOneRel is a reverse ForeignKey
|
||||||
|
self._handle_foreign_key_reverse(related_field, selected_user, current_user, change_logs)
|
||||||
|
elif isinstance(related_field, OneToOneRel):
|
||||||
|
self._handle_one_to_one_reverse(related_field, selected_user, current_user, change_logs)
|
||||||
|
elif isinstance(related_field, ManyToManyRel):
|
||||||
|
self._handle_many_to_many_reverse(related_field, selected_user, current_user, change_logs)
|
||||||
|
else:
|
||||||
|
logger.error(f"Unknown relationship type for field {related_field}")
|
||||||
|
raise ValueError(f"Unknown relationship type for field {related_field}")
|
||||||
|
|
||||||
for obj in updated_objects:
|
def _handle_foreign_key_reverse(self, related_field: ManyToOneRel, selected_user, current_user, change_logs):
|
||||||
# Check for duplicate UserDomainRole before updating
|
# Handle reverse ForeignKey relationships
|
||||||
if model_class == UserDomainRole:
|
related_manager = getattr(selected_user, related_field.get_accessor_name(), None)
|
||||||
if model_class.objects.filter(user=current_user, domain=obj.domain).exists():
|
if related_manager and related_manager.exists():
|
||||||
continue # Skip the update to avoid a duplicate
|
for related_object in related_manager.all():
|
||||||
|
with ignore_unique_violation():
|
||||||
if model_class == UserPortfolioPermission:
|
setattr(related_object, related_field.field.name, current_user)
|
||||||
if model_class.objects.filter(user=current_user, portfolio=obj.portfolio).exists():
|
related_object.save()
|
||||||
continue # Skip the update to avoid a duplicate
|
self.log_change(related_object, selected_user, current_user, related_field.field.name, change_logs)
|
||||||
|
|
||||||
# Update the field on the object and save it
|
|
||||||
setattr(obj, field_name, current_user)
|
|
||||||
obj.save()
|
|
||||||
|
|
||||||
# Log the change
|
|
||||||
cls.log_change(obj, field_name, selected_user, current_user, change_logs)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def transfer_user_fields_and_log(cls, selected_user, current_user, change_logs):
|
|
||||||
"""
|
|
||||||
Transfers portfolio fields from the selected_user to the current_user.
|
|
||||||
Logs the changes for each transferred field.
|
|
||||||
"""
|
|
||||||
for field in cls.USER_FIELDS:
|
|
||||||
field_value = getattr(selected_user, field, None)
|
|
||||||
|
|
||||||
if field_value:
|
|
||||||
setattr(current_user, field, field_value)
|
|
||||||
cls.log_change(current_user, field, field_value, field_value, change_logs)
|
|
||||||
|
|
||||||
|
def _handle_foreign_key(self, related_field: ForeignKey, selected_user, current_user, change_logs):
|
||||||
|
# Handle ForeignKey relationships
|
||||||
|
related_object = getattr(selected_user, related_field.name, None)
|
||||||
|
if related_object:
|
||||||
|
setattr(current_user, related_field.name, related_object)
|
||||||
current_user.save()
|
current_user.save()
|
||||||
|
self.log_change(related_object, selected_user, current_user, related_field.name, change_logs)
|
||||||
|
|
||||||
|
def _handle_one_to_one(self, related_field: OneToOneField, selected_user, current_user, change_logs):
|
||||||
|
# Handle OneToOne relationship
|
||||||
|
related_object = getattr(selected_user, related_field.name, None)
|
||||||
|
if related_object:
|
||||||
|
with ignore_unique_violation():
|
||||||
|
setattr(current_user, related_field.name, related_object)
|
||||||
|
current_user.save()
|
||||||
|
self.log_change(related_object, selected_user, current_user, related_field.name, change_logs)
|
||||||
|
|
||||||
|
def _handle_many_to_many(self, related_field: ManyToManyField, selected_user, current_user, change_logs):
|
||||||
|
# Handle ManyToMany relationship
|
||||||
|
related_name = related_field.remote_field.name
|
||||||
|
related_manager = getattr(selected_user, related_name, None)
|
||||||
|
if related_manager and related_manager.exists():
|
||||||
|
for instance in related_manager.all():
|
||||||
|
with ignore_unique_violation():
|
||||||
|
getattr(instance, related_name).remove(selected_user)
|
||||||
|
getattr(instance, related_name).add(current_user)
|
||||||
|
self.log_change(instance, selected_user, current_user, related_name, change_logs)
|
||||||
|
|
||||||
|
def _handle_many_to_many_reverse(self, related_field: ManyToManyRel, selected_user, current_user, change_logs):
|
||||||
|
# Handle reverse relationship
|
||||||
|
related_name = related_field.field.name
|
||||||
|
related_manager = getattr(selected_user, related_name, None)
|
||||||
|
if related_manager and related_manager.exists():
|
||||||
|
for instance in related_manager.all():
|
||||||
|
with ignore_unique_violation():
|
||||||
|
getattr(instance, related_name).remove(selected_user)
|
||||||
|
getattr(instance, related_name).add(current_user)
|
||||||
|
self.log_change(instance, selected_user, current_user, related_name, change_logs)
|
||||||
|
|
||||||
|
def _handle_one_to_one_reverse(self, related_field: OneToOneRel, selected_user, current_user, change_logs):
|
||||||
|
# Handle reverse relationship
|
||||||
|
field_name = related_field.get_accessor_name()
|
||||||
|
related_instance = getattr(selected_user, field_name, None)
|
||||||
|
if related_instance:
|
||||||
|
setattr(related_instance, field_name, current_user)
|
||||||
|
related_instance.save()
|
||||||
|
self.log_change(related_instance, selected_user, current_user, field_name, change_logs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def log_change(cls, obj, field_name, field_value, new_value, change_logs):
|
def log_change(cls, obj, selected_user, current_user, field_name, change_logs):
|
||||||
"""Logs the change for a specific field on an object"""
|
log_entry = f"Changed {field_name} from {selected_user} to {current_user} on {obj}"
|
||||||
log_entry = f'Changed {field_name} from "{field_value}" to "{new_value}" on {obj}'
|
|
||||||
|
|
||||||
logger.info(log_entry)
|
logger.info(log_entry)
|
||||||
|
|
||||||
# Collect the related object for the success message
|
|
||||||
change_logs.append(log_entry)
|
change_logs.append(log_entry)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue