Prettier DRF pages when using trusted proxy (#15579) (#6717)

This is a rather hacky, but fixes the DRF pages when going through a
trusted proxy.

Notably: This is meant to primarily fix the DRF pages on downstream
builds while leaving the upstream to function as-is.

When using a trusted proxy, the DRF login and logout endpoints now
redirect to the Platform login page (which respects ?next) and logout
endpoint respectively.

The CSS and JS is inlined because the trusted proxy might only proxy
to /api/ and not /static/ which is a harder problem to solve.

Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
Rick Elrod
2024-10-16 19:58:01 +02:00
committed by GitHub
parent d5388b3c56
commit 4820b084c1
3 changed files with 45 additions and 4 deletions

View File

@@ -1,11 +1,19 @@
{% extends 'rest_framework/base.html' %}
{% load i18n static %}
{% load i18n static ansible_base.lib.templatetags.requests ansible_base.lib.templatetags.util %}
{% block title %}{{ name }} &middot; {% trans 'AWX REST API' %}{% endblock %}
{% block bootstrap_theme %}
{% is_proxied_request as proxied %}
<link rel="stylesheet" type="text/css" href="{% static 'rest_framework/css/bootstrap.min.css' %}" />
{% if proxied %}
<style>
{# inline_file from DAB #}
{% inline_file "static/api/api.css" True %}
</style>
{% else %}
<link rel="stylesheet" type="text/css" href="{% static 'api/api.css' %}?v={{tower_version}}" />
{% endif %}
{% endblock %}
{% block style %}
@@ -24,7 +32,6 @@
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'api:api_root_view' %}">
<img class="logo" src="{% static 'media/logo-header.svg' %}">
<span>{% trans 'REST API' %}</span>
</a>
<a class="navbar-title" href="{{ request.get_full_path }}">
@@ -74,5 +81,14 @@
<a class="toggle-description js-tooltip" href="#" title="Show/Hide Description"><span class="glyphicon glyphicon-question-sign"></span></a>
</div>
{{ block.super }}
{% is_proxied_request as proxied %}
{% if proxied %}
<script>
{# inline_file from DAB #}
{% inline_file "static/api/api.js" True %}
</script>
{% else %}
<script src="{% static 'api/api.js' %}?v={{tower_version}}"></script>
{% endif %}
{% endblock %}