diff --git a/django/contrib/comments/admin.py b/django/contrib/comments/admin.py index 28678e045a..4cb90663a0 100644 --- a/django/contrib/comments/admin.py +++ b/django/contrib/comments/admin.py @@ -28,11 +28,13 @@ class CommentsAdmin(admin.ModelAdmin): def get_actions(self, request): actions = super(CommentsAdmin, self).get_actions(request) # Only superusers should be able to delete the comments from the DB. - if not request.user.is_superuser: + if not request.user.is_superuser and 'delete_selected' in actions: actions.pop('delete_selected') if not request.user.has_perm('comments.can_moderate'): - actions.pop('approve_comments') - actions.pop('remove_comments') + if 'approve_comments' in actions: + actions.pop('approve_comments') + if 'remove_comments' in actions: + actions.pop('remove_comments') return actions def flag_comments(self, request, queryset): diff --git a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py index ef79b4dc15..e5094ab0cc 100644 --- a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py +++ b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py @@ -190,3 +190,14 @@ class AdminActionsTests(CommentTestCase): self.client.login(username="normaluser", password="normaluser") response = self.client.get("/admin/comments/comment/") self.assertEquals("approve_comments" in response.content, True) + + def testActionsDisabledDelete(self): + "Tests a CommentAdmin where 'delete_selected' has been disabled." + comments = self.createSomeComments() + self.client.login(username="normaluser", password="normaluser") + response = self.client.get('/admin2/comments/comment/') + self.assertEqual(response.status_code, 200) + self.assert_( + '