Example #1
0
 def assign_user_to_page(self, page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
     can_add=False, can_change=False, can_delete=False, 
     can_change_advanced_settings=False, can_publish=False, 
     can_change_permissions=False, can_move_page=False, can_moderate=False, 
     grant_all=False):
     """Assigns given user to page, and gives him requested permissions. 
     
     Note: this is not happening over frontend, maybe a test for this in 
     future will be nice.
     """
     if grant_all:
         return self.assign_user_to_page(page, user, grant_on, 
             True, True, True, True, True, True, True, True)
     
     data = {
         'can_add': can_add,
         'can_change': can_change,
         'can_delete': can_delete, 
         'can_change_advanced_settings': can_change_advanced_settings,
         'can_publish': can_publish, 
         'can_change_permissions': can_change_permissions, 
         'can_move_page': can_move_page, 
         'can_moderate': can_moderate,  
     }
     
     page_permission = PagePermission(page=page, user=user, grant_on=grant_on, **data)
     page_permission.save()
     return page_permission
Example #2
0
 def assign_user_to_page(self, page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
     can_add=False, can_change=False, can_delete=False, 
     can_change_advanced_settings=False, can_publish=False, 
     can_change_permissions=False, can_move_page=False, can_moderate=False, 
     grant_all=False):
     """Assigns given user to page, and gives him requested permissions. 
     
     Note: this is not happening over frontend, maybe a test for this in 
     future will be nice.
     """
     if grant_all:
         return self.assign_user_to_page(page, user, grant_on, 
             True, True, True, True, True, True, True, True)
     
     # just check if the current logged in user even can change the page and 
     # see the permission inline
     response = self.client.get(URL_CMS_PAGE_CHANGE % page.id)
     self.assertEqual(response.status_code, 200)
     
     data = {
         'can_add': can_add,
         'can_change': can_change,
         'can_delete': can_delete, 
         'can_change_advanced_settings': can_change_advanced_settings,
         'can_publish': can_publish, 
         'can_change_permissions': can_change_permissions, 
         'can_move_page': can_move_page, 
         'can_moderate': can_moderate,  
     }
     
     page_permission = PagePermission(page=page, user=user, grant_on=grant_on, **data)
     page_permission.save()
     return page_permission
Example #3
0
 def assign_user_to_page(self, page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
     can_add=False, can_change=False, can_delete=False, 
     can_change_advanced_settings=False, can_publish=False, 
     can_change_permissions=False, can_move_page=False, can_moderate=False, 
     grant_all=False):
     """Assigns given user to page, and gives him requested permissions. 
     
     Note: this is not happening over frontend, maybe a test for this in 
     future will be nice.
     """
     if grant_all:
         return self.assign_user_to_page(page, user, grant_on, 
             True, True, True, True, True, True, True, True)
     
     data = {
         'can_add': can_add,
         'can_change': can_change,
         'can_delete': can_delete, 
         'can_change_advanced_settings': can_change_advanced_settings,
         'can_publish': can_publish, 
         'can_change_permissions': can_change_permissions, 
         'can_move_page': can_move_page, 
         'can_moderate': can_moderate,  
     }
     
     page_permission = PagePermission(page=page, user=user, grant_on=grant_on, **data)
     page_permission.save()
     return page_permission
Example #4
0
def assign_user_to_page(page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                        can_add=False, can_change=False, can_delete=False,
                        can_change_advanced_settings=False, can_publish=False,
                        can_change_permissions=False, can_move_page=False,
                        can_recover_page=True, can_view=False,
                        grant_all=False, global_permission=False):
    """
    Assigns given user to page, and gives him requested permissions.

    See docs/extending_cms/api_reference.rst for more info
    """
    grant_all = grant_all and not global_permission
    data = {
        'can_add': can_add or grant_all,
        'can_change': can_change or grant_all,
        'can_delete': can_delete or grant_all,
        'can_change_advanced_settings': can_change_advanced_settings or grant_all,
        'can_publish': can_publish or grant_all,
        'can_change_permissions': can_change_permissions or grant_all,
        'can_move_page': can_move_page or grant_all,
        'can_view': can_view or grant_all,
    }

    page_permission = PagePermission(page=page, user=user,
                                     grant_on=grant_on, **data)
    page_permission.save()
    if global_permission:
        page_permission = GlobalPagePermission(
            user=user, can_recover_page=can_recover_page, **data)
        page_permission.save()
        page_permission.sites.add(get_current_site())
    return page_permission
