summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Visintini <lvisintini@gmail.com>2015-07-25 15:49:00 +0100
committerTim Graham <timograham@gmail.com>2015-07-29 15:09:32 -0400
commit635ffc3c37d58eb96ae17d5389dd50bf635413c6 (patch)
tree33b4a3fe4d70df29bbb08a1f59bb092343688744
parent537818af8783a4f9f239ed6277b1f810c1666839 (diff)
Fixed #25163 -- Added hint for non-staff users to admin login page.
-rw-r--r--django/contrib/admin/templates/admin/login.html10
-rw-r--r--tests/admin_views/tests.py19
2 files changed, 29 insertions, 0 deletions
diff --git a/django/contrib/admin/templates/admin/login.html b/django/contrib/admin/templates/admin/login.html
index b89aa50044..b939c9aac9 100644
--- a/django/contrib/admin/templates/admin/login.html
+++ b/django/contrib/admin/templates/admin/login.html
@@ -31,6 +31,16 @@
{% endif %}
<div id="content-main">
+
+{% if user.is_authenticated %}
+<p class="errornote">
+{% blocktrans with username=request.user.username %}
+ You are authenticated as {{ username }}, but are not authorized to
+ access this page. Would you like to login to a different account?
+{% endblocktrans %}
+</p>
+{% endif %}
+
<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %}
<div class="form-row">
{{ form.username.errors }}
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py
index 55ccee7fe1..9e6c349a36 100644
--- a/tests/admin_views/tests.py
+++ b/tests/admin_views/tests.py
@@ -1558,6 +1558,25 @@ class AdminViewPermissionsTest(TestCase):
self.assertFalse(login.context)
self.client.get(reverse('admin:logout'))
+ def test_login_page_notice_for_non_staff_users(self):
+ """
+ A logged-in non-staff user trying to access the admin index should be
+ presented with the login page and a hint indicating that the current
+ user doesn't have access to it.
+ """
+ hint_template = 'You are authenticated as {}'
+
+ # Anonymous user should not be shown the hint
+ response = self.client.get(self.index_url, follow=True)
+ self.assertContains(response, 'login-form')
+ self.assertNotContains(response, hint_template.format(''), status_code=200)
+
+ # Non-staff user should be shown the hint
+ self.client.login(**self.nostaff_login)
+ response = self.client.get(self.index_url, follow=True)
+ self.assertContains(response, 'login-form')
+ self.assertContains(response, hint_template.format(self.u6.username), status_code=200)
+
def test_add_view(self):
"""Test add view restricts access and actually adds items."""