In my forum I have a user added as a moderator. They can edit and delete forum topics but they are unable to edit or delete other people's comments even though the Forum Moderator role has the "administer comments" permission assigned to it.

From looking through the FA code I can see that forum moderators are never actually assigned the "Forum Moderator" role. This makes sense I guess since we don't want them to be able to administer comments except when viewing a forum topic page. So in hook_init() FA temporarily assigns the Forum Moderator role if the user is viewing a comment or if they're editing a node and they are in the moderator Access Control List for the forum being viewed:-

  if (isset($nid)) {
    $node = node_load($nid);
    if ($tid = _forum_access_get_tid($node)) {
      foreach ($access as $a) {
        if (forum_access_access($tid, $a) > 1) {
          if (arg(0) == 'comment' || arg(0) == 'node' && arg(2) == 'edit') {
            $user->_forum_access_moderator = TRUE;
            module_load_include('node.inc', 'forum_access');
            _forum_access_enable_moderator();
            break;
          }
        }
      }
    }
  }

Then, in _forum_access_preprocess_comment() FA temporarily assigns and then unassigns the Forum Moderator role when it comes to constructing the links to show for a given comment:-

  global $user;
  if (!empty($user->_forum_access_moderator)) {
    _forum_access_enable_moderator();  // this allows us to retrieve the comment links (without setting precedent!)
  }

  $tid = $variables['node']->tid;
  $links = module_invoke_all('link', 'comment', $variables['comment'], 0);

  if (!empty($user->_forum_access_moderator) && arg(0) == 'node' && arg(2) == NULL) {
    _forum_access_disable_moderator();
  }

The problem is that the _forum_access_moderator field is only set when editing a forum topic node, not when viewing it. But it needs to be set when viewing it too so that comments have the edit and delete links showing for moderators.

Additionally, I'm using the advanced_forum module to better them my forum. This internally implements hook_links() and ends up overriding the links generated by _forum_access_moderator with the default ones generated by comment_links (by which point of course the temporary Forum Moderator role assignment has been revoked for the user).

My solution is to patch FA such that the _forum_access_moderator field is set even when just viewing a forum topic node and to now revoke the temporary Forum Moderator role assignment. Thus, even when comment_links gets called it will generate and show the edit and delete links for comments. It is safe to leave this role assigned to the moderator for the duration of the script since we only assign it the user is currently viewing a forum topic.

Patches attached.

Comments

orjantorang’s picture

Title: Forum Moderators are unable to edit or delete other people's comments » Works for me

I have tested hiddentao:s patch and it solved my problem with no administration permissions on comments for Forum Moderators.
I'm using Forum Access 6.x-1.3 and Forum (core) 6.17. (not using Advanced Forum)

Thanks!

orjantorang’s picture

Title: Works for me » Forum Moderators are unable to edit or delete other people's comments

:-)

leamas’s picture

These patches worked on my test implementation (fresh installation) but when I moved the changes to production all I get is the "delete" link but still have no access to delete the replies. So, I'm not sure what else is 'causing the problem. I do have og_access installed, but I'm not certain yet if that is what is causing the error. More testing to go :P

salvis’s picture

I haven't applied these patches so far. We have no tests in place, and making changes in that area is very risky. It can have all sorts of unexpected and unwanted side effects.

Please try to install the current -dev version and run the database update (it will not change your schema, so you can still go back to 1.3 if you want). I did make some fixes since 1.3, and I wonder whether this issue is still present.

salvis’s picture

Status: Active » Fixed

I've committed #733188-5: Implement the D6.17 hook_link_alter() for comments to the -dev version (give it up to 12h to be repackaged).

I believe that fixes this issue, too. Please test this and post your feedback on the other thread, both for pre-D6.17 as well as for D6.17+, and also with or without Advanced Forum.

Feel free to reopen if the issue is still present.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

quarantadue’s picture

Status: Closed (fixed) » Needs work

Hi,

the issue is not fixed, even with forum access 6.x-1.x-dev and ACL 6.x-1.3.

Patches by hiddentao instead solve the problem!

Stephen Scholtz’s picture

Just a note that this is still an issue, as identified earlier. The problem seems to be related to Advanced Forum, as mentioned in the original post, since it overwrites links.

Without Advanced Forum on, and with the user being set as a Moderator for the forum, the module works fine without the patch above. When Advanced Forum is turned on, the Edit/Delete links disappear without the patch.

I have not tried the dev version of FA, but will give it a shot after I finish testing something else. Does Forum Access need a hook_link perhaps?

Using Drupal 6.20, ACL 1.3, Forum Access 1.5, Advance Forum 1.1.

Stephen Scholtz’s picture

Status: Active » Needs work

Tried the dev version of Forum Access, conflict with Advanced Forum still seems to be the problem. However, the patch above *does not* work with dev.

The second part of the patch is located in the function _forum_access_preprocess_comment(), which doesn't seem to be executed anymore if you're using Drupal 6.17 or above. (See forum_access_preprocess_comment(), line 454 in forum_access.module)

Question: should this be a Forum Access problem or a Advanced Forum problem?

(Edit: typo)

Stephen Scholtz’s picture

Version: 6.x-1.3 » 6.x-1.5
Status: Needs work » Active
boftx’s picture

subscribe

salvis’s picture

Status: Needs work » Active

We have to get by without forum_access_preprocess_comment().

In what way is it failing now?

boftx’s picture

I went into the database and changed the weight of FA to 3 and AF to 2 and it cleared the problem for me.

salvis’s picture

What exactly was it that didn't work?

boftx’s picture

I was not seeing edit/delete buttons or links for users assigned as moderators. By making the change I now see normal text links for edit/delete functions.

salvis’s picture

Status: Active » Needs work

Ok, will have to think about this again.

Thanks for the work-around in #13.

fnikola’s picture

I just wanted to add that the work around in #13 resolved the issue for me too and moderators can now edit/delete any comments in the forum. Thanks.

snsace’s picture

Has this been fixed without having to edit the database as in #13?

Previously, I had been using Taxonomy Access Control for forum access control but was hoping this would be a better alternative. I'm not sure I trust this will work since I can't get this moderator feature to work. I have a few users that I want to make moderators (without creating a new role).

I currently have forum_access 6.x-1.5 installed.

salvis’s picture

6.x-1.5 is quite old. I would definitely recommend getting the -dev version instead.

I'd be very interested to know whether the -dev version fixes this problem. I should have asked that in #14...

juju’s picture

The DEV version solved the issue, for me.
THANKS!

boftx’s picture

I guess I'm old-school, I don't like using dev versions on a production site if I can avoid it.

salvis’s picture

Status: Needs work » Fixed

Fixed in the -dev version, thanks juju!

There will be a new release as soon as #762270: WANTED: SimpleTests for Forum Access is completed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pauln600’s picture

Version: 6.x-1.5 » 6.x-1.x-dev
Status: Closed (fixed) » Active

I'm running the current dev version, but this is still not working in the forum on my site. At the moment there seems to be no way of approving or un-approving comments / posts. I also changed the FA / AF weights as in #13. Comments / posts that were un-approved are showing up in the approval queue under admin/content/comment/approval, but are live on the site.

pauln600’s picture

So at the moment, the only way to get rid of a post (comment) is to delete it from the comment table.... too strange.

salvis’s picture

Status: Active » Closed (fixed)

@pauln600: This is unrelated to "Forum Moderators are unable to edit or delete other people's comments." Please open a new issue.