Example #5
0
    def assign_user_to_page(self,
                            page,
                            user,
                            grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                            can_add=False,
                            can_change=False,
                            can_delete=False,
                            can_change_advanced_settings=False,
                            can_publish=False,
                            can_change_permissions=False,
                            can_move_page=False,
                            can_moderate=False,
                            grant_all=False):
        """Assigns given user to page, and gives him requested permissions. 
        
        Note: this is not happening over frontend, maybe a test for this in 
        future will be nice.
        """
        if grant_all:
            return self.assign_user_to_page(page, user, grant_on, True, True,
                                            True, True, True, True, True, True)

        # just check if the current logged in user even can change the page and
        # see the permission inline
        response = self.client.get(URL_CMS_PAGE_CHANGE % page.id)
        self.assertEqual(response.status_code, 200)

        data = {
            'can_add': can_add,
            'can_change': can_change,
            'can_delete': can_delete,
            'can_change_advanced_settings': can_change_advanced_settings,
            'can_publish': can_publish,
            'can_change_permissions': can_change_permissions,
            'can_move_page': can_move_page,
            'can_moderate': can_moderate,
        }

        page_permission = PagePermission(page=page,
                                         user=user,
                                         grant_on=grant_on,
                                         **data)
        page_permission.save()
        return page_permission
Example #6
0
 def grant_to_user(self, user, site, pages=None):
     """Grant the given user this role for given site"""
     if self.is_site_wide:
         user.groups.add(self.get_site_specific_group(site))
     else:
         if pages is None or len(pages) == 0:
             raise ValidationError("At lest a page must be given")
         # delete the existing page perms
         self.get_user_page_perms(user, site).delete()
         # and assign the new ones
         for page in pages:
             page_permission = PagePermission(page=page, user=user, grant_on=ACCESS_PAGE_AND_DESCENDANTS)
             for key, value in self._get_permissions_dict().iteritems():
                 setattr(page_permission, key, value)
             page_permission.save()
             self.derived_page_permissions.add(page_permission)
         user.groups.add(self.group)
     if not user.is_staff:
         user.is_staff = True
         user.save()
Example #7
0
def assign_user_to_page(page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS,
    can_add=False, can_change=False, can_delete=False, 
    can_change_advanced_settings=False, can_publish=False, 
    can_change_permissions=False, can_move_page=False,
    can_recover_page=True, can_view=False,
    grant_all=False, global_permission=False):
    """
    Assigns given user to page, and gives him requested permissions.
    
    See docs/extending_cms/api_reference.rst for more info
    """
    grant_all = grant_all and not global_permission
    data = {
        'can_add': can_add or grant_all,
        'can_change': can_change or grant_all,
        'can_delete': can_delete or grant_all,
        'can_change_advanced_settings': can_change_advanced_settings or grant_all,
        'can_publish': can_publish or grant_all,
        'can_change_permissions': can_change_permissions or grant_all,
        'can_move_page': can_move_page or grant_all,
        'can_view': can_view or grant_all,
        }

    page_permission = PagePermission(page=page, user=user,
                                     grant_on=grant_on, **data)
    page_permission.save()
    if global_permission:
        page_permission = GlobalPagePermission(
            user=user, can_recover_page=can_recover_page, **data)
        page_permission.save()
        page_permission.sites.add(Site.objects.get_current())
    return page_permission
Example #8
0
 def grant_to_user(self, user, site, pages=None):
     """Grant the given user this role for given site"""
     if self.is_site_wide:
         user.groups.add(self.get_site_specific_group(site))
     else:
         if pages is None or len(pages) == 0:
             raise ValidationError('At lest a page must be given')
         # delete the existing page perms
         self.get_user_page_perms(user, site).delete()
         # and assign the new ones
         for page in pages:
             page_permission = PagePermission(
                 page=page, user=user, grant_on=ACCESS_PAGE_AND_DESCENDANTS)
             for key, value in self._get_permissions_dict()\
                     .iteritems():
                 setattr(page_permission, key, value)
             page_permission.save()
             self.derived_page_permissions.add(page_permission)
         user.groups.add(self.group)
     if not user.is_staff:
         user.is_staff = True
         user.save()
