<commit_before># -*- coding: utf-8 -*-
from django.conf import settings

from django.contrib.auth.models import User

from cms.models import Page, CMSPlugin
from cms.models.moderatormodels import ACCESS_DESCENDANTS
from cms.test_utils.testcases import CMSTestCase, URL_CMS_PAGE_ADD, URL_CMS_PLUGIN_REMOVE
from cms.test_utils.util.context_managers import SettingsOverride
from cms.utils.permissions import has_generic_permission

class PermissionModeratorTestCase(CMSTestCase):
    """
    Permissions and moderator together
    
    Fixtures contains 3 users and 1 published page and some other stuff
    
    Users:
        1. `super`: superuser
        2. `master`: user with permissions to all applications
        3. `slave`: user assigned to page `slave-home`
    
    Pages:
        1. `home`:
            - published page
            - master can do anything on its subpages, but not on home!
            
        2. `master`:
            - published page
            - crated by super
            - `master` can do anything on it and its descendants
            - subpages:
        
        3.       `slave-home`:
                    - not published
                    - assigned slave user which can add/change/delete/
                      move/publish/moderate this page and its descendants
                    - `master` user want to moderate this page and all descendants
                    
        4. `pageA`:
            - created by super
            - master can add/change/delete on it and descendants 

        5. `pageB`:
            - created by super
            - normal can view on it and descendants

    """
    def setUp(self):
        # create super user
        self.user_super = User(username="super", is_staff=True, is_active=True, 
            is_superuser=True)
        self.user_super.set_password("<PASSWORD>")
        self.user_super.save()
        
        # create staff user
        self.user_staff = User(username="staff", is_staff=True, is_active=True)
        self.user_staff.set_password("<PASSWORD>")
        self.user_staff.save()
        
        self.login_user(self.user_super)

        # create basic structure ...
        
        self.home_page = self.create_page(title="home", user=self.user_super)
        
        # master page & master user
        
        self.master_page = self.create_page(title="master")

        # create master user
        self.user_master = self.create_page_user("master", grant_all=True)
        
        # assign master user under home page
        self.assign_user_to_page(self.home_page, self.user_master, grant_on=ACCESS_DESCENDANTS,
            grant_all=True)
        
        # and to master page
        self.assign_user_to_page(self.master_page, self.user_master, grant_all=True)
        
        # slave page & slave user
        
        self.slave_page = self.create_page(title="slave-home", parent_page=self.master_page, user=self.user_super)  
        self.user_slave = self.create_page_user("slave", 
            can_add_page=True, can_change_page=True, can_delete_page=True)
        
        self.assign_user_to_page(self.slave_page, self.user_slave, grant_all=True)
        
        # create page_b
        
        page_b = self.create_page(title="pageB", published=True)
        page_b = self.publish_page(page_b, approve=True)

        # Normal user
        self.user_normal = self.create_page_user("normal")
        # it's allowed for the normal user to view the page
        perm = self.assign_user_to_page(page_b, self.user_normal, can_view=True)

        # create page_a - sample page from master
        
        page_a = self.create_page(title="pageA", user=self.user_super)
        self.assign_user_to_page(page_a, self.user_master,
            can_add=True, can_change=True, can_delete=True, can_publish=True, 
            can_move_page=True, can_moderate=True)
        
        # publish after creating all drafts
        self.publish_page(self.home_page)
        self.publish_page(self.master_page)
        # logg in as master, and request moderation for slave page and descendants<commit_msg>Create the pageB test page correctly with super user.<commit_after># -*- coding: utf-8 -*-
from django.conf import settings

from django.contrib.auth.models import User

from cms.models import Page, CMSPlugin
from cms.models.moderatormodels import ACCESS_DESCENDANTS
from cms.test_utils.testcases import CMSTestCase, URL_CMS_PAGE_ADD, URL_CMS_PLUGIN_REMOVE
from cms.test_utils.util.context_managers import SettingsOverride
from cms.utils.permissions import has_generic_permission

class PermissionModeratorTestCase(CMSTestCase):
    """
    Permissions and moderator together
    
    Fixtures contains 3 users and 1 published page and some other stuff
    
    Users:
        1. `super`: superuser
        2. `master`: user with permissions to all applications
        3. `slave`: user assigned to page `slave-home`
    
    Pages:
        1. `home`:
            - published page
            - master can do anything on its subpages, but not on home!
            
        2. `master`:
            - published page
            - crated by super
            - `master` can do anything on it and its descendants
            - subpages:
        
        3.       `slave-home`:
                    - not published
                    - assigned slave user which can add/change/delete/
                      move/publish/moderate this page and its descendants
                    - `master` user want to moderate this page and all descendants
                    
        4. `pageA`:
            - created by super
            - master can add/change/delete on it and descendants 

        5. `pageB`:
            - created by super
            - normal can view on it and descendants

    """
    def setUp(self):
        # create super user
        self.user_super = User(username="super", is_staff=True, is_active=True, 
            is_superuser=True)
        self.user_super.set_password("<PASSWORD>")
        self.user_super.save()
        
        # create staff user
        self.user_staff = User(username="staff", is_staff=True, is_active=True)
        self.user_staff.set_password("<PASSWORD>")
        self.user_staff.save()
        
        self.login_user(self.user_super)

        # create basic structure ...
        
        self.home_page = self.create_page(title="home", user=self.user_super)
        
        # master page & master user
        
        self.master_page = self.create_page(title="master")

        # create master user
        self.user_master = self.create_page_user("master", grant_all=True)
        
        # assign master user under home page
        self.assign_user_to_page(self.home_page, self.user_master, grant_on=ACCESS_DESCENDANTS,
            grant_all=True)
        
        # and to master page
        self.assign_user_to_page(self.master_page, self.user_master, grant_all=True)
        
        # slave page & slave user
        
        self.slave_page = self.create_page(title="slave-home", parent_page=self.master_page, user=self.user_super)  
        self.user_slave = self.create_page_user("slave", 
            can_add_page=True, can_change_page=True, can_delete_page=True)
        
        self.assign_user_to_page(self.slave_page, self.user_slave, grant_all=True)
        
        # create page_b
        page_b = self.create_page(title="pageB", user=self.user_super)

        # Normal user
        self.user_normal = self.create_page_user("normal")
        # it's allowed for the normal user to view the page
        perm = self.assign_user_to_page(page_b, self.user_normal, can_view=True)

        # create page_a - sample page from master
        
        page_a = self.create_page(title="pageA", user=self.user_super)
        self.assign_user_to_page(page_a, self.user_master,
            can_add=True, can_change=True, can_delete=True, can_publish=True, 
            can_move_page=True, can_moderate=True)
        
        # publish after creating all drafts
        self.publish_page(self.home_page)
        self.publish_page(self.master_page)
        self.publish_page(page_b)
        # logg in as master, and request moderation for slave page and descendants
{'fraction_non_alphanumeric': 0.07934386391251519, 'fraction_numerical': 0.0026731470230862697, 'mean_word_length': 2.186604723190089, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '617003', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2313, 'n_words': 583}