Commits

Georg Brandl committed c4bcb55

Support complete comment deletion.

Comments (0)

Files changed (4)

sphinx/themes/basic/static/websupport.js

       data: {id: id},
       success: function(data, textStatus, request) {
         var div = $('#cd' + id);
+        if (data == 'delete') {
+          // Moderator mode: remove the comment and all children immediately
+          div.slideUp('fast', function() {
+            div.remove();
+          });
+          return;
+        }
+        // User mode: only mark the comment as deleted
         div
           .find('span.user-id:first')
           .text('[deleted]').end()
         addComment($('#rf' + id));
         closeReply(id);
       });
-    div.slideDown('fast');
+    div.slideDown('fast', function() {
+      $('#rf' + id).find('textarea').focus();
+    });
   }
 
   /**
       div.find('#' + direction + 'u' + comment.id).show();
     }
 
-    if (comment.text != '[deleted]') {
+    if (opts.moderator || comment.text != '[deleted]') {
       div.find('a.reply').show();
       if (comment.proposal_diff)
         div.find('#sp' + comment.id).show();
       <p class="add-a-comment">Add a comment\
         (<a href="#" class="comment-markup" id="ab<%id%>">markup</a>):</p>\
       <div class="comment-markup-box" id="mb<%id%>">\
-        Comment markup: </div>\
+        reStructured text markup: <i>*emph*</i>, <b>**strong**</b>, \
+        <tt>``code``</tt>, \
+        code blocks: <tt>::</tt> and an indented block after blank line</div>\
       <form method="post" id="cf<%id%>" class="comment-form" action="">\
         <textarea name="comment" cols="80"></textarea>\
         <p class="propose-button">\

sphinx/websupport/__init__.py

         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.
+        """Delete a comment.
 
-        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.
+        If `moderator` is True, the comment and all descendants will be deleted
+        from the database, and the function returns ``True``.
+
+        If `moderator` is False, the comment will be marked as deleted (but not
+        removed from the database so as not to leave any comments orphaned), but
+        only if the `username` matches the `username` on the comment.  The
+        username and text files are replaced with "[deleted]" .  In this case,
+        the function returns ``False``.
 
         This raises :class:`~sphinx.websupport.errors.UserNotAuthorizedError`
         if moderator is False and `username` doesn't match username on the
         :param username: the username requesting the deletion.
         :param moderator: whether the requestor is a moderator.
         """
-        self.storage.delete_comment(comment_id, username, moderator)
+        return self.storage.delete_comment(comment_id, username, moderator)
 
     def add_comment(self, text, node_id='', parent_id='', displayed=True,
                     username=None, time=None, proposal=None,

sphinx/websupport/storage/sqlalchemy_db.py

 
     def nested_comments(self, username, moderator):
         """Create a tree of comments. First get all comments that are
-        descendents of this node, then convert them to a tree form.
+        descendants of this node, then convert them to a tree form.
 
         :param username: the name of the user to get comments for.
         :param moderator: whether the user is moderator.
         # Filter out all comments not descending from this node.
         q = q.filter(Comment.path.like(str(self.id) + '.%'))
 
+        # Filter out all comments that are not moderated yet.
         if not moderator:
             q = q.filter(Comment.displayed == True)
 

sphinx/websupport/storage/sqlalchemystorage.py

         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()
 
     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()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.