diff --git a/src/registrar/admin.py b/src/registrar/admin.py index a0894c203..26002a5e8 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -6,6 +6,7 @@ from django.http.response import HttpResponseRedirect from django.urls import reverse from . import models + logger = logging.getLogger(__name__) @@ -141,8 +142,10 @@ class DomainAdmin(ListHeaderAdmin): readonly_fields = ["state"] def response_change(self, request, obj): - ACTION_BUTTON = "_place_client_hold" - if ACTION_BUTTON in request.POST: + PLACE_HOLD = "_place_client_hold" + EDIT_DOMAIN = "_edit_domain" + if PLACE_HOLD in request.POST: + logger.debug("Hit!") try: obj.place_client_hold() except Exception as err: @@ -157,11 +160,17 @@ class DomainAdmin(ListHeaderAdmin): % obj.name, ) return HttpResponseRedirect(".") - + elif EDIT_DOMAIN in request.POST: + # We want to know, globally, when an edit action occurs + request.session['analyst_action'] = 'edit' + return HttpResponseRedirect(reverse('domain', args=(obj.id,))) return super().response_change(request, obj) - # Sets domain_id as a context var def change_view(self, request, object_id, form_url="", extra_context=None): + if 'analyst_action' in request.session: + # If an analyst performed an edit action, + # delete the session variable + del request.session['analyst_action'] extra_context = extra_context or {} extra_context["domain_id"] = object_id return super().change_view( diff --git a/src/registrar/templates/django/admin/domain_change_form.html b/src/registrar/templates/django/admin/domain_change_form.html index e8eaeaf78..5461cc82a 100644 --- a/src/registrar/templates/django/admin/domain_change_form.html +++ b/src/registrar/templates/django/admin/domain_change_form.html @@ -2,7 +2,9 @@ {% block field_sets %}
- Edit domain + + +
{{ block.super }} diff --git a/src/registrar/templates/domain_base.html b/src/registrar/templates/domain_base.html index ab1b38a83..335c88980 100644 --- a/src/registrar/templates/domain_base.html +++ b/src/registrar/templates/domain_base.html @@ -19,7 +19,7 @@
- {% if not is_analyst_or_superuser or is_original_creator %} + {% if not is_analyst_or_superuser or not analyst_action%} - {% elif is_analyst_or_superuser%} + {% elif is_analyst_or_superuser and analyst_action == 'edit' %} - {# Q: should this be 'Back to .gov admin' or 'Back to manage your domains'? #} + {# Q: For analysts, should this be 'Back to .gov admin' or 'Back to change domain'? #}

- Back to change domain + Back to manage your domains

diff --git a/src/registrar/templates/domain_detail.html b/src/registrar/templates/domain_detail.html index 77ac44d3e..4bae384f5 100644 --- a/src/registrar/templates/domain_detail.html +++ b/src/registrar/templates/domain_detail.html @@ -6,36 +6,20 @@
{% url 'domain-nameservers' pk=domain.id as url %} {% if domain.nameservers %} - {% if is_original_creator %} - {% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' edit_link=url %} - {% else %} - {% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' %} - {% endif %} + {% include "includes/summary_item.html" with title='DNS name servers' value=domain.nameservers list='true' edit_link=url %} {% else %}

DNS name servers

- {% if is_original_creator %}

No DNS name servers have been added yet. Before your domain can be used we’ll need information about your domain name servers.

Add DNS name servers - {% else %} -

No DNS name servers have been added yet.

- {% endif %} {% endif %} {% url 'domain-org-name-address' pk=domain.id as url %} {% include "includes/summary_item.html" with title='Organization name and mailing address' value=domain.domain_info address='true' edit_link=url %} {% url 'domain-authorizing-official' pk=domain.id as url %} - {% if is_original_creator %} - {% include "includes/summary_item.html" with title='Authorizing official' value=domain.domain_info.authorizing_official contact='true' edit_link=url %} - {% else %} - {% include "includes/summary_item.html" with title='Authorizing official' value=domain.domain_info.authorizing_official contact='true'%} - {% endif %} + {% include "includes/summary_item.html" with title='Authorizing official' value=domain.domain_info.authorizing_official contact='true' edit_link=url %} {% url 'domain-your-contact-information' pk=domain.id as url %} - {% if is_original_creator %} - {% include "includes/summary_item.html" with title='Your contact information' value=request.user.contact contact='true' edit_link=url %} - {% else %} - {% include "includes/summary_item.html" with title='Contact information' value=request.user.contact contact='true' edit_link=url %} - {% endif %} + {% include "includes/summary_item.html" with title='Your contact information' value=request.user.contact contact='true' edit_link=url %} {% url 'domain-security-email' pk=domain.id as url %} {% include "includes/summary_item.html" with title='Security email' value=domain.security_email edit_link=url %} diff --git a/src/registrar/templates/domain_org_name_address.html b/src/registrar/templates/domain_org_name_address.html index a9691fc08..587ba4782 100644 --- a/src/registrar/templates/domain_org_name_address.html +++ b/src/registrar/templates/domain_org_name_address.html @@ -8,11 +8,8 @@ {% include "includes/form_errors.html" with form=form %}

Organization name and mailing address

- {% if is_original_creator %} +

The name of your organization will be publicly listed as the domain registrant.

- {% else %} -

The name of the organization will be publicly listed as the domain registrant.

- {% endif %} {% include "includes/required_fields.html" %} diff --git a/src/registrar/templates/domain_sidebar.html b/src/registrar/templates/domain_sidebar.html index e5f9e045a..2260a586d 100644 --- a/src/registrar/templates/domain_sidebar.html +++ b/src/registrar/templates/domain_sidebar.html @@ -11,7 +11,6 @@ Domain overview - {% if is_original_creator %}
  • {% url 'domain-nameservers' pk=domain.id as url %}
  • - {% endif %}
  • {% url 'domain-org-name-address' pk=domain.id as url %}
  • - {% if is_original_creator %}
  • {% url 'domain-authorizing-official' pk=domain.id as url %}
  • - {% endif %}
  • {% url 'domain-your-contact-information' pk=domain.id as url %} - {% if is_original_creator %} - Your contact information - {% else %} - Contact information - {% endif %} + Your contact information
  • diff --git a/src/registrar/views/domain.py b/src/registrar/views/domain.py index ee66ceade..6274767fe 100644 --- a/src/registrar/views/domain.py +++ b/src/registrar/views/domain.py @@ -78,6 +78,28 @@ class DomainOrgNameAddressView(DomainPermissionView, FormMixin): messages.success( self.request, "The organization name and mailing address has been updated." ) + + # If the user is not privileged, don't do any special checks + if not self.request.user.is_staff and not self.request.user.is_superuser: + # superclass has the redirect + return super().form_valid(form) + + # Otherwise, if they are editing from an '/admin' redirect, log their actions + # Q: do we want to be logging on every changed field? + # I could see that becoming spammy log-wise, but it may also be important. + # To do so, I'd likely have to override some of the save() functionality of ModelForm. + if 'analyst_action' in self.request.session: + action = self.request.session['analyst_action'] + + # Template for future expansion, + # in the event we want more logging granularity. + # Could include things such as 'view' + # or 'copy', for instance. + match action: + case 'edit': + if(self.request.user.is_staff): + logger.info("Analyst {} edited {} for {}".format(self.request.user, type(form_class).__name__, self.get_object().domain_info)) + # superclass has the redirect return super().form_valid(form) diff --git a/src/registrar/views/utility/permission_views.py b/src/registrar/views/utility/permission_views.py index b48e0f4f3..30a421ce9 100644 --- a/src/registrar/views/utility/permission_views.py +++ b/src/registrar/views/utility/permission_views.py @@ -37,13 +37,14 @@ class DomainPermissionView(DomainPermission, DetailView, abc.ABC): is_original_creator = DomainInformation.objects.filter( creator_id=self.request.user.id, id=self.kwargs["pk"] ).exists() - - context['primary_key'] = self.kwargs["pk"] - context['is_analyst_or_superuser'] = user.is_superuser or user.is_staff context['is_original_creator'] = is_original_creator - context['is_active_user'] = DomainInformation.objects.filter( - id=self.kwargs["pk"] - ) + context['is_analyst_or_superuser'] = user.is_superuser or user.is_staff + + # Flag to see if an analyst is attempting to make edits + if 'analyst_action' in self.request.session: + context['analyst_action'] = self.request.session['analyst_action'] + # Clear the session variable after use + # del self.request.session['analyst_action'] return context