More code cleanup

This commit is contained in:
zandercymatics 2023-08-25 08:43:47 -06:00
parent 3d0a519ab0
commit 81e5f5f8bb
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
3 changed files with 11 additions and 21 deletions

View file

@ -167,16 +167,14 @@ class DomainAdmin(ListHeaderAdmin):
request.session["analyst_action"] = "edit" request.session["analyst_action"] = "edit"
# Restricts this action to this domain (pk) only # Restricts this action to this domain (pk) only
request.session["analyst_action_location"] = obj.id request.session["analyst_action_location"] = obj.id
return HttpResponseRedirect(reverse("domain", args=(obj.id,))) return HttpResponseRedirect(reverse("domain", args=(obj.id,)))
return super().response_change(request, obj) return super().response_change(request, obj)
def change_view(self, request, object_id): def change_view(self, request, object_id):
# If the analyst was recently editing # If the analyst was recently editing a domain page,
# delete any associated session values
if "analyst_action" in request.session: if "analyst_action" in request.session:
# delete the session variable
del request.session["analyst_action"] del request.session["analyst_action"]
# delete the associated location
del request.session["analyst_action_location"] del request.session["analyst_action_location"]
return super().change_view(request, object_id) return super().change_view(request, object_id)

View file

@ -654,7 +654,7 @@ class DomainSessionVariableTest(TestCase):
p = "adminpass" p = "adminpass"
self.client.login(username="superuser", password=p) self.client.login(username="superuser", password=p)
dummy_domain_information: DomainInformation = generic_domain_object("information", "session") dummy_domain_information = generic_domain_object("information", "session")
request = self.get_factory_post_edit_domain(dummy_domain_information.domain.pk) request = self.get_factory_post_edit_domain(dummy_domain_information.domain.pk)
self.populate_session_values(request, dummy_domain_information.domain) self.populate_session_values(request, dummy_domain_information.domain)
@ -663,10 +663,11 @@ class DomainSessionVariableTest(TestCase):
def test_session_variables_retain_information(self): def test_session_variables_retain_information(self):
""" Checks to see if session variables retain old information """ """ Checks to see if session variables retain old information """
p = "adminpass" p = "adminpass"
self.client.login(username="superuser", password=p) self.client.login(username="superuser", password=p)
dummy_domain_information_list: [DomainInformation] = multiple_unalphabetical_domain_objects("information") dummy_domain_information_list = multiple_unalphabetical_domain_objects("information")
for item in dummy_domain_information_list: for item in dummy_domain_information_list:
request = self.get_factory_post_edit_domain(item.domain.pk) request = self.get_factory_post_edit_domain(item.domain.pk)
self.populate_session_values(request, item) self.populate_session_values(request, item)
@ -676,22 +677,15 @@ class DomainSessionVariableTest(TestCase):
def test_session_variables_concurrent_requests(self): def test_session_variables_concurrent_requests(self):
""" Simulates two requests at once """ """ Simulates two requests at once """
p = "adminpass" p = "adminpass"
self.client.login(username="superuser", password=p) self.client.login(username="superuser", password=p)
info_first: DomainInformation = generic_domain_object("information", "session") info_first = generic_domain_object("information", "session")
info_second: DomainInformation = generic_domain_object("information", "session2") info_second = generic_domain_object("information", "session2")
request_first = self.factory.post( request_first = self.get_factory_post_edit_domain(info_first.domain.pk)
reverse('admin:registrar_domain_change', args=(info_first.domain.pk,)), request_second = self.get_factory_post_edit_domain(info_second.domain.pk)
{'_edit_domain': 'true'},
follow=True
)
request_second = self.factory.post(
reverse('admin:registrar_domain_change', args=(info_second.domain.pk,)),
{'_edit_domain': 'true'},
follow=True
)
self.populate_session_values(request_first, info_first.domain) self.populate_session_values(request_first, info_first.domain)
self.populate_session_values(request_second, info_second.domain) self.populate_session_values(request_second, info_second.domain)

View file

@ -81,9 +81,7 @@ class DomainOrgNameAddressView(DomainPermissionView, FormMixin):
) )
# Q: Is there a more efficent way to do this? # Q: Is there a more efficent way to do this?
# I don't like repeating code across these functions, # It would be ideal if we didn't have to repeat this.
# But I can't figure out a way to do this without installing
# middleware...
if self.request.user.is_staff or self.request.user.is_superuser: if self.request.user.is_staff or self.request.user.is_superuser:
# if they are editing from an '/admin' redirect, log their actions # if they are editing from an '/admin' redirect, log their actions
self.log_analyst_form_actions( self.log_analyst_form_actions(