Repository: cisagov/manage.get.gov

Issue:
You have been added to a domain- email notification for .gov accounts
See PB: https://www.google.com/calendar/event?eid=MmUzc3FkNjZxOWl1aWxiODExZTAxNGRydDZfMjAyMzAzMjJUMTgwMDAwWiBsb2dhbi5tY2RvbmFsZEBnc2EuZ292

**Acceptance Criteria**
- Will be sent for users who have get.gov accounts in addition to ones who do not
- Will be sent for users who are added to one or multiple domains (from the domain management page)
-update unit tests
- The subject line and copy is the same for all users (replace old copy)

CC @neilmb 

- [x] [Draft email](https://docs.google.com/document/d/1HnMdniAB9INphrLwKjiACyNLrenyXy0QFf0-yz4EStI/edit?usp=sharing) @michelle-rago 

-------------

Relates to: #507 


implementation note: 
in form_valid on views/domain.py, it may be as simple as always sending an email_invitation.


Discussion:
ToDo: IS THIS MOSTLY DONE???  (Maybe content?)
ToDo: Split this ticket up
ToDo: Review design side
This is similar to what was done but still needs implementation. In reply to Mohammad's comment above, the development needs to be added for get.gov email addresses and the content will be confirmed in the related ticket. Ticket has been modified and no longer needs to be split up
If you dont have a get.gov account you wont get an email.
@CocoByte are you working on this one?
Clarification Q: Are we replacing the "domain invitation" email subject + text with this new "you’ve been added to a domain" email subject/text? 
tagging @Katherine-Osos or @gabydisarli for the above question


Resolving patch:
diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py
--- a/src/registrar/views/domain.py
+++ b/src/registrar/views/domain.py
@@ -16,6 +16,7 @@
 
 from registrar.models import (
     Domain,
+    DomainInformation,
     DomainInvitation,
     User,
     UserDomainRole,
@@ -335,6 +336,11 @@ def _make_invitation(self, email_address):
             )
         else:
             # created a new invitation in the database, so send an email
+            domaininfo = DomainInformation.objects.filter(domain=self.object)
+            first = domaininfo.first().creator.first_name
+            last = domaininfo.first().creator.last_name
+            full_name = f"{first} {last}"
+
             try:
                 send_templated_email(
                     "emails/domain_invitation.txt",
@@ -343,6 +349,7 @@ def _make_invitation(self, email_address):
                     context={
                         "domain_url": self._domain_abs_url(),
                         "domain": self.object,
+                        "full_name": full_name,
                     },
                 )
             except EmailSendingError:


Test patch:
diff --git a/src/registrar/tests/common.py b/src/registrar/tests/common.py
--- a/src/registrar/tests/common.py
+++ b/src/registrar/tests/common.py
@@ -457,6 +457,7 @@ def completed_application(
     has_anything_else=True,
     status=DomainApplication.STARTED,
     user=False,
+    name="city.gov",
 ):
     """A completed domain application."""
     if not user:
@@ -468,7 +469,7 @@ def completed_application(
         email="testy@town.com",
         phone="(555) 555 5555",
     )
-    domain, _ = DraftDomain.objects.get_or_create(name="city.gov")
+    domain, _ = DraftDomain.objects.get_or_create(name=name)
     alt, _ = Website.objects.get_or_create(website="city1.gov")
     current, _ = Website.objects.get_or_create(website="city.com")
     you, _ = Contact.objects.get_or_create(
diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py
--- a/src/registrar/tests/test_views.py
+++ b/src/registrar/tests/test_views.py
@@ -1079,6 +1079,7 @@ def tearDown(self):
             self.domain_information.delete()
             if hasattr(self.domain, "contacts"):
                 self.domain.contacts.all().delete()
+            DomainApplication.objects.all().delete()
             self.domain.delete()
             self.role.delete()
         except ValueError:  # pass if already deleted
@@ -1197,6 +1198,10 @@ def test_domain_invitation_created(self):
         EMAIL = "mayor@igorville.gov"
         User.objects.filter(email=EMAIL).delete()
 
+        self.domain_information, _ = DomainInformation.objects.get_or_create(
+            creator=self.user, domain=self.domain
+        )
+
         add_page = self.app.get(
             reverse("domain-users-add", kwargs={"pk": self.domain.id})
         )
@@ -1218,6 +1223,10 @@ def test_domain_invitation_email_sent(self):
         EMAIL = "mayor@igorville.gov"
         User.objects.filter(email=EMAIL).delete()
 
+        self.domain_information, _ = DomainInformation.objects.get_or_create(
+            creator=self.user, domain=self.domain
+        )
+
         mock_client = MagicMock()
         mock_client_instance = mock_client.return_value
         with boto3_mocking.clients.handler_for("sesv2", mock_client):
@@ -1270,6 +1279,11 @@ def test_domain_invitation_flow(self):
         add_page = self.app.get(
             reverse("domain-users-add", kwargs={"pk": self.domain.id})
         )
+
+        self.domain_information, _ = DomainInformation.objects.get_or_create(
+            creator=self.user, domain=self.domain
+        )
+
         session_id = self.app.cookies[settings.SESSION_COOKIE_NAME]
         add_page.form["email"] = EMAIL
         self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)