I have installed forum_access and it works exactly as advertised. Nice work!

My question is... I would like to show links to all of the forums on the site to all users, even if the forum is private. This would work as sort of a teaser, so when the user clicks to a private forum, they are sent to a page that asks them to login or register. I don't want them to be able to actually view any of the forum content, but I would like to list the forum name and stats on the /forum page.

I'm sure this is probably a really stupid newbie question, but I cannot seem to find the answer on my own.

Thanks for your help!

Comments

salvis’s picture

Thanks, the praise is due to merlinofchaos.

No, not a stupid question at all. FA doesn't support what you'd like to do. The Drupal way is to hide what's not accessible.

You could hack FA to not pass the query that retrieves the forum list through db_rewrite_sql(). This would give you all forums, but it would give the user an access denied message when s/he tries to access a private forum. To redirect to a different page, you'd have to compare the lists you get with and without db_rewrite_sql and change the links accordingly.

jorbot’s picture

Status: Active » Closed (fixed)

Excellent!

All I did was comment out all the lines inside forum_access_db_rewrite_sql() and now all the forum links show up in the list for all users. Yes, I get an access denied page when trying to click them (if the user doesn't have access), but I'll write a friendly message that describes why.

Thanks for the tip!

darumaki’s picture

Can you tell me how you did this ? Im trying to do the same, is this inside forum_access_module ?

Update I think I found it but how do you comment these out ?

function forum_access_db_rewrite_sql($query, $primary_table, $primary_field, $args)

jorbot’s picture

Put two forward slashes at the beginning of each line inside the forum_access_db_rewrite_sql() function.

Like this...

function forum_access_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
  // if ($primary_field == 'tid' && !user_access('administer forums')) {
  //   global $user;
  //   $roles = _forum_access_get_roles($user);
  //   $sql['join'] = "LEFT JOIN {forum_access} fa ON $primary_table.tid = fa.tid 
  //   LEFT JOIN {acl} acl ON acl.name = $primary_table.tid AND acl.module = 'forum_access' 
  //   LEFT JOIN {acl_user} aclu ON aclu.acl_id = acl.acl_id AND aclu.uid = $user->uid";
  //   $sql['where'] = "(fa.grant_view >= 1 AND fa.rid IN ($roles)) OR fa.tid IS NULL OR aclu.uid = $user->uid";
  //   $sql['distinct'] = 1;
  //   return $sql;
  // }
}

Note: I split the $sql['join'] string into 3 lines so it would fit in this box without wrapping oddly.

Essentially it just creates an empty function. You wouldn't want to comment out the function name because that would cause an error when the function is called by the forum_access module.