mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
added delete_comment method
This commit is contained in:
parent
f58fe6eed6
commit
69a2c07396
@ -85,7 +85,7 @@ class WebSupport(object):
|
||||
"""Build the documentation. Places the data into the `outdir`
|
||||
directory. Use it like this::
|
||||
|
||||
support = WebSupport(srcdir, outdir, search)
|
||||
support = WebSupport(srcdir, outdir, search='xapian')
|
||||
support.build()
|
||||
|
||||
This will read reStructured text files from `srcdir`. Then it
|
||||
@ -109,7 +109,7 @@ class WebSupport(object):
|
||||
"""Load and return a document from a pickle. The document will
|
||||
be a dict object which can be used to render a template::
|
||||
|
||||
support = WebSupport(outdir=outdir)
|
||||
support = WebSupport(datadir=datadir)
|
||||
support.get_document('index')
|
||||
|
||||
In most cases `docname` will be taken from the request path and
|
||||
@ -193,6 +193,21 @@ class WebSupport(object):
|
||||
"""
|
||||
return self.storage.get_data(node_id, username, moderator)
|
||||
|
||||
def delete_comment(self, comment_id, username='', moderator=False):
|
||||
"""Delete a comment. Doesn't actually delete the comment, but
|
||||
instead replaces the username and text files with "[deleted]" so
|
||||
as not to leave any comments orphaned.
|
||||
|
||||
If `moderator` is True, the comment will always be deleted. If
|
||||
`moderator` is False, the comment will only be deleted if the
|
||||
`username` matches the `username` on the comment.
|
||||
|
||||
:param comment_id: the id of the comment to delete.
|
||||
:param username: the username requesting the deletion.
|
||||
:param moderator: whether the requestor is a moderator.
|
||||
"""
|
||||
self.storage.delete_comment(comment_id, username, moderator)
|
||||
|
||||
def add_comment(self, text, node_id='', parent_id='', displayed=True,
|
||||
username=None, rating=0, time=None, proposal=None,
|
||||
moderator=False):
|
||||
|
@ -9,7 +9,8 @@
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
__all__ = ['DocumentNotFoundError', 'SrcdirNotSpecifiedError']
|
||||
__all__ = ['DocumentNotFoundError', 'SrcdirNotSpecifiedError',
|
||||
'UserNotAuthorizedError']
|
||||
|
||||
class DocumentNotFoundError(Exception):
|
||||
pass
|
||||
@ -17,3 +18,7 @@ class DocumentNotFoundError(Exception):
|
||||
|
||||
class SrcdirNotSpecifiedError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UserNotAuthorizedError(Exception):
|
||||
pass
|
||||
|
@ -79,11 +79,13 @@ def test_comments(support):
|
||||
|
||||
# Create a displayed comment and a non displayed comment.
|
||||
comment = support.add_comment('First test comment',
|
||||
node_id=str(first_node.id))
|
||||
node_id=str(first_node.id),
|
||||
username='user_one')
|
||||
support.add_comment('Hidden comment', node_id=str(first_node.id),
|
||||
displayed=False)
|
||||
# Add a displayed and not displayed child to the displayed comment.
|
||||
support.add_comment('Child test comment', parent_id=str(comment['id']))
|
||||
support.add_comment('Child test comment', parent_id=str(comment['id']),
|
||||
username='user_one')
|
||||
support.add_comment('Hidden child test comment',
|
||||
parent_id=str(comment['id']), displayed=False)
|
||||
# Add a comment to another node to make sure it isn't returned later.
|
||||
@ -144,8 +146,7 @@ def test_voting(support):
|
||||
@with_support()
|
||||
def test_proposals(support):
|
||||
session = Session()
|
||||
nodes = session.query(Node).all()
|
||||
node = nodes[0]
|
||||
node = session.query(Node).first()
|
||||
|
||||
data = support.get_data(str(node.id))
|
||||
|
||||
@ -156,6 +157,43 @@ def test_proposals(support):
|
||||
node_id=str(node.id),
|
||||
proposal=proposal)
|
||||
|
||||
|
||||
@with_support()
|
||||
def test_user_delete_comments(support):
|
||||
def get_comment():
|
||||
session = Session()
|
||||
node = session.query(Node).first()
|
||||
session.close()
|
||||
return support.get_data(str(node.id))['comments'][0]
|
||||
|
||||
comment = get_comment()
|
||||
assert comment['username'] == 'user_one'
|
||||
# Make sure other normal users can't delete someone elses comments.
|
||||
raises(UserNotAuthorizedError, support.delete_comment,
|
||||
comment['id'], username='user_two')
|
||||
# Now delete the comment using the correct username.
|
||||
support.delete_comment(comment['id'], username='user_one')
|
||||
comment = get_comment()
|
||||
assert comment['username'] == '[deleted]'
|
||||
assert comment['text'] == '[deleted]'
|
||||
|
||||
|
||||
@with_support()
|
||||
def test_moderator_delete_comments(support):
|
||||
def get_comment():
|
||||
session = Session()
|
||||
node = session.query(Node).first()
|
||||
session.close()
|
||||
return support.get_data(str(node.id), moderator=True)['comments'][1]
|
||||
|
||||
comment = get_comment()
|
||||
support.delete_comment(comment['id'], username='user_two',
|
||||
moderator=True)
|
||||
comment = get_comment()
|
||||
assert comment['username'] == '[deleted]'
|
||||
assert comment['text'] == '[deleted]'
|
||||
|
||||
|
||||
def test_differ():
|
||||
differ = CombinedHtmlDiff()
|
||||
source = 'Lorem ipsum dolor sit amet,\nconsectetur adipisicing elit,\n' \
|
||||
|
Loading…
Reference in New Issue
Block a user