Author: adrian
Date: 2008-12-25 00:17:42 -0600 (Thu, 25 Dec 2008)
New Revision: 9683

Modified:
   django/trunk/django/contrib/auth/admin.py
Log:
Improved the auth admin site to raise Http404 with a helpful error message if 
DEBUG is True, explaining why permission isn't denied. Refs #9866, and see also 
[9682]

Modified: django/trunk/django/contrib/auth/admin.py
===================================================================
--- django/trunk/django/contrib/auth/admin.py   2008-12-25 06:04:11 UTC (rev 
9682)
+++ django/trunk/django/contrib/auth/admin.py   2008-12-25 06:17:42 UTC (rev 
9683)
@@ -1,14 +1,14 @@
-
+from django import template
+from django.conf import settings
+from django.contrib import admin
+from django.contrib.auth.forms import UserCreationForm, UserChangeForm, 
AdminPasswordChangeForm
 from django.contrib.auth.models import User, Group
 from django.core.exceptions import PermissionDenied
-from django import template
+from django.http import HttpResponseRedirect, Http404
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
 from django.utils.html import escape
-from django.http import HttpResponseRedirect
 from django.utils.translation import ugettext, ugettext_lazy as _
-from django.contrib.auth.forms import UserCreationForm, UserChangeForm, 
AdminPasswordChangeForm
-from django.contrib import admin
 
 class GroupAdmin(admin.ModelAdmin):
     search_fields = ('name',)
@@ -49,6 +49,10 @@
         # disallow users from adding users if they don't have change
         # permission.
         if not self.has_change_permission(request):
+            if self.has_add_permission(request) and settings.DEBUG:
+                # Raise Http404 in debug mode so that the user gets a helpful
+                # error message.
+                raise Http404('Your user does not have the "Change user" 
permission. In order to add users, Django requires that your user account have 
both the "Add user" and "Change user" permissions set.')
             raise PermissionDenied
         if request.method == 'POST':
             form = self.add_form(request.POST)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to