Updated: Comment #44

Problem/Motivation

Users cannot delete their own comments if they do not have permission to delete comments. Allowing users to unconditionally edit/delete their comments can lead to broken or incomprehensible threads if users change their original posts once other users have replied to them.

Preventing users from deleting comments at all leads to a few issues:

- Duplicate posts cannot be removed by end-users
- Users expect to be able to delete comments that they have very recently posted

Proposed resolution

Allow comments to be configured so that users can delete their own comments if no further replies have been posted to the thread that may be in response to that comment.

Remaining tasks

- Decide whether this behaviour should be default, controlled globally by permissions or a combination of permissions and field level configuration
- Patch
- Followup issue: Allowing users to "delete" comments that have replies by replacing the body of the comment with a "this comment has been deleted" notice
- Followup issue: Allow editing of comments without replies
- Followup issue: Ability to "flatten" threaded comments

User interface changes

Users will see a link that allows them to delete comments that have no replies.

API changes

It's possible a new permission will be added to manage the new behaviour.

Original report by @ixis.dylan

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).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jakeg’s picture

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?

ixis.dylan’s picture

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

Wesley Tanaka’s picture

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.

pfaocle’s picture

Title: Ability to delete own comments before reply is added » Delete own comments
Version: 5.5 » x.y.z
Status: Needs review » Active

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.

webchick’s picture

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.

Wesley Tanaka’s picture

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.

dan_aka_jack’s picture

Title: Ability to delete own comments before reply is added » Delete own comments
Version: 7.x-dev » x.y.z
Status: Needs work » Active

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.

dan_aka_jack’s picture

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.

geodaniel’s picture

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.

gildedgod’s picture

Version: 7.x-dev » 5.5
Status: Active » Needs review
FileSize
2.07 KB

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.

StevenPatz’s picture

5.x is feature frozen.

gildedgod’s picture

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

nedjo’s picture

Title: Delete own comments » Ability to delete own comments before reply is added
Version: x.y.z » 7.x-dev
Status: Active » Needs review

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.

nedjo’s picture

FileSize
8.62 KB

With patch.

taqwa’s picture

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

drawk’s picture

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.

beeradb’s picture

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.

beeradb’s picture

Status: Needs review » Needs work
drawk’s picture

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?

beeradb’s picture

Status: Needs work » Needs review

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

JaccoViljoen’s picture

Version: 7.x-dev » 6.6

Is this patch tested and working on Drupal 6.6?

StevenPatz’s picture

Version: 6.6 » 7.x-dev

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

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

jyg’s picture

n/m

gildedgod’s picture

Title: Delete own comments » Ability to delete own comments before reply is added
Version: x.y.z » 7.x-dev
Status: Active » Needs work

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

Dave Reid’s picture

@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.

kenorb’s picture

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

VM’s picture

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.

Ingumsky’s picture

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

v8powerage’s picture

Any hopes for backporting patch to 6 soon?

k3vin’s picture

+1

DjC4’s picture

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.

v8powerage’s picture

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

jsgammato’s picture

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

andrenoronha’s picture

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?

andrenoronha’s picture

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?

dixon_’s picture

Version: 7.x-dev » 8.x-dev
ShadowMonster’s picture

I use Comment Access for D7 and would like also let users delete own comments meaningless to with node are attached

subscribe

Media Crumb’s picture

Any news on this. Going against almost all other forum software on the planet is just plain silly.

mototribe’s picture

The comment goodness module promises to do just that: http://drupal.org/node/1540924

marthinal’s picture

Status: Needs work » Needs review
FileSize
7.7 KB

This is a very old issue so I added a patch + test where we have a permission to delete own comment only if this comment hasn't a reply.

mototribe’s picture

I'm using a "soft delete" feature where I unpublish a comment rather than deleting it. Any comment can be soft deleted, even with replies.

ceardach’s picture

I started to review the patch in comment 41 by marthinal, but it just ended up with me thinking about a lot of the issues here, so I'm going to just throw in my recommendations of how this should be handled.

First of all, I do believe this should be handled in core. I started thinking about how to do it "right" and it would be best to work directly with the comment system itself instead of trying to layer on top of it.

I also believe that a full solution to this problem will need two permissions: delete any own comments, and delete own unreplied-to comments. It can be argued that people who want to delete their comments that are at a tail of a thread can do that. It can also be argued that once someone has replied, that comment should be permanent. And it can be argued that even if someone has replied to a comment, the original can be deleted if desired. Adding these two delete-comment permissions will give site builders decent flexibility to choose what is best for them.

Deleting comments at the tail of a thread is technically easier to do, which marthinal has provided a patch for. As for deleting a comment that has replies, I have seen others implement that as replacing the entire comment with a [deleted] note, and all replies are threaded underneath. Example:

  • Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    • [deleted]
      • Proin sit amet nibh eu turpis malesuada posuere in quis lorem.
      • Ut tincidunt quam eget risus euismod non dapibus elit porttitor.
    • Pellentesque vitae turpis in purus elementum iaculis at non lorem.
  • Donec tempus eleifend euismod.

I recommend using the [deleted] method. The next thing to consider is if the user should still be associated with the deleted comment or not -- and I would recommend having that as a global toggle display option, while the user remains associated with the deleted comment in the database.

Also, I think there needs to be some thought around the UX when people can delete some of their comments and not others (such as in the case of preventing the delete when the comment has replies). In that case, I think the "delete" should show up in the list of links, but it should provide a message that deleting is prevented due to the replies (e.g.: a "disabled link" with hover help text).

Marthinal's patch does not satisfy all needs of this problem, but it's a good step forward.

thedavidmeister’s picture

Issue summary: View changes
Status: Needs review » Active
Issue tags: +Core Review Bonus

Ok, so I've read over this thread.

Firstly, @ceardack, you should have set this to "needs work" as your review presents a few valid points that need following up. The idea of replacing comments with a [deleted] note should be a followup issue, really.

Secondly, I disagree that this should be a global permission and should be more configurable than that - most likely at the field level now that Comments settings are a field - https://drupal.org/node/2100015

I'm setting this to "active" so that there can be further discussion about what should actually be included in the patch.

Thirdly, patch no longer applies:

error: patch failed: core/modules/comment/comment.module:294
error: core/modules/comment/comment.module: patch does not apply
error: patch failed: core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php:168
error: core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php: patch does not apply

I've updated the issue summary.

I like this idea so I'm going to give it a #2094585: [policy, no patch] Core review bonus tag from this review, so hopefully if we get a new patch this issue won't languish un-reviewed for another full year.

ixis.dylan’s picture

andypost’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Active » Postponed

Looks this feature is not very popular, anyway 8.0.x closed for features

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

XLD’s picture

I was shocked to find out today that users cannot delete their own comments so I stumbled across this thread. As some of you have mentioned, I believe simply changing the content of the comment to "This comment has been deleted." and same for the author of the comment (in case the commenter does no longer wish to be associated to the comment) is more than a decent solution. This way the existing threads will not loose their logic. For unthreaded comments, the comment can be deleted completely I suppose.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

chucksimply’s picture

Status: Postponed » Active

Setting the issue to active to hopefully revive some interest and traction on the patch. With the number of sites using comments these days, it seems neccesary to have some sort of "delete own comment" functionality.

Can we start with some simple logic?

If a user deletes their own comment and...

  • Comment is unthreaded (no replys) - Comment should be deleted
  • Comment is threaded (has replys) - Comment text should change to [deleted] (or something similar)

Thoughts?

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.