Ability to delete own comments before reply is added

leafish_dylan - September 10, 2004 - 01:03
Project:Drupal
Version:7.x-dev
Component:comment.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

It would be great if users could delete their own comments. It would reduce the number of double-posts and is expected by a lot of forum users.

A feature request for this feature request would be a configurable time limit after which comments can no longer be deleted (or edited).

#1

jakeg - July 17, 2005 - 13:11

I agree. My users who've migrated from vBulletin want the 'delete post' (i.e. delete own comments) ability. This should/could be added as an access control permission?

#2

leafish_dylan - July 17, 2005 - 23:07

This relies on somebody submitting code to work around the "delete one comment in a thread without destroying the whole thread" problem.

#3

Wesley Tanaka - November 23, 2005 - 19:29

Perhaps... Or more simply for a lot of forums some kind of comment flattening procedure, which would remove threading from comments before doing this kind of operation. On my site, the UI for replying to a comment (instead of the first forum post directly) isn't even exposed, so I'm pretty confident that all my forum posts don't have any threading in their replies.

#4

leafish_paul - June 24, 2008 - 19:58

Not really a viable solution, in my opinion: surely site maintainers would want threaded, um, threads to stay threaded?

The ideal would be to join any child comments of a deleted comment to its parent.

#5

webchick - November 23, 2005 - 23:22

An interim solution could be to allow users to delete comments with no threads beneath them (there should be a separate permission for this). If the comment has children, then delete is forbidden apart from administrators.

Or, use JavaScript to disable the submit button upon clicking it to try and prevent double-posts. I'm not crazy about a JS solution but I've seen it used in other software packages.

#6

Wesley Tanaka - November 24, 2005 - 06:04

Not really a viable solution, in my opinion: surely site maintainers would want threaded, um, threads to stayed threaded?

I certainly don't want that for comments on forum posts. I in fact went through some effort to try to prevent people from creating threaded comments on forum posts. And I think this probably holds for some sizeable fraction of site admins that want forums on their site. For my forums, a flattening procedure would be nice independent of whether or not an editor could delete a comment, as I've just installed quote.module, which appears to have again exposed a link through which someone can create a reply to a comment instead of to the node.

#7

dan_aka_jack - February 2, 2009 - 11:26

We too went to some effort to "flattern" our forums: ukfilm.org/forum

I agree that, in my experience, the vast majority of forums are flat. Personally, I think threading-within-a-thread is messy and should be disabled by default. Half the users on a threaded forum probably don't understand that they're posting to a thread-within-a-thread instead of the main thread.

Personally, I think it's a _good_ idea to let users delete duplicates but I think it's a _bad_ idea to let users delete any other sort of post. Sometimes, especially in heated arguments, immoral users have been known to manipulate what they said earlier in the conversation.

#8

dan_aka_jack - March 19, 2006 - 11:57

First off: I must correct a typo in my post above.

Instead of "I think it's a _good_ idea to let users duplicates" I meant to type "I think it's a good idea to let users delete duplicates..." (sorry for the typo)

Instead of allowing users to delete "normal" posts, I have submitted a new issue suggesting that we let users edit comments for up to an hour after posting. This would allow the correction of typos but would prevent users from editing previous comments if the discussion gets heated.

#9

geodaniel - December 20, 2007 - 14:52
Title:Delete own comments» Ability to delete own comments before reply is added
Version:x.y.z» 7.x-dev

I think the first step for this should just be to add a permission to allow people to delete their own comments as long as there have been no subsequent replies added as children to that comment.

#10

gildedgod - June 24, 2008 - 18:25
Version:7.x-dev» 5.5
Status:active» needs review

Solved for Drupal 5.5

// $Id: comment.module,v 1.520.2.12 2007/11/07 08:03:30 drumm Exp $

--- comment.old.module 2008-06-24 22:48:24.000000000 +0500
+++ comment.new.module 2008-06-24 23:10:50.000000000 +0500
@@ -205,6 +205,11 @@ function comment_menu($may_cache) {
     }
   }

+  $access = user_access('post comments');
+  $items[] = array('path' => 'comment/delete_own', 'title' => t('Delete own comment'),
+    'callback' => 'comment_delete_own',
+    'access' => $access, 'type' => MENU_CALLBACK);
+
   return $items;
}

@@ -577,6 +582,11 @@ function comment_access($op, $comment) {
   if ($op == 'edit') {
     return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || user_access('administer comments');
   }
+
+  if ($op == 'delete') {
+    return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0);
+  }
+
}

function comment_node_url() {
@@ -832,6 +842,15 @@ function comment_links($comment, $return
   }

   if (node_comment_mode($comment->nid) == COMMENT_NODE_READ_WRITE) {
+    if ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) {
+      $links['comment_delete_own'] = array(
+        'title' => t('delete'),
+        'href' => "comment/delete_own/$comment->cid"
+      );
+    }
+  }
+
+  if (node_comment_mode($comment->nid) == COMMENT_NODE_READ_WRITE) {
     if (user_access('administer comments') && user_access('post comments')) {
       $links['comment_delete'] = array(
         'title' => t('delete'),
@@ -1086,6 +1105,25 @@ function comment_delete($cid = NULL) {
   return $output;
}

+function comment_delete_own($cid) {
+  global $user;
+
+  $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid));
+  $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
+
+  $output = '';
+
+  if (comment_access('delete', $comment)) {
+    $output = drupal_get_form('comment_confirm_delete', $comment);
+  } else {
+    drupal_access_denied();
+  }
+
+  return $output;
+}
+
+
+
function comment_confirm_delete($comment) {

   $form = array();

> Adds a permission to allow people to delete their own comments as long as there have been no subsequent replies added as children to that comment.

The way I do it:

1) add a new link to comments ("comment_delete_own" links to "comment/delete_own/$comment->cid") where user is author of comment and there is no replies

2) add page callback ("comment_delete_own" on "comment/delete_own/") for users with "post comments'" permission calls to "comment_delete_own" function

