Repository: cisagov/manage.get.gov

Issue:
Unable to access Manage Domain for a transition domain
### Current Behavior

Logged in as a full access user I manually created a domain that just had domain and domain info, but no application. When going to its Manage Domain page via the django admin domain object I got a 500 error and the logs showed an Exception was thrown.  This was to simulate a transition domain and looks like this bug would affect analysts too. 

### Expected Behavior

Expected as I am full access to not see a 500 error going to the manage domain page. Nothing should have crashed.

### Steps to Reproduce

1. Log in as full access or admin user
2. Create a domain with a domain information object 
3. click the manage domain button on the Domain object
4. see a 500 error

### Environment

_No response_

### Additional Context

![image](https://github.com/cisagov/manage.get.gov/assets/109625347/19dccac5-1127-4848-8a2b-0302befe7420)
This line "if requested_domain.domain_application.status not in valid_domain_statuses" in the error message above is the cause of the problem. it should not be checking domain application and needs to check domain information instead. 

### Issue Links

_No response_


Discussion:

Resolving patch:
diff --git a/src/registrar/views/utility/mixins.py b/src/registrar/views/utility/mixins.py
--- a/src/registrar/views/utility/mixins.py
+++ b/src/registrar/views/utility/mixins.py
@@ -100,7 +100,15 @@ def can_access_other_user_domains(self, pk):
         if DomainInformation.objects.filter(id=pk).exists():
             requested_domain = DomainInformation.objects.get(id=pk)
 
-        if requested_domain.domain_application.status not in valid_domain_statuses:
+        # if no domain information or application exist, the user
+        # should be able to manage the domain; however, if domain information
+        # and domain application exist, and application is not in valid status,
+        # user should not be able to manage domain
+        if (
+            requested_domain
+            and requested_domain.domain_application
+            and requested_domain.domain_application.status not in valid_domain_statuses
+        ):
             return False
 
         # Valid session keys exist,


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
@@ -453,7 +453,7 @@ def create_user():
     p = "userpass"
     user = User.objects.create_user(
         username="staffuser",
-        email="user@example.com",
+        email="staff@example.com",
         is_staff=True,
         password=p,
     )
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
@@ -5,7 +5,7 @@
 from django.test import Client, TestCase
 from django.urls import reverse
 from django.contrib.auth import get_user_model
-from .common import MockEppLib, completed_application  # type: ignore
+from .common import MockEppLib, completed_application, create_user  # type: ignore
 
 from django_webtest import WebTest  # type: ignore
 import boto3_mocking  # type: ignore
@@ -1105,6 +1105,9 @@ def setUp(self):
         self.domain_just_nameserver, _ = Domain.objects.get_or_create(
             name="justnameserver.com"
         )
+        self.domain_no_information, _ = Domain.objects.get_or_create(
+            name="noinformation.gov"
+        )
 
         self.domain_dsdata, _ = Domain.objects.get_or_create(name="dnssec-dsdata.gov")
         self.domain_multdsdata, _ = Domain.objects.get_or_create(
@@ -1278,6 +1281,29 @@ def test_domain_see_nameserver_and_ip(self):
         self.assertContains(detail_page, "(1.2.3.4,")
         self.assertContains(detail_page, "2.3.4.5)")
 
+    def test_domain_with_no_information_or_application(self):
+        """Test that domain management page returns 200 and displays error
+        when no domain information or domain application exist"""
+        # have to use staff user for this test
+        staff_user = create_user()
+        # staff_user.save()
+        self.client.force_login(staff_user)
+
+        # need to set the analyst_action and analyst_action_location
+        # in the session to emulate user clicking Manage Domain
+        # in the admin interface
+        session = self.client.session
+        session["analyst_action"] = "foo"
+        session["analyst_action_location"] = self.domain_no_information.id
+        session.save()
+
+        detail_page = self.client.get(
+            reverse("domain", kwargs={"pk": self.domain_no_information.id})
+        )
+
+        self.assertContains(detail_page, "noinformation.gov")
+        self.assertContains(detail_page, "Domain missing domain information")
+
 
 class TestDomainManagers(TestDomainOverview):
     def test_domain_managers(self):