Ticket #13709: admin_action_permission_check.patch

File admin_action_permission_check.patch, 1.8 KB (added by Sebastian Noack, 14 years ago)
  • django/django/contrib/admin/actions.py

    diff --git a/django/django/contrib/admin/actions.py b/django/django/contrib/admin/actions.py
    index 29fe28c..2c4b7b7 100644
    a b def delete_selected(modeladmin, request, queryset):  
    3030    opts = modeladmin.model._meta
    3131    app_label = opts.app_label
    3232
    33     # Check that the user has delete permission for the actual model
    34     if not modeladmin.has_delete_permission(request):
    35         raise PermissionDenied
    36 
    3733    # Populate deletable_objects, a data structure of all related objects that
    3834    # will also be deleted.
    3935
    def delete_selected(modeladmin, request, queryset):  
    8783    ], context, context_instance=template.RequestContext(request))
    8884
    8985delete_selected.short_description = ugettext_lazy("Delete selected %(verbose_name_plural)s")
     86delete_selected.has_permission = lambda admin, request: admin.has_delete_permission(request)
  • django/django/contrib/admin/options.py

    diff --git a/django/django/contrib/admin/options.py b/django/django/contrib/admin/options.py
    index 4638f7e..ad5c2f1 100644
    a b class ModelAdmin(BaseModelAdmin):  
    455455                continue
    456456            actions.extend([self.get_action(action) for action in class_actions])
    457457
    458         # get_action might have returned None, so filter any of those out.
    459         actions = filter(None, actions)
     458        # get_action might have returned None, so filter any of those out and
     459        # ensure that the action is usable in the current context.
     460        actions = [a for a in actions if a and (not hasattr(a[0], 'has_permission') or a[0].has_permission(self, request))]
    460461
    461462        # Convert the actions into a SortedDict keyed by name
    462463        # and sorted by description.
Back to Top