How to Make Public and Private Forums
Here's a small Drupal module (D6) and instructions to allow you to have both public and private forums on a site. It actually can be used to have any set of role-based access rules to different forum containers. It relies on the Taxonomy Access Control Lite module. You should already have forum module enabled (you can also add Advanced Forum).
drush dl tac_lite
drush en tac_lite tac_lite_create
Create two forum containers for your public and private forums.
Configure tac_lite at /admin/user/access/tac_lite and set it up to control the 'Forums' vocabulary with two schemes (for a public and private forums scenario). Configure each scheme to grant view access to the appropriate roles to the appropriate forum container (and any forums inside that container if they already exist).

Add a few test forum topics and test your setup to be sure that the roles are getting access to the correct forums. If access is not being denied properly you may need to rebuild the node access records at /admin/content/node-settings or figure out an issue with having too many node access modules (use devel node access module's blocks and understand the issues).
Once your access is correct the remaining piece is to automatically put new forums into the public or private tac_lite schemes according to which forum container they are placed into. Modify my code for your needs.
First the .info file:
name = MY PROJECT Forum
description = Customizations for the MY PROJECT forum
package = MY PROJECT
core = 6.x
dependencies[] = forum
dependencies[] = tac_liteThen the .module file. Make sure you change the constants at the top to match the various vocabulary, term and role IDs that match your site.
<?php
/**
* @file
* Customizations to the forum system.
*/
define('MY_PROJECT_FORUM_VID', 6); // The vocabulary ID for the forum.
define('MY_PROJECT_PUBLIC_FORUM_TID', 1465); // The term ID for the public forum container.
define('MY_PROJECT_PRACTITIONER_FORUM_TID', 1894); // The term ID for the practitioner forum container.
define('MY_PROJECT_PRACTIONER_RID', 3); // The Role ID for privileged users.
define('MY_PROJECT_ADMIN_RID', 4); // The Role ID for admins.
/**
* Implementation of hook_taxonomy().
*/
function my_project_forum_taxonomy($op, $type, $value) {
switch ($op) {
case 'insert':
case 'update':
if ($type == 'term') {
$term = $value;
// Set forum terms to be public under tac_lite if they are in the public container.
if ($term['vid'] == MY_PROJECT_FORUM_VID) {
$public = FALSE;
$private = FALSE;
$parents = taxonomy_get_parents_all($term['tid']);
foreach ($parents as $parent) {
if ($parent->tid == MY_PROJECT_PUBLIC_FORUM_TID) {
$public = TRUE;
}
elseif ($parent->tid == MY_PROJECT_PRACTITIONER_FORUM_TID) {
$private = TRUE;
}
}
if ($public) {
my_project_forum_set_access($term['tid'], 1);
}
elseif ($private) {
my_project_forum_set_access($term['tid'], 2);
}
}
}
break;
}
}
/**
* Add a term ID to the tac_lite settings to make it a public or practitioner forum.
*/
function my_project_forum_set_access($tid, $tac_scheme) {
$settings = variable_get('tac_lite_grants_scheme_' . $tac_scheme, array());
if ($tac_scheme == 1) { // public tac scheme
$settings[DRUPAL_ANONYMOUS_RID][MY_PROJECT_FORUM_VID][$tid] = $tid;
$settings[DRUPAL_AUTHENTICATED_RID][MY_PROJECT_FORUM_VID][$tid] = $tid;
}
if ($tac_scheme == 2) { // private tac scheme
$settings[MY_PROJECT_PRACTITIONER_RID][MY_PROJECT_FORUM_VID][$tid] = $tid;
$settings[MY_PROJECT_ADMIN_RID][MY_PROJECT_FORUM_VID][$tid] = $tid;
}
variable_set('tac_lite_grants_scheme_' . $tac_scheme, $settings);
}
?>





Post new comment