def test_edit_title_is_allowed_for_staff_user(self):
        """
        We check here both the permission on a single page, and the global permissions
        """
        user = self._create_user('user', is_staff=True)
        another_user = self._create_user('another_user', is_staff=True)

        page = create_page('A', 'nav_playground.html', 'en')
        admin_url = reverse("admin:cms_page_edit_title", args=(
            page.pk, 'en'
        ))
        page_admin = PageAdmin(Page, None)
        page_admin._current_page = page

        self.client.login(username=user.username, password=user.username)
        response = self.client.get(admin_url)
        self.assertEqual(response.status_code, HttpResponseForbidden.status_code)

        assign_user_to_page(page, user, grant_all=True)
        self.client.login(username=user.username, password=user.username)
        response = self.client.get(admin_url)
        self.assertEqual(response.status_code, HttpResponse.status_code)

        self._give_cms_permissions(another_user)
        self.client.login(username=another_user.username, password=another_user.username)
        response = self.client.get(admin_url)
        self.assertEqual(response.status_code, HttpResponse.status_code)
    def test_page_permission_inline_visibility(self):
        user = User(username='******', email='*****@*****.**', password='******',
                    is_staff=True)
        user.save()
        self._give_page_permission_rights(user)
        page = create_page('A', 'nav_playground.html', 'en')
        page_permission = PagePermission.objects.create(
            can_change_permissions=True, user=user, page=page)
        request = self._get_change_page_request(user, page)
        page_admin = PageAdmin(Page, None)
        page_admin._current_page = page
        # user has can_change_permission
        # => must see the PagePermissionInline
        self.assertTrue(
            any(type(inline) is PagePermissionInlineAdmin
                for inline in page_admin.get_inline_instances(request,
                                                              page if not DJANGO_1_4 else None)))

        page = Page.objects.get(pk=page.pk)
        # remove can_change_permission
        page_permission.can_change_permissions = False
        page_permission.save()
        request = self._get_change_page_request(user, page)
        page_admin = PageAdmin(Page, None)
        page_admin._current_page = page
        # => PagePermissionInline is no longer visible
        self.assertFalse(
            any(type(inline) is PagePermissionInlineAdmin
                for inline in page_admin.get_inline_instances(request,
                                                              page if not DJANGO_1_4 else None)))
    def test_edit_title_languages(self):
        language = "en"
        admin = self.get_admin()
        page = create_page('A', 'nav_playground.html', language)
        page_admin = PageAdmin(Page, None)
        page_admin._current_page = page
        page.publish()
        draft_page = page.get_draft_object()
        admin_url = reverse("admin:cms_page_edit_title", args=(
            draft_page.pk, language
        ))

        post_data = {
            'title': "A Title"
        }
        with self.login_user_context(admin):
            response = self.client.post(admin_url, post_data)
            draft_page = Page.objects.get(pk=page.pk).get_draft_object()
            self.assertTrue(draft_page.is_dirty())
Пример #4
0
 def setUp(self):
     self._createAdminUser()
     page = create_page('HOME', 'testing.html', 'en', published=True, in_navigation=True,
         created_by=self.user)
     self.placeholder = Placeholder.objects.create(slot='Main Content')
     self.placeholder.page_set.add(page)
     self.placeholder.save()
     self.request = self.get_request(language='en', page=page)
     self.admin_site = admin.sites.AdminSite()
     self.page_admin = PageAdmin(page, self.admin_site)
Пример #5
0
 def get_admin(self):
     """
     Returns a PageAdmin instance.
     """
     return PageAdmin(Page, admin.site)