Repository: django-cms/django-cms

Issue:
2.2 Moderation Bug - Public Page Gets Unpublished
Hi all - 

Here is what I am experiencing:

A published and publicly visible page -  the home page - becomes unpublished. This happens
when a user makes an edit and Saves (or just hits Save), with permissions of "Add" and "Change" to just the home page.

To recreate.
1. settings.py

CMS_PUBLIC_FOR = 'all'
CMS_PERMISSION = True
CMS_MODERATOR = True
--(run required command: cms moderator on)

2: Users(Page)
--- Create user with only "Add" and "Change" page permissions
--- Only give this user permissions to edit the home page

3: Login in as that user. Go to the home page in admin. Press "Save". (You don't
need to make a change for the bug to happen. just press "Save"). And you
see the home page is marked as unpublished.
1. Logout of admin. See that your home page is missing from the the
   public all together. It's not in the nav. And the second page underneath
   became the new home page.
2. Login back in as super user, see that the second page just under
   the home page is now marked with the tree symbol, as the new home
   page.  The original first homepage has to be republished to go live. 



Discussion:
does this only happen on home pages or all pages?

After more testing I am able to reproduce on all pages.

can you confirm this only happening the _first_ time an underprivileged admin saves the page? If a superuser later publishes it, the other admin can no longer accidentally unpublish it. At least that was the behavior I experienced

I can confirm following behavior (admin with rights as described in OT):

1: superuser creates page (public)
2: admin saves the page
3: page is unpublished
4: superuser publishes page (again)
5: page is published
6: admin saves page
7: page is still published (expected behavior)

The different workflow internally is that line 324 (elif not self.requires_approvement()) triggers in 2, but not in 6. This sets the moderator state to 'MODERATOR_NEED_APPROVEMENT' in the first case, not in the second.

actually those findings were wrong

I now get consistent unpublishing.

The culprit seems to be 370-372 and not what I linked above (see https://github.com/divio/django-cms/blob/develop/cms/models/pagemodel.py#L370-372)


Resolving patch:
diff --git a/cms/models/pagemodel.py b/cms/models/pagemodel.py
--- a/cms/models/pagemodel.py
+++ b/cms/models/pagemodel.py
@@ -307,7 +307,6 @@ def save(self, no_signals=False, change_state=True, commit=True,
         
         # Published pages should always have a publication date
         publish_directly, under_moderation = False, False
-        
         if self.publisher_is_draft:
             # publisher specific stuff, but only on draft model, this is here 
             # because page initializes publish process
@@ -366,11 +365,6 @@ def save(self, no_signals=False, change_state=True, commit=True,
                 if commit and publish_directly:
                     
                     self.publish()
-                    
-            elif self.publisher_public and self.publisher_public.published:
-                self.publisher_public.published = False
-                self.publisher_public.save()
-                
                 
     def save_base(self, *args, **kwargs):
         """Overriden save_base. If an instance is draft, and was changed, mark


Test patch: