mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 09:43:33 +02:00
Fix issues with org_user_status global context and logo_clickable profile context
This commit is contained in:
parent
a7c29f4d21
commit
dcb63d1947
11 changed files with 132 additions and 127 deletions
|
@ -429,6 +429,10 @@ class ViewsTest(TestCase):
|
||||||
# Create a mock request
|
# Create a mock request
|
||||||
request = self.factory.get("/some-url")
|
request = self.factory.get("/some-url")
|
||||||
request.session = {"acr_value": ""}
|
request.session = {"acr_value": ""}
|
||||||
|
# Mock user and its attributes
|
||||||
|
mock_user = MagicMock()
|
||||||
|
mock_user.is_authenticated = True
|
||||||
|
request.user = mock_user
|
||||||
# Ensure that the CLIENT instance used in login_callback is the mock
|
# Ensure that the CLIENT instance used in login_callback is the mock
|
||||||
# patch _requires_step_up_auth to return False
|
# patch _requires_step_up_auth to return False
|
||||||
with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch(
|
with patch("djangooidc.views._requires_step_up_auth", return_value=False), patch(
|
||||||
|
|
|
@ -6,5 +6,4 @@
|
||||||
|
|
||||||
.usa-identifier__logo {
|
.usa-identifier__logo {
|
||||||
height: units(7);
|
height: units(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,11 +135,7 @@
|
||||||
|
|
||||||
<div class="usa-overlay"></div>
|
<div class="usa-overlay"></div>
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% if not is_org_user %}
|
{% include "includes/header_selector.html" with logo_clickable=True %}
|
||||||
{% include "includes/header_basic.html" %}
|
|
||||||
{% else %}
|
|
||||||
{% include "includes/header_extended.html" %}
|
|
||||||
{% endif %}
|
|
||||||
{% endblock header %}
|
{% endblock header %}
|
||||||
|
|
||||||
{% block wrapper %}
|
{% block wrapper %}
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% block messages %}
|
{% block messages %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<p>test</p>
|
|
||||||
<ul class="messages">
|
<ul class="messages">
|
||||||
{% for message in messages %}
|
{% for message in messages %}
|
||||||
<li {% if message.tags %} class="{{ message.tags }}" {% endif %}>
|
<li {% if message.tags %} class="{{ message.tags }}" {% endif %}>
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
{% block title %} Finish setting up your profile | {% endblock %}
|
{% block title %} Finish setting up your profile | {% endblock %}
|
||||||
|
|
||||||
{# Disable the redirect #}
|
{# Disable the redirect #}
|
||||||
{% block logo %}
|
{% block header %}
|
||||||
{% include "includes/gov_extended_logo.html" with logo_clickable=user_finished_setup %}
|
{% include "includes/header_selector.html" with logo_clickable=user_finished_setup %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{# Add the new form #}
|
{# Add the new form #}
|
||||||
|
|
|
@ -1,42 +1,39 @@
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
<header class="usa-header usa-header--basic">
|
<header class="usa-header usa-header--basic">
|
||||||
<div class="usa-nav-container">
|
<div class="usa-nav-container">
|
||||||
<div class="usa-navbar">
|
<div class="usa-navbar">
|
||||||
{% block logo %}
|
{% include "includes/gov_extended_logo.html" with logo_clickable=logo_clickable %}
|
||||||
{% include "includes/gov_extended_logo.html" with logo_clickable=True %}
|
<button type="button" class="usa-menu-btn">Menu</button>
|
||||||
{% endblock %}
|
|
||||||
<button type="button" class="usa-menu-btn">Menu</button>
|
|
||||||
</div>
|
|
||||||
{% block usa_nav %}
|
|
||||||
<nav class="usa-nav" aria-label="Primary navigation">
|
|
||||||
<button type="button" class="usa-nav__close">
|
|
||||||
<img src="{%static 'img/usa-icons/close.svg'%}" role="img" alt="Close" />
|
|
||||||
</button>
|
|
||||||
<ul class="usa-nav__primary usa-accordion">
|
|
||||||
<li class="usa-nav__primary-item">
|
|
||||||
{% if user.is_authenticated %}
|
|
||||||
<span class="usa-nav__username ellipsis">{{ user.email }}</span>
|
|
||||||
</li>
|
|
||||||
{% if has_profile_feature_flag %}
|
|
||||||
<li class="usa-nav__primary-item">
|
|
||||||
{% url 'user-profile' as user_profile_url %}
|
|
||||||
{% url 'finish-user-profile-setup' as finish_setup_url %}
|
|
||||||
<a class="usa-nav-link {% if request.path == user_profile_url or request.path == finish_setup_url %}usa-current{% endif %}" href="{{ user_profile_url }}">
|
|
||||||
<span class="text-primary">Your profile</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
<li class="usa-nav__primary-item">
|
|
||||||
<a href="{% url 'logout' %}"><span class="text-primary">Sign out</span></a>
|
|
||||||
{% else %}
|
|
||||||
<a href="{% url 'login' %}"><span>Sign in</span></a>
|
|
||||||
{% endif %}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
{% block usa_nav_secondary %}{% endblock %}
|
|
||||||
{% endblock %}
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
{% block usa_nav %}
|
||||||
|
<nav class="usa-nav" aria-label="Primary navigation">
|
||||||
|
<button type="button" class="usa-nav__close">
|
||||||
|
<img src="{%static 'img/usa-icons/close.svg'%}" role="img" alt="Close" />
|
||||||
|
</button>
|
||||||
|
<ul class="usa-nav__primary usa-accordion">
|
||||||
|
<li class="usa-nav__primary-item">
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<span class="usa-nav__username ellipsis">{{ user.email }}</span>
|
||||||
|
</li>
|
||||||
|
{% if has_profile_feature_flag %}
|
||||||
|
<li class="usa-nav__primary-item">
|
||||||
|
{% url 'user-profile' as user_profile_url %}
|
||||||
|
{% url 'finish-user-profile-setup' as finish_setup_url %}
|
||||||
|
<a class="usa-nav-link {% if request.path == user_profile_url or request.path == finish_setup_url %}usa-current{% endif %}" href="{{ user_profile_url }}">
|
||||||
|
<span class="text-primary">Your profile</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
<li class="usa-nav__primary-item">
|
||||||
|
<a href="{% url 'logout' %}"><span class="text-primary">Sign out</span></a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'login' %}"><span>Sign in</span></a>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
{% block usa_nav_secondary %}{% endblock %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
<header class="usa-header usa-header--extended">
|
<header class="usa-header usa-header--extended">
|
||||||
<div class="usa-navbar">
|
<div class="usa-navbar">
|
||||||
{% block logo %}
|
{% include "includes/gov_extended_logo.html" with logo_clickable=logo_clickable %}
|
||||||
{% include "includes/gov_extended_logo.html" with logo_clickable=True %}
|
|
||||||
{% endblock %}
|
|
||||||
<button type="button" class="usa-menu-btn">Menu</button>
|
<button type="button" class="usa-menu-btn">Menu</button>
|
||||||
</div>
|
</div>
|
||||||
{% block usa_nav %}
|
{% block usa_nav %}
|
||||||
|
@ -71,5 +69,5 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</header>
|
</header>
|
||||||
|
|
5
src/registrar/templates/includes/header_selector.html
Normal file
5
src/registrar/templates/includes/header_selector.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{% if not is_org_user %}
|
||||||
|
{% include "includes/header_basic.html" with logo_clickable=logo_clickable %}
|
||||||
|
{% else %}
|
||||||
|
{% include "includes/header_extended.html" with logo_clickable=logo_clickable %}
|
||||||
|
{% endif %}
|
|
@ -36,6 +36,4 @@
|
||||||
|
|
||||||
{% block content_bottom %}{% endblock %}
|
{% block content_bottom %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock wrapper %}
|
{% endblock wrapper %}
|
||||||
|
|
|
@ -6,8 +6,8 @@ Edit your User Profile |
|
||||||
{% load static url_helpers %}
|
{% load static url_helpers %}
|
||||||
|
|
||||||
{# Disable the redirect #}
|
{# Disable the redirect #}
|
||||||
{% block logo %}
|
{% block header %}
|
||||||
{% include "includes/gov_extended_logo.html" with logo_clickable=user_finished_setup %}
|
{% include "includes/header_selector.html" with logo_clickable=user_finished_setup %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
|
@ -17,82 +17,15 @@ def get_domains_json(request):
|
||||||
objects = Domain.objects.filter(id__in=domain_ids)
|
objects = Domain.objects.filter(id__in=domain_ids)
|
||||||
unfiltered_total = objects.count()
|
unfiltered_total = objects.count()
|
||||||
|
|
||||||
# Handle sorting
|
objects = apply_search(objects, request)
|
||||||
sort_by = request.GET.get("sort_by", "id") # Default to 'id'
|
objects = apply_state_filter(objects, request)
|
||||||
order = request.GET.get("order", "asc") # Default to 'asc'
|
objects = apply_sorting(objects, request)
|
||||||
|
|
||||||
# Handle search term
|
|
||||||
search_term = request.GET.get("search_term")
|
|
||||||
if search_term:
|
|
||||||
objects = objects.filter(Q(name__icontains=search_term))
|
|
||||||
|
|
||||||
# Handle state
|
|
||||||
status_param = request.GET.get("status")
|
|
||||||
if status_param:
|
|
||||||
status_list = status_param.split(",")
|
|
||||||
|
|
||||||
# if unknown is in status_list, append 'dns needed' since both
|
|
||||||
# unknown and dns needed display as DNS Needed, and both are
|
|
||||||
# searchable via state parameter of 'unknown'
|
|
||||||
if "unknown" in status_list:
|
|
||||||
status_list.append("dns needed")
|
|
||||||
|
|
||||||
# Split the status list into normal states and custom states
|
|
||||||
normal_states = [state for state in status_list if state in Domain.State.values]
|
|
||||||
custom_states = [state for state in status_list if state == "expired"]
|
|
||||||
|
|
||||||
# Construct Q objects for normal states that can be queried through ORM
|
|
||||||
state_query = Q()
|
|
||||||
if normal_states:
|
|
||||||
state_query |= Q(state__in=normal_states)
|
|
||||||
|
|
||||||
# Handle custom states in Python, as expired can not be queried through ORM
|
|
||||||
if "expired" in custom_states:
|
|
||||||
expired_domain_ids = [domain.id for domain in objects if domain.state_display() == "Expired"]
|
|
||||||
state_query |= Q(id__in=expired_domain_ids)
|
|
||||||
|
|
||||||
# Apply the combined query
|
|
||||||
objects = objects.filter(state_query)
|
|
||||||
|
|
||||||
# If there are filtered states, and expired is not one of them, domains with
|
|
||||||
# state_display of 'Expired' must be removed
|
|
||||||
if "expired" not in custom_states:
|
|
||||||
expired_domain_ids = [domain.id for domain in objects if domain.state_display() == "Expired"]
|
|
||||||
objects = objects.exclude(id__in=expired_domain_ids)
|
|
||||||
|
|
||||||
if sort_by == "state_display":
|
|
||||||
# Fetch the objects and sort them in Python
|
|
||||||
objects = list(objects) # Evaluate queryset to a list
|
|
||||||
objects.sort(key=lambda domain: domain.state_display(), reverse=(order == "desc"))
|
|
||||||
else:
|
|
||||||
if order == "desc":
|
|
||||||
sort_by = f"-{sort_by}"
|
|
||||||
objects = objects.order_by(sort_by)
|
|
||||||
|
|
||||||
paginator = Paginator(objects, 10)
|
paginator = Paginator(objects, 10)
|
||||||
page_number = request.GET.get("page")
|
page_number = request.GET.get("page")
|
||||||
page_obj = paginator.get_page(page_number)
|
page_obj = paginator.get_page(page_number)
|
||||||
|
|
||||||
# Convert objects to JSON-serializable format
|
domains = [serialize_domain(domain) for domain in page_obj.object_list]
|
||||||
domains = [
|
|
||||||
{
|
|
||||||
"id": domain.id,
|
|
||||||
"name": domain.name,
|
|
||||||
"expiration_date": domain.expiration_date,
|
|
||||||
"state": domain.state,
|
|
||||||
"state_display": domain.state_display(),
|
|
||||||
"get_state_help_text": domain.get_state_help_text(),
|
|
||||||
"action_url": reverse("domain", kwargs={"pk": domain.id}),
|
|
||||||
"action_label": ("View" if domain.state in [Domain.State.DELETED, Domain.State.ON_HOLD] else "Manage"),
|
|
||||||
"svg_icon": ("visibility" if domain.state in [Domain.State.DELETED, Domain.State.ON_HOLD] else "settings"),
|
|
||||||
"suborganization": (
|
|
||||||
domain.domain_info.sub_organization.name
|
|
||||||
if domain.domain_info and domain.domain_info.sub_organization
|
|
||||||
else None
|
|
||||||
),
|
|
||||||
}
|
|
||||||
for domain in page_obj.object_list
|
|
||||||
]
|
|
||||||
|
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{
|
{
|
||||||
|
@ -105,3 +38,79 @@ def get_domains_json(request):
|
||||||
"unfiltered_total": unfiltered_total,
|
"unfiltered_total": unfiltered_total,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def apply_search(queryset, request):
|
||||||
|
search_term = request.GET.get("search_term")
|
||||||
|
if search_term:
|
||||||
|
queryset = queryset.filter(Q(name__icontains=search_term))
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
def apply_state_filter(queryset, request):
|
||||||
|
status_param = request.GET.get("status")
|
||||||
|
if status_param:
|
||||||
|
status_list = status_param.split(",")
|
||||||
|
# if unknown is in status_list, append 'dns needed' since both
|
||||||
|
# unknown and dns needed display as DNS Needed, and both are
|
||||||
|
# searchable via state parameter of 'unknown'
|
||||||
|
if "unknown" in status_list:
|
||||||
|
status_list.append("dns needed")
|
||||||
|
# Split the status list into normal states and custom states
|
||||||
|
normal_states = [state for state in status_list if state in Domain.State.values]
|
||||||
|
custom_states = [state for state in status_list if state == "expired"]
|
||||||
|
# Construct Q objects for normal states that can be queried through ORM
|
||||||
|
state_query = Q()
|
||||||
|
if normal_states:
|
||||||
|
state_query |= Q(state__in=normal_states)
|
||||||
|
# Handle custom states in Python, as expired can not be queried through ORM
|
||||||
|
if "expired" in custom_states:
|
||||||
|
expired_domain_ids = [domain.id for domain in queryset if domain.state_display() == "Expired"]
|
||||||
|
state_query |= Q(id__in=expired_domain_ids)
|
||||||
|
# Apply the combined query
|
||||||
|
queryset = queryset.filter(state_query)
|
||||||
|
# If there are filtered states, and expired is not one of them, domains with
|
||||||
|
# state_display of 'Expired' must be removed
|
||||||
|
if "expired" not in custom_states:
|
||||||
|
expired_domain_ids = [domain.id for domain in queryset if domain.state_display() == "Expired"]
|
||||||
|
queryset = queryset.exclude(id__in=expired_domain_ids)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
|
def apply_sorting(queryset, request):
|
||||||
|
sort_by = request.GET.get("sort_by", "id")
|
||||||
|
order = request.GET.get("order", "asc")
|
||||||
|
if sort_by == "state_display":
|
||||||
|
objects = list(queryset)
|
||||||
|
objects.sort(key=lambda domain: domain.state_display(), reverse=(order == "desc"))
|
||||||
|
return objects
|
||||||
|
else:
|
||||||
|
if order == "desc":
|
||||||
|
sort_by = f"-{sort_by}"
|
||||||
|
return queryset.order_by(sort_by)
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_domain(domain):
|
||||||
|
suborganization_name = None
|
||||||
|
try:
|
||||||
|
domain_info = domain.domain_info
|
||||||
|
if domain_info:
|
||||||
|
suborganization = domain_info.sub_organization
|
||||||
|
if suborganization:
|
||||||
|
suborganization_name = suborganization.name
|
||||||
|
except Domain.domain_info.RelatedObjectDoesNotExist:
|
||||||
|
domain_info = None
|
||||||
|
|
||||||
|
return {
|
||||||
|
"id": domain.id,
|
||||||
|
"name": domain.name,
|
||||||
|
"expiration_date": domain.expiration_date,
|
||||||
|
"state": domain.state,
|
||||||
|
"state_display": domain.state_display(),
|
||||||
|
"get_state_help_text": domain.get_state_help_text(),
|
||||||
|
"action_url": reverse("domain", kwargs={"pk": domain.id}),
|
||||||
|
"action_label": ("View" if domain.state in [Domain.State.DELETED, Domain.State.ON_HOLD] else "Manage"),
|
||||||
|
"svg_icon": ("visibility" if domain.state in [Domain.State.DELETED, Domain.State.ON_HOLD] else "settings"),
|
||||||
|
"suborganization": suborganization_name,
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue