Example #1
0
    def test_publishing_unpublishing_blog_post(self):
        self.login(self.BLOG_EDITOR_EMAIL)
        csrf_token = self.get_new_csrf_token()
        payload = {
            'change_dict': {
                'title': 'Sample Title',
                'content': '<p>Hello<p>',
                'tags': ['New lessons', 'Learners'],
                'thumbnail_filename': 'file.svg'
            },
            'new_publish_status': True
        }

        self.put_json('%s/%s' %
                      (feconf.BLOG_EDITOR_DATA_URL_PREFIX, self.blog_post.id),
                      payload,
                      csrf_token=csrf_token)
        blog_post_rights = blog_services.get_blog_post_rights(
            self.blog_post.id)
        self.assertTrue(blog_post_rights.blog_post_is_published)

        # Unpublishing blog post.
        csrf_token = self.get_new_csrf_token()
        payload = {'change_dict': {}, 'new_publish_status': False}
        self.put_json('%s/%s' %
                      (feconf.BLOG_EDITOR_DATA_URL_PREFIX, self.blog_post.id),
                      payload,
                      csrf_token=csrf_token)
        blog_post_rights = blog_services.get_blog_post_rights(
            self.blog_post.id)
        self.assertFalse(blog_post_rights.blog_post_is_published)
Example #2
0
    def test_deassign_user_from_all_blog_posts(self):
        blog_post_rights = (
            blog_services.get_blog_post_rights(self.blog_post_a_id))
        self.assertTrue(self.user_id_a in blog_post_rights.editor_ids)

        blog_services.deassign_user_from_all_blog_posts(self.user_id_a)

        updated_blog_post_rights = (
            blog_services.get_blog_post_rights(self.blog_post_a_id))
        self.assertFalse(self.user_id_a in updated_blog_post_rights.editor_ids)
Example #3
0
    def test_unpublish_blog_post(self):
        blog_services.update_blog_post(
            self.blog_post_a_id, self.change_dict_two)
        blog_services.publish_blog_post(self.blog_post_a_id)
        blog_post_rights = (
            blog_services.get_blog_post_rights(self.blog_post_a_id))
        self.assertTrue(blog_post_rights.blog_post_is_published)

        blog_services.unpublish_blog_post(self.blog_post_a_id)
        blog_post_rights = (
            blog_services.get_blog_post_rights(self.blog_post_a_id))
        self.assertFalse(blog_post_rights.blog_post_is_published)
Example #4
0
 def test_delete_blog_post(self):
     blog_services.delete_blog_post(self.blog_post_a_id)
     self.assertIsNone(blog_services.get_blog_post_rights(
         self.blog_post_a_id, strict=False))
     self.assertIsNone(blog_services.get_blog_post_by_id(
         self.blog_post_a_id, strict=False))
     self.assertIsNone(blog_services.get_blog_post_summary_by_id(
         self.blog_post_a_id, strict=False))
Example #5
0
 def test_save_blog_post_rights(self) -> None:
     blog_post_rights = blog_domain.BlogPostRights(
         self.blog_post_a_id, [self.user_id_a, self.user_id_b], False)
     blog_services.save_blog_post_rights(blog_post_rights)
     fetched_blog_post_rights = (blog_services.get_blog_post_rights(
         self.blog_post_a_id))
     self.assertEqual(blog_post_rights.to_dict(),
                      fetched_blog_post_rights.to_dict())
Example #6
0
    def test_publish_blog_post(self):
        blog_post_rights = (
            blog_services.get_blog_post_rights(self.blog_post_a_id))
        self.assertFalse(blog_post_rights.blog_post_is_published)

        blog_services.update_blog_post(
            self.blog_post_a_id, self.change_dict_two)
        blog_services.publish_blog_post(self.blog_post_a_id)
        blog_post_summary = (
            blog_services.get_blog_post_summary_by_id(self.blog_post_a_id))
        blog_post = blog_services.get_blog_post_by_id(self.blog_post_a_id)
        blog_post_rights = (
            blog_services.get_blog_post_rights(self.blog_post_a_id))

        self.assertTrue(blog_post_rights.blog_post_is_published)
        self.assertIsNotNone(blog_post.published_on)
        self.assertIsNotNone(blog_post_summary.published_on)
        self.assertEqual(
            blog_post.published_on, blog_post_summary.published_on)
