summaryrefslogtreecommitdiff
path: root/sphinx/websupport/storage/sqlalchemystorage.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-11-21 13:17:11 +0100
committerGeorg Brandl <georg@python.org>2010-11-21 13:17:11 +0100
commitbdf27419e46bc005de470207fdecd4a07a1c8e57 (patch)
treef43e39134f78da338e4874bf7af118de80f43776 /sphinx/websupport/storage/sqlalchemystorage.py
parent69713fb26d028dcbd43708f9bd156edf8ba705b2 (diff)
downloadsphinx-git-bdf27419e46bc005de470207fdecd4a07a1c8e57.tar.gz
Support complete comment deletion.
Diffstat (limited to 'sphinx/websupport/storage/sqlalchemystorage.py')
-rw-r--r--sphinx/websupport/storage/sqlalchemystorage.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/sphinx/websupport/storage/sqlalchemystorage.py b/sphinx/websupport/storage/sqlalchemystorage.py
index 6f13c91b6..a83c7623f 100644
--- a/sphinx/websupport/storage/sqlalchemystorage.py
+++ b/sphinx/websupport/storage/sqlalchemystorage.py
@@ -88,12 +88,23 @@ class SQLAlchemyStorage(StorageBackend):
session = Session()
comment = session.query(Comment).\
filter(Comment.id == comment_id).one()
- if moderator or comment.username == username:
+ if moderator:
+ # moderator mode: delete the comment and all descendants
+ # find descendants via path
+ session.query(Comment).filter(
+ Comment.path.like(comment.path + '.%')).delete(False)
+ session.delete(comment)
+ session.commit()
+ session.close()
+ return True
+ elif comment.username == username:
+ # user mode: do not really delete, but remove text and proposal
comment.username = '[deleted]'
comment.text = '[deleted]'
comment.proposal = ''
session.commit()
session.close()
+ return False
else:
session.close()
raise UserNotAuthorizedError()
@@ -154,20 +165,16 @@ class SQLAlchemyStorage(StorageBackend):
def accept_comment(self, comment_id):
session = Session()
-
- # XXX assignment to "comment" needed?
- comment = session.query(Comment).filter(
- Comment.id == comment_id).update(
- {Comment.displayed: True})
+ session.query(Comment).filter(Comment.id == comment_id).update(
+ {Comment.displayed: True}
+ )
session.commit()
session.close()
def reject_comment(self, comment_id):
session = Session()
-
- comment = session.query(Comment).\
- filter(Comment.id == comment_id).one()
+ comment = session.query(Comment).filter(Comment.id == comment_id).one()
session.delete(comment)
session.commit()