I must get this working. It's been one of the biggest selling points on my site... manage your own comments.

I've been hacking at comments.module and I've got the "edit" and "delete" links to show up by changing code around line 184.

Unfortunatly, when the links were clicked, I got "Access denied - You are not authorized to access this page."

So, I changed line 89 thinking that would cover it, but it doesn't and I don't see anything near line 955 or in the comment_delete function that needs changing.

What am I missing?

Thank you,
Billy

Comments

jeepfreak’s picture

Sorry, I should have posted snippets of the code for reference:

To get the links to show up, I edited line 684 (not 184 as previously stated)... The if(user_access('administer comments')) line below.

function comment_links($comment, $return = 1) 
.
.
.
  if (node_comment_mode($comment->nid) == 2) {
    if (user_access('adminster comments')) {
      $links[] = l(t('delete'), "admin/comment/delete/$comment->cid");
      $links[] = l(t('edit'), "admin/comment/edit/$comment->cid");
      $links[] = l(t('reply'), "comment/reply/$comment->nid/$comment->cid");
    }

Then I edited the $access but it didn't fix the 'access denied' error.

function comment_menu($may_cache) {
  $items = array();

  if ($may_cache) {
    $access = user_access('administer comments');
    $items[] = array('path' => 'admin/comment', 'title' => t('comments'),
      'callback' => 'comment_admin_overview', 'access' => $access);
    $items[] = array('path' => 'admin/comment/edit', 'title' => t('edit comment'),
      'callback' => 'comment_admin_edit', 'access' => $access, 'type' => MENU_CALLBACK);
    $items[] = array('path' => 'admin/comment/delete', 'title' => t('delete comment'),
      'callback' => 'comment_delete', 'access' => $access, 'type' => MENU_CALLBACK);
merlinofchaos’s picture

To make this work properly is slightly more complicated than I'm afraid you want it to be.

You're going to have to do 2 things.

First, for admin/comment/edit and /delete, change 'access' => $access to 'access' => 1

Then, you'll need to edit comment_admin_edit() to actually check to see if the current user (use global $user to get access to the $user variable, and compare $node->uid to $user->uid once $node is loaded). Your code will look something like this:

  $global user;
  if ($node->uid != $user->uid && !user_access('administer comments'))
    return drupal_access_denied();

Now the bad news: I just looked at comment_admin_edit() and $node isn't actually loaded at that stage. SO you're going to have to get the uid like this:

  $uid = db_result(db_query("SELECT n.uid FROM {node} n LEFT JOIN {comments} c ON c.nid = n.nid WHERE c.cid = %d", $cid);

Then use that $uid rather than $node->uid above.

You'll also need to make sure you get the right $cid -- it can come either as an argument or as $edit['cid'] depending on the context the function is called in.

Now, the bit that actually saves teh comment then does a drupal_goto('admin/comment') -- that won't be appropriate for all users. You'll want to check to see if the user has administer comments access, and if not, go to the node. Or maybe just edit that go to the node.

You'll have to do similar things to comment_delete().

Does this all make sense? I wrote all this with the hope that you've gotten this far, you're familiar enough with PHP and Drupal that you can piece together what needs to be done with this info, but that's me making a wild guess at your knowledge.

Good luck!

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

jeepfreak’s picture

That looks do-able for me. Thank you so much. I'll implement the changes and post the results.
Thanks again,
Billy