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
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
This relies on somebody submitting code to work around the "delete one comment in a thread without destroying the whole thread" problem.
#3
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
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
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
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
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
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
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
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.
#11
5.x is feature frozen.
#12
@spatz4000: but the problem it still alive. I solved it for my own site... maybe, someone else will found this code useful =)
#13
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 callcomment_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
With patch.
#15
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
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
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
#19
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
Moving back to CNR to try and get another person or two to provide feedback on what I reported.
#21
Is this patch tested and working on Drupal 6.6?
#22
probably not, as things are generally fixed in the latest version and then backported back.
#23
The last submitted patch failed testing.
#24
n/m
#25
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
@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
True, on 6.x users can't delete their own comments.
In which # I'll find patch for 6.x?
#28
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
Subscribing. It' be very useful for my users (on Drupal 6.x)
#30
Any hopes for backporting patch to 6 soon?
#31
+1
#32
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
I was thinking that if this feature will be eventually implemented it should require flatcomments module to be present
#34
+1
I need threaded discussions, but forbidding deletion after there is a reply is OK.
#35
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
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?