Linter, reordered logic

This commit is contained in:
zandercymatics 2023-08-24 11:38:46 -06:00
parent a2572d0c73
commit 376aa30e1e
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 24 additions and 21 deletions

View file

@ -191,7 +191,8 @@ class DomainAdmin(ListHeaderAdmin):
)
def has_change_permission(self, request, obj=None):
# Fixes a bug wherein users which are only is_staff can access 'change' when GET,
# Fixes a bug wherein users which are only is_staff
# can access 'change' when GET,
# but cannot access this page when it is a request of type POST.
if request.user.is_staff:
return True

View file

@ -6,7 +6,7 @@
{% block content %}
<div class="grid-container">
<div class="grid-row">
{% if not is_analyst_or_superuser or not analyst_action %}
{% if not is_analyst_or_superuser or not analyst_action or analyst_action_location != domain.pk %}
<p class="font-body-md margin-top-0 margin-bottom-2
text-primary-darker text-semibold"
>
@ -21,18 +21,8 @@
<div class="tablet:grid-col-9">
<main id="main-content" class="grid-container">
{% if not is_analyst_or_superuser or not analyst_action %}
<a href="{% url 'home' %}" class="breadcrumb__back">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use>
</svg>
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
Back to manage your domains
</p>
</a>
{% elif is_analyst_or_superuser and analyst_action == 'edit' %}
{% if is_analyst_or_superuser and analyst_action == 'edit' and analyst_action_location == domain.pk %}
<div class="usa-alert usa-alert--warning">
<div class="usa-alert__body">
<h4 class="usa-alert__heading larger-font-sizing ">Attention!</h4>
@ -41,6 +31,16 @@
</p>
</div>
</div>
{% else %}
<a href="{% url 'home' %}" class="breadcrumb__back">
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="{% static 'img/sprite.svg' %}#arrow_back"></use>
</svg>
<p class="margin-left-05 margin-top-0 margin-bottom-0 line-height-sans-1">
Back to manage your domains
</p>
</a>
{% endif %}
{# messages block is under the back breadcrumb link #}
{% if messages %}

View file

@ -58,10 +58,10 @@ class DomainPermission(PermissionsLoginMixin):
except DomainInformation.DoesNotExist:
# Q: While testing, I saw that, application-wide, if you go to a domain
# that does not exist (i.e: https://getgov-staging.app.cloud.gov/domain/73333),
# the page throws a 403 error,
# instead of a 404. This fixes that behaviour,
# but do we want it to throw a 403 instead?
# that does not exist, for example,
# https://getgov-staging.app.cloud.gov/domain/73333,
# the page throws a 403 error, instead of a 404.
# This fixes that behaviour, but do we want it to throw a 403 instead?
# Basically, should this be logger.debug()?
raise Http404()

View file

@ -5,7 +5,7 @@ import abc # abstract base class
from django.views.generic import DetailView, DeleteView
from registrar.models import Domain, DomainApplication, DomainInvitation
from registrar.models.domain_information import DomainInformation
from .mixins import (
DomainPermission,
@ -35,11 +35,13 @@ class DomainPermissionView(DomainPermission, DetailView, abc.ABC):
context = super().get_context_data(**kwargs)
user = self.request.user
context["is_analyst_or_superuser"] = user.is_superuser or user.is_staff
context["is_analyst_or_superuser"] = user.is_staff or user.is_superuser
# 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"]
context["analyst_action_location"] = self.request.session["analyst_action_location"]
# Stored in a variable for the linter
action = "analyst_action"
context[action] = self.request.session[action]
context[f"{action}_location"] = self.request.session[f"{action}_location"]
return context