Repository: django-cms/django-cms

Issue:
Admin action log not loggedon CMS Pages list AJAX action
When I save a CMS Page on its details, all is ok and that action is logged so I can see it on my last actions.

But when I for example publish a page via checkbox on the list of pages (AJAX call) that action is not logged



Discussion:

Resolving patch:
diff --git a/cms/admin/pageadmin.py b/cms/admin/pageadmin.py
--- a/cms/admin/pageadmin.py
+++ b/cms/admin/pageadmin.py
@@ -9,6 +9,7 @@
 import django
 from django.conf import settings
 from django.contrib import admin, messages
+from django.contrib.admin.models import LogEntry, CHANGE
 from django.contrib.admin.options import IncorrectLookupParameters
 from django.contrib.admin.util import get_deleted_objects
 from django.contrib.contenttypes.models import ContentType
@@ -1063,6 +1064,13 @@ def change_status(self, request, page_id):
                         messages.info(request, _('The page "%s" was successfully unpublished') % page)
                     else:
                         messages.info(request, _('The page "%s" was successfully published') % page)
+                    LogEntry.objects.log_action(
+                        user_id=request.user.id,
+                        content_type_id=ContentType.objects.get_for_model(Page).pk,
+                        object_id=page_id,
+                        object_repr=page.get_title(),
+                        action_flag=CHANGE,
+                    )
                 except RuntimeError, e:
                     messages.error(request, e.message)
             return admin_utils.render_admin_menu_item(request, page)
@@ -1086,7 +1094,7 @@ def descendants(self, request, page_id):
         """
         Get html for descendants of given page
         Used for lazy loading pages in change_list.js
-        
+
         Permission checks is done in admin_utils.get_admin_menu_item_context
         which is called by admin_utils.render_admin_menu_item.
         """


Test patch:
diff --git a/cms/tests/admin.py b/cms/tests/admin.py
--- a/cms/tests/admin.py
+++ b/cms/tests/admin.py
@@ -20,6 +20,7 @@
 from cms.utils import get_cms_setting
 import django
 from django.contrib import admin
+from django.contrib.admin.models import LogEntry
 from django.contrib.admin.sites import site
 from django.contrib.auth.models import User, Permission, AnonymousUser
 from django.contrib.sites.models import Site
@@ -598,6 +599,17 @@ def test_change_status(self):
             page = self.reload(page)
             self.assertFalse(page.published)
 
+    def test_change_status_adds_log_entry(self):
+        page = self.get_page()
+        admin = self.get_admin()
+        with self.login_user_context(admin):
+            request = self.get_request(post_data={'no': 'data'})
+            self.assertFalse(LogEntry.objects.count())
+            response = self.admin_class.change_status(request, page.pk)
+            self.assertEqual(response.status_code, 200)
+            self.assertEqual(1, LogEntry.objects.count())
+            self.assertEqual(page.pk, int(LogEntry.objects.all()[0].object_id))
+
     def test_change_innavigation(self):
         page = self.get_page()
         permless = self.get_permless()
@@ -939,7 +951,7 @@ def test_page_permission_inline_visibility(self):
         request = self._get_change_page_request(user, page)
         page_admin = PageAdmin(Page, None)
         page_admin._current_page = page
-        # user has can_change_permission 
+        # user has can_change_permission
         # => must see the PagePermissionInline
         self.assertTrue(
             any(type(inline) is PagePermissionInlineAdmin
@@ -1079,8 +1091,8 @@ class AdminPageEditContentSizeTests(AdminTestsBase):
     """
     System user count influences the size of the page edit page,
     but the users are only 2 times present on the page
-    
-    The test relates to extra=0 
+
+    The test relates to extra=0
     at PagePermissionInlineAdminForm and ViewRestrictionInlineAdmin
     """