Job:

Want to hire someone to make a module or hack, to allow users to edit or delete comments made to their own posts.

contact:

email me through the contact form
http://drupal.org/user/83124/contact

Comments

Delete Me-1’s picture

i just wrote this hack of the comments module for you -- patch your comments.module with this file and give the user group you want to be able to moderate their own nodes rights in the admin CP, i called it "administer comments in own node".

this is a patch against 4.7.4

good luck!

123c123
< 
---
>     $access = user_access('administer comments') || user_access('administer comments in own node');
153c153
<   return array('access comments', 'post comments', 'administer comments', 'post comments without approval');
---
>   return array('access comments', 'post comments', 'administer comments', 'post comments without approval', 'administer comments in own node');
444d443
< 
446c445,448
<     return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || user_access('administer comments');
---
>    return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || (user_access('administer comments in own node') && user_owns_node($comment->nid)) || user_access('administer comments');
>   }
>   if ($op == 'delete') {
>     return (user_access('administer comments in own node') && user_owns_node($comment->nid)) || user_access('administer comments');
665c667
<   global $user;
---
>   global $user, $user_owns_node;
675c677
<     if (user_access('administer comments') && user_access('post comments')) {
---
>     if ((user_access('administer comments') && user_access('post comments')) || (user_access('administer comments in own node') && user_owns_node($comment->nid))) {
876,877c878,881
< 
<   if (is_object($comment) && is_numeric($comment->cid)) {
---
>   if (!comment_access('delete', $comment)) {
> 	drupal_access_denied();
>   }
>   elseif (is_object($comment) && is_numeric($comment->cid)) {
1787a1792,1804
> 
> /*
>  * Returns true if current user created node $nid, false if not
>  */
> function user_owns_node($nid) {
>   static $cacheq;
>   global $user;
>   if (!isset($cacheq[$nid])) {
>     $cacheq[$nid] = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE nid = %d AND uid= %d", $nid, $user->uid), 0);
>   }
>   return $cacheq[$nid];
> }
> 
dwees’s picture

Hehehe, I looked at this last night and came up with some very similar stuff. I thought there might be a way to use the built in functionality of Drupal to handle user_owns_node. I suppose this is much better than doing a node_load (since you only want 1 field).

Dave

heine’s picture

A contributed module that allows users to edit / delete comments on nodes for which they have the update permission will become available this week.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

ms2011’s picture

Dunno what happened to the module that was supposedly coming out last year.
Here it is again, only for Drupal 5... (pretty much the same)

Index: modules/comment/comment.module
===================================================================
--- modules/comment/comment.module	(revision 570)
+++ modules/comment/comment.module	(working copy)
@@ -147,7 +147,7 @@
   $items = array();
 
   if ($may_cache) {
-    $access = user_access('administer comments');
+    $access = user_access('administer comments') || user_access('administer comments in own node');
     $items[] = array(
       'path' => 'admin/content/comment',
       'title' => t('Comments'),
@@ -212,7 +212,7 @@
  * Implementation of hook_perm().
  */
 function comment_perm() {
-  return array('access comments', 'post comments', 'administer comments', 'post comments without approval');
+  return array('access comments', 'post comments', 'administer comments', 'post comments without approval', 'administer comments in own node');
 }
 
 /**
@@ -575,8 +575,11 @@
   global $user;
 
   if ($op == 'edit') {
-    return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || user_access('administer comments');
+    return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || (user_access('administer comments in own node') && user_owns_node($comment->nid)) || user_access('administer comments');
   }
+  if ($op == 'delete') {
+    return (user_access('administer comments in own node') && user_owns_node($comment->nid)) || user_access('administer comments');
+  }
 }
 
 function comment_node_url() {
@@ -818,7 +821,7 @@
 }
 
 function comment_links($comment, $return = 1) {
-  global $user;
+  global $user, $user_owns_node;
 
   $links = array();
 
@@ -832,7 +835,7 @@
   }
 
   if (node_comment_mode($comment->nid) == COMMENT_NODE_READ_WRITE) {
-    if (user_access('administer comments') && user_access('post comments')) {
+   if ((user_access('administer comments') && user_access('post comments')) || (user_access('administer comments in own node') && user_owns_node($comment->nid))) {
       $links['comment_delete'] = array(
         'title' => t('delete'),
         'href' => "comment/delete/$comment->cid"
@@ -1090,7 +1093,10 @@
 
     drupal_goto("node/$comment->nid");
   }
-  else if (is_object($comment) && is_numeric($comment->cid)) {
+  else if (!comment_access('delete', $comment)) {
+		drupal_access_denied();
+	}
+	elseif (is_object($comment) && is_numeric($comment->cid)) {
     $output = drupal_get_form('comment_confirm_delete', $comment->subject, $comment->nid);
   }
   else {
@@ -2008,3 +2014,14 @@
   return base_convert(substr($c, 1), 36, 10);
 }
 
+/*
+ * Returns true if current user created node $nid, false if not
+ */
+function user_owns_node($nid) {
+  static $cacheq;
+  global $user;
+  if (!isset($cacheq[$nid])) {
+    $cacheq[$nid] = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE nid = %d AND uid= %d", $nid, $user->uid), 0);
+  }
+  return $cacheq[$nid];
+}
\ No newline at end of file

Mike Smullin
http://www.mikesmullin.com/

gwen’s picture

I just contributed a module to allow users to delete comments made to their nodes:
http://drupal.org/project/usercomment

I didn't add an edit link b/c my site didn't want it, but if i have some time, perhaps I'll make the module a bit more generic and have the links shown be a configurable option or something.

SlavviR’s picture

THANK YOU thank you BIG !

DineshBhatia’s picture

This Module allows the post(node) author to delete comments from his post.
What if I want to give same access to Group Admin. Is There any option or any module that helps us do this.

Thanks