Example #9
0
    def _migrate_page(self, options, site, pagetree, pagemeta, pagecontent):
        url = pagemeta.get_absolute_url()
        created_py = self.USER_MAP[pagemeta.createby.pk]
        changed_by = self.USER_MAP[pagemeta.lastupdateby.pk]

        if pagemeta.permitViewGroup == None and pagetree.permitViewGroup == None:
            login_required = False
        else:
            login_required = True

        if pagetree.id in self._PAGES:
            # Was created before in other language
            page = self._PAGES[pagetree.id]
            self.file_log.debug("\t * Add in language %r: %s" % (pagemeta.language.code, url))

            create_title(
                language=pagemeta.language.code,
                title=pagemeta.get_title(),
                page=page,
                slug=pagetree.slug,
                meta_description=pagemeta.description,
            )
            # page.rescan_placeholders()
            # page = page.reload()
        else:
            self.file_log.debug("\t * Create in language %r: %s" % (pagemeta.language.code, url))
            if pagetree.parent:
                # self.file_log.debug("parent: %r" % pagetree.parent.get_absolute_url())
                parent = self._PAGES[pagetree.parent.id]
            else:
                parent = None

            # http://docs.django-cms.org/en/support-3.0.x/reference/api_references.html#cms.api.create_page
            page = create_page(
                title=pagemeta.get_title(),
                menu_title=pagemeta.get_name(),

                template=cms.constants.TEMPLATE_INHERITANCE_MAGIC,
                language=pagemeta.language.code,
                slug=pagetree.slug,
                # apphook=None, apphook_namespace=None, redirect=None,
                meta_description=pagemeta.description,
                created_by=created_py,
                parent=parent,
                # publication_date=None, publication_end_date=None,

                # Accessable for all users, but don't put a Link to this page into menu/sitemap etc.
                in_navigation=pagetree.showlinks,

                # soft_root=False, reverse_id=None,
                # navigation_extenders=None,
                published=False,
                site=site,
                login_required=login_required,
                # limit_visibility_in_menu=VISIBILITY_ALL,
                # position="last-child", overwrite_url=None, xframe_options=Page.X_FRAME_OPTIONS_INHERIT
            )

            self._PAGES[pagetree.id] = page

        # pagemeta.permitViewGroup # Limit viewable this page in this language to a user group?
        # pagetree.permitViewGroup # Limit viewable to a group?
        view_group = pagetree.permitViewGroup or pagemeta.permitViewGroup
        edit_group = pagetree.permitEditGroup  # Usergroup how can edit this page.
        # print("\nview:", view_group, "edit:", edit_group)

        if view_group and edit_group and view_group == edit_group:
            page_permission = PagePermission(
                page=page,
                user=None,
                group=edit_group,
                grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                can_add=True,
                can_change=True,
                can_delete=True,
                can_change_advanced_settings=True,
                can_publish=True,
                can_change_permissions=True,
                can_move_page=True,
                can_view=True,
            )
            page_permission.save()
        else:
            if view_group:
                page_permission = PagePermission(
                    page=page,
                    user=None,
                    group=view_group,
                    grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                    can_add=False,
                    can_change=False,
                    can_delete=False,
                    can_change_advanced_settings=False,
                    can_publish=False,
                    can_change_permissions=False,
                    can_move_page=False,
                    can_view=True,
                )
                page_permission.save()

            if edit_group:
                page_permission = PagePermission(
                    page=page,
                    user=None,
                    group=view_group,
                    grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                    can_add=True,
                    can_change=True,
                    can_delete=True,
                    can_change_advanced_settings=True,
                    can_publish=True,
                    can_change_permissions=True,
                    can_move_page=True,
                    can_view=True,
                )
                page_permission.save()

        placeholder = page.placeholders.filter(slot="content")[0]
        content2plugins(options, placeholder, pagecontent.content, pagecontent.markup,
                        pagemeta.language.code)

        page.publish(pagemeta.language.code)

        # using api.publish_page() will result in django.db.utils.IntegrityError:
        #       UNIQUE constraint failed: cms_page.publisher_public_id
        # published_page = publish_page(page, user=changed_by, language=pagemeta.language.code)

        page_meta_patcher = PageMetaPatcher(
            created_by=created_py.username,
            creation_date=pagemeta.createtime,
            changed_by=changed_by.username,
            changed_date=pagemeta.lastupdatetime,
        )

        # print("\npatch draft version")
        draft_page = page.get_draft_object()
        page_meta_patcher.patch(draft_page)  # patch the draft version

        # print("patch the published version")
        published_page = page.get_public_object()
        page_meta_patcher.patch(published_page)  # patch the published version
