Permalink
Browse files

Fixed #7179 -- Changed breadcrumbs on the add page so that a link to …

…the change view is not included when the user doesn't have permission for that view. Also added tests to ensure the link is not there when it shouldn't be, and there when it should be. Thanks for the report & patch alen__ribic.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9276 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 3dfbaae commit 03070a9955775017d2e313a851c435bc85041ced @kmtracey kmtracey committed Oct 24, 2008
@@ -16,7 +16,7 @@
<div class="breadcrumbs">
<a href="../../../">{% trans "Home" %}</a> &rsaquo;
<a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
- <a href="../">{{ opts.verbose_name_plural|capfirst }}</a> &rsaquo;
+ {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
{% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div>
{% endif %}{% endblock %}
@@ -327,6 +327,11 @@ def testAddView(self):
# Add user may login and POST to add view, then redirect to admin root
self.client.get('/test_admin/admin/')
self.client.post('/test_admin/admin/', self.adduser_login)
+ addpage = self.client.get('/test_admin/admin/admin_views/article/add/')
+ self.failUnlessEqual(addpage.status_code, 200)
+ change_list_link = '<a href="../">Articles</a> &rsaquo;'
+ self.failIf(change_list_link in addpage.content,
+ 'User restricted to add permission is given link to change list view in breadcrumbs.')
post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict)
self.assertRedirects(post, '/test_admin/admin/')
self.failUnlessEqual(Article.objects.all().count(), 4)
@@ -335,6 +340,10 @@ def testAddView(self):
# Super can add too, but is redirected to the change list view
self.client.get('/test_admin/admin/')
self.client.post('/test_admin/admin/', self.super_login)
+ addpage = self.client.get('/test_admin/admin/admin_views/article/add/')
+ self.failUnlessEqual(addpage.status_code, 200)
+ self.failIf(change_list_link not in addpage.content,
+ 'Unrestricted user is not given link to change list view in breadcrumbs.')
post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict)
self.assertRedirects(post, '/test_admin/admin/admin_views/article/')
self.failUnlessEqual(Article.objects.all().count(), 5)

0 comments on commit 03070a9

Please sign in to comment.