Skip to content

Commit

Permalink
Merge pull request #1736 from cisagov/1373-non-prod-banner
Browse files Browse the repository at this point in the history
Issue 1373: Add non-prod banner (RJM sandbox)
  • Loading branch information
rachidatecs authored Feb 7, 2024
2 parents d4f1de9 + 8f1ab86 commit c0fd3d9
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 29 deletions.
5 changes: 4 additions & 1 deletion src/registrar/assets/sass/_theme/_alerts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
.usa-alert__body::before {
left: 1rem !important;
}
}
}
.usa-alert__body.margin-left-1 {
margin-left: 0.5rem!important;
}
}
4 changes: 4 additions & 0 deletions src/registrar/assets/sass/_theme/_uswds-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ in the form $setting: value,
$theme-color-success-light: $dhs-green-30,
$theme-color-success-lighter: $dhs-green-15,

/*---------------------------
## Emergency state
----------------------------*/
$theme-color-emergency: #FFC3F9,

/*---------------------------
# Input settings
Expand Down
79 changes: 51 additions & 28 deletions src/registrar/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,57 @@
{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block extrastyle %}{{ block.super }}
<link rel="stylesheet" type="text/css" href="{% static "css/styles.css" %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/styles.css' %}" />
{% endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">.gov admin</a></h1>
{% if user.is_anonymous %}
{% include "admin/color_theme_toggle.html" %}
{% endif %}
{% endblock %}
{% comment %}
This was copied from the 'userlinks' template, with a few minor changes.
You can find that here:
https://github.com/django/django/blob/d25f3892114466d689fd6936f79f3bd9a9acc30e/django/contrib/admin/templates/admin/base.html#L59
{% endcomment %}
{% block userlinks %}
{% if site_url %}
<a href="{{ site_url }}">{% translate 'View site' %}</a> /
{% endif %}
{% if user.is_active and user.is_staff %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}
<a href="{{ docsroot }}">{% translate 'Documentation' %}</a> /
{% endif %}
{% endif %}
{% if user.has_usable_password %}
<a href="{% url 'admin:password_change' %}">{% translate 'Change password' %}</a> /
{% block header %}
{% if not IS_PRODUCTION %}
{% with add_body_class="margin-left-1" %}
{% include "includes/non-production-alert.html" %}
{% endwith %}
{% endif %}
<a href="{% url 'admin:logout' %}" id="admin-logout-button">{% translate 'Log out' %}</a>
{% include "admin/color_theme_toggle.html" %}
{% endblock %}
{% block nav-global %}{% endblock %}

{# Djando update: this div will change to header #}
<div id="header">
<div id="branding">
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">.gov admin</a></h1>
{% if user.is_anonymous %}
{% include "admin/color_theme_toggle.html" %}
{% endif %}
{% endblock %}
</div>
{% block usertools %}
{% if has_permission %}
<div id="user-tools">
{% block welcome-msg %}
{% translate 'Welcome,' %}
<strong>{% firstof user.get_short_name user.get_username %}</strong>.
{% endblock %}
{% comment %}
This was copied from the 'userlinks' template, with a few minor changes.
You can find that here:
https://github.com/django/django/blob/d25f3892114466d689fd6936f79f3bd9a9acc30e/django/contrib/admin/templates/admin/base.html#L59
{% endcomment %}
{% block userlinks %}
{% if site_url %}
<a href="{{ site_url }}">{% translate 'View site' %}</a> /
{% endif %}
{% if user.is_active and user.is_staff %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}
<a href="{{ docsroot }}">{% translate 'Documentation' %}</a> /
{% endif %}
{% endif %}
{% if user.has_usable_password %}
<a href="{% url 'admin:password_change' %}">{% translate 'Change password' %}</a> /
{% endif %}
<a href="{% url 'admin:logout' %}" id="admin-logout-button">{% translate 'Log out' %}</a>
{% include "admin/color_theme_toggle.html" %}
{% endblock %}
</div>
{% endif %}
{% endblock %}
{% block nav-global %}{% endblock %}
</div>
{% endblock %}
4 changes: 4 additions & 0 deletions src/registrar/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
<script src="{% static 'js/uswds.min.js' %}" defer></script>
<a class="usa-skipnav" href="#main-content">Skip to main content</a>

{% if not IS_PRODUCTION %}
{% include "includes/non-production-alert.html" %}
{% endif %}

<section class="usa-banner" aria-label="Official website of the United States government">
<div class="usa-accordion">
<header class="usa-banner__header">
Expand Down
5 changes: 5 additions & 0 deletions src/registrar/templates/includes/non-production-alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="usa-alert usa-alert--emergency margin-y-0 {% if add_class %}{{ add_class }}{% endif %}">
<div class="usa-alert__body {% if add_body_class %}{{ add_body_class }}{% endif %}">
<b>Attention:</b> You are on a test site.
</div>
</div>
31 changes: 31 additions & 0 deletions src/registrar/tests/test_environment_variables_effects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.test import Client, TestCase, override_settings
from django.contrib.auth import get_user_model


class MyTestCase(TestCase):
def setUp(self):
self.client = Client()
username = "test_user"
first_name = "First"
last_name = "Last"
email = "[email protected]"
self.user = get_user_model().objects.create(
username=username, first_name=first_name, last_name=last_name, email=email
)
self.client.force_login(self.user)

def tearDown(self):
super().tearDown()
self.user.delete()

@override_settings(IS_PRODUCTION=True)
def test_production_environment(self):
"""No banner on prod."""
home_page = self.client.get("/")
self.assertNotContains(home_page, "You are on a test site.")

@override_settings(IS_PRODUCTION=False)
def test_non_production_environment(self):
"""Banner on non-prod."""
home_page = self.client.get("/")
self.assertContains(home_page, "You are on a test site.")

0 comments on commit c0fd3d9

Please sign in to comment.