Example #10
0
    def _migrate_page(self, options, site, pagetree, pagemeta, pagecontent):
        url = pagemeta.get_absolute_url()
        created_py = self.USER_MAP[pagemeta.createby.pk]
        changed_by = self.USER_MAP[pagemeta.lastupdateby.pk]

        if pagemeta.permitViewGroup == None and pagetree.permitViewGroup == None:
            login_required = False
            visibility = constants.VISIBILITY_ALL
        else:
            login_required = True
            visibility = constants.VISIBILITY_USERS

        if pagetree.id in self._PAGES:
            # Was created before in other language
            page = self._PAGES[pagetree.id]
            self.file_log.debug("\t * Add in language %r: %s" %
                                (pagemeta.language.code, url))

            create_title(
                language=pagemeta.language.code,
                title=pagemeta.get_title(),
                menu_title=pagemeta.name,
                page=page,
                slug=pagetree.slug,
                meta_description=pagemeta.description,
            )
            # page.rescan_placeholders()
            # page = page.reload()
        else:
            self.file_log.debug("\t * Create in language %r: %s" %
                                (pagemeta.language.code, url))
            if pagetree.parent:
                # self.file_log.debug("parent: %r" % pagetree.parent.get_absolute_url())
                parent = self._PAGES[pagetree.parent.id]
            else:
                parent = None

            # http://docs.django-cms.org/en/latest/reference/api_references.html#cms.api.create_page
            page = create_page(
                title=pagemeta.get_title(),
                menu_title=pagemeta.get_name(),
                template=cms.constants.TEMPLATE_INHERITANCE_MAGIC,
                language=pagemeta.language.code,
                slug=pagetree.slug,
                # apphook=None, apphook_namespace=None, redirect=None,
                meta_description=pagemeta.description,
                created_by=created_py,
                parent=parent,
                # publication_date=None, publication_end_date=None,

                # Accessable for all users, but don't put a Link to this page into menu/sitemap etc.
                in_navigation=pagetree.showlinks,

                # soft_root=False, reverse_id=None,
                # navigation_extenders=None,
                published=False,
                site=site,
                login_required=login_required,
                limit_visibility_in_menu=visibility,

                # position="last-child", overwrite_url=None, xframe_options=Page.X_FRAME_OPTIONS_INHERIT
            )

            self._PAGES[pagetree.id] = page

        # pagemeta.permitViewGroup # Limit viewable this page in this language to a user group?
        # pagetree.permitViewGroup # Limit viewable to a group?
        view_group = pagetree.permitViewGroup or pagemeta.permitViewGroup
        edit_group = pagetree.permitEditGroup  # Usergroup how can edit this page.
        # print("\nview:", view_group, "edit:", edit_group)

        if view_group and edit_group and view_group == edit_group:
            page_permission = PagePermission(
                page=page,
                user=None,
                group=edit_group,
                grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                can_add=True,
                can_change=True,
                can_delete=True,
                can_change_advanced_settings=True,
                can_publish=True,
                can_change_permissions=True,
                can_move_page=True,
                can_view=True,
            )
            page_permission.save()
        else:
            if view_group:
                page_permission = PagePermission(
                    page=page,
                    user=None,
                    group=view_group,
                    grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                    can_add=False,
                    can_change=False,
                    can_delete=False,
                    can_change_advanced_settings=False,
                    can_publish=False,
                    can_change_permissions=False,
                    can_move_page=False,
                    can_view=True,
                )
                page_permission.save()

            if edit_group:
                page_permission = PagePermission(
                    page=page,
                    user=None,
                    group=view_group,
                    grant_on=ACCESS_PAGE_AND_DESCENDANTS,
                    can_add=True,
                    can_change=True,
                    can_delete=True,
                    can_change_advanced_settings=True,
                    can_publish=True,
                    can_change_permissions=True,
                    can_move_page=True,
                    can_view=True,
                )
                page_permission.save()

        placeholder = page.placeholders.filter(slot="content")[0]
        content2plugins(options, placeholder, pagecontent.content,
                        pagecontent.markup, pagemeta.language.code)

        page.publish(pagemeta.language.code)

        # using api.publish_page() will result in django.db.utils.IntegrityError:
        #       UNIQUE constraint failed: cms_page.publisher_public_id
        # published_page = publish_page(page, user=changed_by, language=pagemeta.language.code)

        page_meta_patcher = PageMetaPatcher(
            created_by=created_py.username,
            creation_date=pagemeta.createtime,
            changed_by=changed_by.username,
            changed_date=pagemeta.lastupdatetime,
        )

        # print("\npatch draft version")
        draft_page = page.get_draft_object()
        page_meta_patcher.patch(draft_page)  # patch the draft version

        # print("patch the published version")
        published_page = page.get_public_object()
        page_meta_patcher.patch(published_page)  # patch the published version