Example #7
0
    def setUp(self):
        super(BlogPostRightsDomainUnitTests, self).setUp()
        self.signup('*****@*****.**', 'A')
        self.signup('*****@*****.**', 'B')

        self.user_id_a = self.get_user_id_from_email('*****@*****.**')
        self.user_id_b = self.get_user_id_from_email('*****@*****.**')

        blog_post = blog_services.create_new_blog_post(self.user_id_a)
        self.blog_post_id = blog_post.id
        self.blog_post_rights = (blog_services.get_blog_post_rights(
            self.blog_post_id))
Example #8
0
    def setUp(self) -> None:
        super(BlogPostRightsDomainUnitTests, self).setUp()
        self.signup('*****@*****.**', 'A')
        self.signup('*****@*****.**', 'B')

        self.user_id_a = self.get_user_id_from_email(
            '*****@*****.**')  # type: ignore[no-untyped-call]
        self.user_id_b = self.get_user_id_from_email(
            '*****@*****.**')  # type: ignore[no-untyped-call]

        blog_post = blog_services.create_new_blog_post(
            self.user_id_a)  # type: ignore[no-untyped-call]
        self.blog_post_id = blog_post.id
        self.blog_post_rights = (blog_services.get_blog_post_rights(
            self.blog_post_id))  # type: ignore[no-untyped-call]
Example #9
0
    def test_check_can_edit_blog_post(self):
        blog_post_rights = (
            blog_services.get_blog_post_rights(self.blog_post_a_id))
        user_info_a = user_services.get_user_actions_info(self.user_id_a)
        user_info_b = user_services.get_user_actions_info(self.user_id_b)

        self.assertFalse(blog_services.check_can_edit_blog_post(
            user_info_b, blog_post_rights))
        self.assertTrue(blog_services.check_can_edit_blog_post(
            user_info_a, blog_post_rights))
        self.assertFalse(blog_services.check_can_edit_blog_post(
            user_info_a, None))

        user_info_b.actions.append(u'EDIT_ANY_BLOG_POST')
        self.assertTrue(blog_services.check_can_edit_blog_post(
            user_info_b, blog_post_rights))
Example #10
0
    def test_create_new_blog_post(self):
        # Checks blog editor can create a new blog post.
        self.login(self.BLOG_EDITOR_EMAIL)
        csrf_token = self.get_new_csrf_token()
        json_response = self.post_json(
            '%s' % (feconf.BLOG_DASHBOARD_DATA_URL), {}, csrf_token=csrf_token)
        blog_post_id = json_response['blog_post_id']
        blog_post_rights = blog_services.get_blog_post_rights(blog_post_id)
        self.assertEqual(blog_post_rights.editor_ids, [self.blog_editor_id])
        self.logout()

        # Checks non blog-admins and non editors cannot create a new blog post.
        self.login(self.user_email)
        json_response = self.post_json(
            '%s' % (feconf.BLOG_DASHBOARD_DATA_URL), {},
            csrf_token=csrf_token, expected_status_int=401)
        self.logout()
Example #11
0
    def put(self, blog_post_id: str) -> None:
        """Updates properties of the given blog post."""
        blog_domain.BlogPost.require_valid_blog_post_id(blog_post_id)
        blog_post_rights = (blog_services.get_blog_post_rights(blog_post_id,
                                                               strict=False))
        blog_post_currently_published = blog_post_rights.blog_post_is_published
        change_dict = self.normalized_payload.get('change_dict')

        blog_services.update_blog_post(blog_post_id, change_dict)
        new_publish_status = self.normalized_payload.get('new_publish_status')
        if new_publish_status:
            blog_services.publish_blog_post(blog_post_id)
        elif blog_post_currently_published:
            blog_services.unpublish_blog_post(blog_post_id)

        blog_post_dict = (
            blog_services.get_blog_post_by_id(blog_post_id).to_dict())

        self.values.update({'blog_post': blog_post_dict})
        self.render_json(self.values)