def test_comment_replies_inherit_restrictions(self): """webcomment - a reply to a comment inherits restrictions""" # In this test we reply to a restricted comment, and check if # the restriction is inherited. However, in order to make sure # that the comment restriction is inherited, and not the # record restriction, we temporary change the restriction of # the parent. from invenio.modules.comments.api import query_add_comment_or_remark self.public_record_restr_comment original_restriction = run_sql("SELECT restriction FROM cmtRECORDCOMMENT WHERE id=%s", (self.restr_comid_2,))[0][0] restriction_to_inherit = 'juliet_only' run_sql("UPDATE cmtRECORDCOMMENT SET restriction=%s WHERE id=%s", (restriction_to_inherit, self.restr_comid_2)) # Reply to a restricted comment self.msg4 = "A test comment 4" prepare_attachments() self.restr_comid_3 = \ query_add_comment_or_remark(reviews=0, recID=self.public_record_restr_comment, uid=self.jekyll_uid, msg=self.msg4, editor_type='textarea', attached_files=self.attached_files, reply_to=self.restr_comid_2) inherited_restriction = run_sql("SELECT restriction FROM cmtRECORDCOMMENT WHERE id=%s", (self.restr_comid_3,))[0][0] self.assertEqual(restriction_to_inherit, inherited_restriction) # Restore original restriction run_sql("UPDATE cmtRECORDCOMMENT SET restriction=%s WHERE id=%s", (original_restriction, self.restr_comid_2))
def test_comment_replies_inherit_restrictions(self): """webcomment - a reply to a comment inherits restrictions""" # In this test we reply to a restricted comment, and check if # the restriction is inherited. However, in order to make sure # that the comment restriction is inherited, and not the # record restriction, we temporary change the restriction of # the parent. from invenio.modules.comments.api import query_add_comment_or_remark self.public_record_restr_comment original_restriction = run_sql( "SELECT restriction FROM cmtRECORDCOMMENT WHERE id=%s", (self.restr_comid_2, ))[0][0] restriction_to_inherit = 'juliet_only' run_sql("UPDATE cmtRECORDCOMMENT SET restriction=%s WHERE id=%s", (restriction_to_inherit, self.restr_comid_2)) # Reply to a restricted comment self.msg4 = "A test comment 4" prepare_attachments() self.restr_comid_3 = \ query_add_comment_or_remark(reviews=0, recID=self.public_record_restr_comment, uid=self.jekyll_uid, msg=self.msg4, editor_type='textarea', attached_files=self.attached_files, reply_to=self.restr_comid_2) inherited_restriction = run_sql( "SELECT restriction FROM cmtRECORDCOMMENT WHERE id=%s", (self.restr_comid_3, ))[0][0] self.assertEqual(restriction_to_inherit, inherited_restriction) # Restore original restriction run_sql("UPDATE cmtRECORDCOMMENT SET restriction=%s WHERE id=%s", (original_restriction, self.restr_comid_2))
def setUp(self): """Insert some comments in some records""" from invenio.modules.comments.api import query_add_comment_or_remark from invenio.legacy.webcomment.adminlib import query_delete_comment_auth # Comments have access restrictions when: # - the comment is in a restricted collection ('viewrestrcoll' action) # - the comment is in a restricted discussion page ('viewcomment' action) # - the comment itself is restricted ('viewrestrcomment' # action), either because of the markup of the record, or # because it is a reply to a restricted comment. self.public_record = 5 self.public_record_restr_comment = 6 self.restr_record = 42 self.restr_record_restr_comment = 41 self.restricted_discussion = 76 self.romeo_uid = 5 self.jekyll_uid = 2 self.attached_files = {'file1': cfg['CFG_TMPDIR'] + '/journal_water_dog.gif', 'file2': cfg['CFG_TMPDIR'] + '/invenio.css'} # Load content of texual file2 prepare_attachments() fp = file(self.attached_files['file2']) self.attached_file2_content = fp.read() fp.close() # Insert a public comment in a public record (public collection) self.msg1 = "A test comment 1" self.public_comid = query_add_comment_or_remark(reviews=0, recID=self.public_record, uid=self.romeo_uid, msg=self.msg1, editor_type='textarea', attached_files=self.attached_files) # Insert a public comment in a restricted record (restricted collection) self.msg2 = "A test comment 2" prepare_attachments() self.restr_comid_1 = \ query_add_comment_or_remark(reviews=0, recID=self.restr_record, uid=self.jekyll_uid, msg=self.msg2, editor_type='textarea', attached_files=self.attached_files) # Insert a restricted comment in a public collection self.msg3 = "A test comment 3" prepare_attachments() self.restr_comid_2 = \ query_add_comment_or_remark(reviews=0, recID=self.public_record_restr_comment, uid=self.jekyll_uid, msg=self.msg3, editor_type='textarea', attached_files=self.attached_files) # Insert a restricted comment, in a restricted collection self.msg5 = "A test comment 5" prepare_attachments() self.restr_comid_4 = \ query_add_comment_or_remark(reviews=0, recID=self.restr_record_restr_comment, uid=self.romeo_uid, msg=self.msg5, editor_type='textarea', attached_files=self.attached_files) # Insert a public comment in a restricted discussion self.msg6 = "A test comment 6" prepare_attachments() self.restr_comid_5 = \ query_add_comment_or_remark(reviews=0, recID=self.restricted_discussion, uid=self.romeo_uid, msg=self.msg6, editor_type='textarea', attached_files=self.attached_files) self.restr_comid_3 = None # Insert a public, deleted comment in a public record (public collection) self.msg7 = "A test comment 7" prepare_attachments() self.deleted_comid = query_add_comment_or_remark(reviews=0, recID=self.public_record, uid=self.romeo_uid, msg=self.msg7, editor_type='textarea', attached_files=self.attached_files) query_delete_comment_auth(self.deleted_comid)
def setUp(self): """Insert some comments in some records""" from invenio.modules.comments.api import query_add_comment_or_remark from invenio.legacy.webcomment.adminlib import query_delete_comment_auth # Comments have access restrictions when: # - the comment is in a restricted collection ('viewrestrcoll' action) # - the comment is in a restricted discussion page ('viewcomment' action) # - the comment itself is restricted ('viewrestrcomment' # action), either because of the markup of the record, or # because it is a reply to a restricted comment. self.public_record = 5 self.public_record_restr_comment = 6 self.restr_record = 42 self.restr_record_restr_comment = 41 self.restricted_discussion = 76 self.romeo_uid = 5 self.jekyll_uid = 2 self.attached_files = { 'file1': cfg['CFG_TMPDIR'] + '/journal_water_dog.gif', 'file2': cfg['CFG_TMPDIR'] + '/invenio.css' } # Load content of texual file2 prepare_attachments() fp = file(self.attached_files['file2']) self.attached_file2_content = fp.read() fp.close() # Insert a public comment in a public record (public collection) self.msg1 = "A test comment 1" self.public_comid = query_add_comment_or_remark( reviews=0, recID=self.public_record, uid=self.romeo_uid, msg=self.msg1, editor_type='textarea', attached_files=self.attached_files) # Insert a public comment in a restricted record (restricted collection) self.msg2 = "A test comment 2" prepare_attachments() self.restr_comid_1 = \ query_add_comment_or_remark(reviews=0, recID=self.restr_record, uid=self.jekyll_uid, msg=self.msg2, editor_type='textarea', attached_files=self.attached_files) # Insert a restricted comment in a public collection self.msg3 = "A test comment 3" prepare_attachments() self.restr_comid_2 = \ query_add_comment_or_remark(reviews=0, recID=self.public_record_restr_comment, uid=self.jekyll_uid, msg=self.msg3, editor_type='textarea', attached_files=self.attached_files) # Insert a restricted comment, in a restricted collection self.msg5 = "A test comment 5" prepare_attachments() self.restr_comid_4 = \ query_add_comment_or_remark(reviews=0, recID=self.restr_record_restr_comment, uid=self.romeo_uid, msg=self.msg5, editor_type='textarea', attached_files=self.attached_files) # Insert a public comment in a restricted discussion self.msg6 = "A test comment 6" prepare_attachments() self.restr_comid_5 = \ query_add_comment_or_remark(reviews=0, recID=self.restricted_discussion, uid=self.romeo_uid, msg=self.msg6, editor_type='textarea', attached_files=self.attached_files) self.restr_comid_3 = None # Insert a public, deleted comment in a public record (public collection) self.msg7 = "A test comment 7" prepare_attachments() self.deleted_comid = query_add_comment_or_remark( reviews=0, recID=self.public_record, uid=self.romeo_uid, msg=self.msg7, editor_type='textarea', attached_files=self.attached_files) query_delete_comment_auth(self.deleted_comid)