Author: jacob
Date: 2009-04-08 14:47:46 -0500 (Wed, 08 Apr 2009)
New Revision: 10451
Modified:
django/trunk/django/contrib/admin/options.py
django/trunk/django/contrib/admin/sites.py
Log:
Fixed #9036: unified the permission checking in `AdminSite`, pushing it down to
the `ModelAdmin` where it belongs.
Modified: django/trunk/django/contrib/admin/options.py
===================================================================
--- django/trunk/django/contrib/admin/options.py 2009-04-08 19:42:01 UTC
(rev 10450)
+++ django/trunk/django/contrib/admin/options.py 2009-04-08 19:47:46 UTC
(rev 10451)
@@ -291,6 +291,18 @@
opts = self.opts
return request.user.has_perm(opts.app_label + '.' +
opts.get_delete_permission())
+ def get_model_perms(self, request):
+ """
+ Returns a dict of all perms for this model. This dict has the keys
+ ``add``, ``change``, and ``delete`` mapping to the True/False for each
+ of those actions.
+ """
+ return {
+ 'add': self.has_add_permission(request),
+ 'change': self.has_change_permission(request),
+ 'delete': self.has_delete_permission(request),
+ }
+
def queryset(self, request):
"""
Returns a QuerySet of all model instances that can be edited by the
Modified: django/trunk/django/contrib/admin/sites.py
===================================================================
--- django/trunk/django/contrib/admin/sites.py 2009-04-08 19:42:01 UTC (rev
10450)
+++ django/trunk/django/contrib/admin/sites.py 2009-04-08 19:47:46 UTC (rev
10451)
@@ -328,11 +328,7 @@
has_module_perms = user.has_module_perms(app_label)
if has_module_perms:
- perms = {
- 'add': model_admin.has_add_permission(request),
- 'change': model_admin.has_change_permission(request),
- 'delete': model_admin.has_delete_permission(request),
- }
+ perms = model_admin.get_model_perms(request)
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
@@ -391,11 +387,8 @@
for model, model_admin in self._registry.items():
if app_label == model._meta.app_label:
if has_module_perms:
- perms = {
- 'add': user.has_perm("%s.%s" % (app_label,
model._meta.get_add_permission())),
- 'change': user.has_perm("%s.%s" % (app_label,
model._meta.get_change_permission())),
- 'delete': user.has_perm("%s.%s" % (app_label,
model._meta.get_delete_permission())),
- }
+ perms = model_admin.get_model_perms(request)
+
# Check whether user has any perm for this module.
# If so, add the module to the model_list.
if True in perms.values():
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---