3) add function "comment_delete_own", which checks that user is author of comment and there is no replies. If it is so - evaluates standard admin comment deletion procedure by executing confirm dialog "comment_confirm_delete"

Code needs review.

AttachmentSizeStatusTest resultOperations
comment.patch2.07 KBIdleFailed: Failed to apply patch.View details | Re-test

#11

spatz4000 - June 24, 2008 - 18:55

5.x is feature frozen.

#12

gildedgod - June 24, 2008 - 19:26

@spatz4000: but the problem it still alive. I solved it for my own site... maybe, someone else will found this code useful =)

#13

nedjo - June 25, 2008 - 15:36
Version:5.5» 7.x-dev

Here's an untested patch for HEAD.

Approach:

* Introduce a new delete op in comment_access(), which works the same as the existing edit one--users can delete their own comments provided there are no replies.

* In comment_menu(), follow the same approach for delete as for edit. That is, everyone with 'post comment' permission has access to the menu item but in the callback we load the comment and test for access.

* Move comment_delete() and related functions from comment.admin.inc to comment.pages.inc because the are now accessed by non-admins.

* Adapt comment_delete() to call comment_access() to test for delete access.

* In the delete confirm for and confirmation submit handler, customize messaging according to whether user has administer 'comments' permission and hence is able to delete threads.

#14

nedjo - June 25, 2008 - 15:37

With patch.

AttachmentSizeStatusTest resultOperations
comment-delete-own.patch8.62 KBIdleFailed: 7185 passes, 2 fails, 0 exceptionsView details | Re-test

#15

taqwa - August 24, 2008 - 04:26

Hey gilded!

Thanks for this wonderful patch. The only problem is that I get a white screen once the comment has been deleted. Do you have this issue as well? If so, any idea on how I can fix it?

Thanks

#16

drawk - September 7, 2008 - 20:38

Patch still applies with offset. I didn't experience any of the white screen problems mentioned by Lukas2000 while testing.

Worked as described. I was able to delete comments as an authenticated user, so long as there were no replies to that comment. Deleting all replies to a comment (as admin) makes the original comment delete-able again by the poster, just as it seems it should.

#17

beeradb - September 7, 2008 - 23:32

Just tested, and my initial comment threw an error.

To reproduce:
1). Get a clean installation of drupal with this patch installed.
2). Create a page, with comments set to Read/Write.
3). Post a comment to the page you've just created.
4). Click the delete link.
5). Get presented with a Page not found error.

#18

beeradb - September 7, 2008 - 23:32
Status:needs review» needs work

#19

drawk - September 7, 2008 - 23:47

Hmm, I am unable to reproduce the page not found error on my side, following exactly those steps
(fresh checkout of HEAD, create a page, comments set to Read/Write, post a comment, click delete link). I get re-directed back to the node with my comment deleted.

Anyone else willing to take this for a spin?

#20

beeradb - September 9, 2008 - 06:18
Status:needs work» needs review

Moving back to CNR to try and get another person or two to provide feedback on what I reported.

#21

JaccoViljoen - October 23, 2008 - 16:14
Version:7.x-dev» 6.6

Is this patch tested and working on Drupal 6.6?

#22

spatz4000 - October 23, 2008 - 17:14
Version:6.6» 7.x-dev

probably not, as things are generally fixed in the latest version and then backported back.

#23

Anonymous (not verified) - November 11, 2008 - 08:30
Status:needs review» needs work

The last submitted patch failed testing.

#24

jyg - December 12, 2008 - 06:47

n/m

#25

gildedgod - February 2, 2009 - 21:23

Because this issue became relevant to drupal 7, I moved my own patch for drupal 5.x to another node: http://drupal.org/node/350488

#26

Dave Reid - December 23, 2008 - 20:22

@gildedgod That's just how the issue queues work. Feature requests are only accepted into the development version of Drupal, 7.x. You can post a patch for others to use, but unless it is a critical bug fix, it usually will not get accepted for D5 or D6.

#27

kenorb - January 11, 2009 - 02:41

True, on 6.x users can't delete their own comments.
In which # I'll find patch for 6.x?

#28

VM - March 3, 2009 - 13:33

There is no patch for Drupal 6.x in this thread. A patch will be created for Drupal 7.x. If the desired functionality is found to work as expected and if it can be, it will be back ported to Drupal 6.x.

#29

Ingumsky - March 9, 2009 - 21:33

Subscribing. It' be very useful for my users (on Drupal 6.x)

#30

-Shaman- - April 19, 2009 - 21:16

Any hopes for backporting patch to 6 soon?

#31

bit7 - May 3, 2009 - 13:55

+1

#32

DjC4 - July 6, 2009 - 11:02

Would love a patch for this on six. My comments and forums have been flattened. So when I delete one comment it won't delete all comments related to it or after it. I'd love to give users the ability to delete their own posts.

#33

-Shaman- - July 2, 2009 - 14:01

I was thinking that if this feature will be eventually implemented it should require flatcomments module to be present

#34

jsgammato - October 13, 2009 - 00:44

+1
I need threaded discussions, but forbidding deletion after there is a reply is OK.

#35

a.luiz.n - December 18, 2009 - 16:22

I use usercomments to let the node owner to delete the comments to the node. but i'd like to let the author of the comment to delete it....

is it possible in drupal 6?

#36

a.luiz.n - December 18, 2009 - 16:39

i installed the module comment delete, gave the right permissions (delete own comment to authenticated user) but i still get the access denied page....
any idea?

 
 

Drupal is a registered trademark of Dries Buytaert.