Access control in group based forums On my websites I have forums that mirror the structure of og-based groups. I am using advanced forums, OG Forum D7 and a decent amount of custom code.

My problem is to restrict access/visibility to forums based on the og role. While I know how to do it with forum topics which are stored as nodes, I have problems with forums which under a hood are taxonomy terms.

I am looking for a place where I can hook the code restricting visibility of a taxonomy term.

function mymodule_taxonomy_access($taxonomyterm, $op, $account) {
    if( $op == 'view' )
        $gid = get_grop_from_term($taxonomyterm);
        if( user_has_forum_access($gid, $account))
                return ACCESS_ALLOW;
        //else
        return ACCESS_DENY;
    }
}


I have no idea in which module I should look for the right hook: taxonomy, forum, forum_access, core (I think that taxonomy terms are entities)?

Taxonomy Access Control while being very powerful, provides no connection with organic groups. 

UPDATE
I have found that TCL Lite is using the hook_query_TAG_alter to hide taxonomy terms.
The hook is editing all queries made to the database and is effectively filtering the taxonomy_terms that any query can see.
This looks like an awfully heavy solution.

Can anyone suggest a better approach?
After a small fight I managed to have it solved. There are few issues to have in mind like caching or preventing infinite recursion (you don't want to change the queries that you use inside the query altering function).

The code is based on TAC module.

function mymodule_query_term_access_alter($query) {
    static $mymodule_recursion_flag = FALSE;

    //prevent infinite recursion altering db_queries inside of this function
    if($mymodule_recursion_flag) return;

    // Take no action if there is no term table in the query.
    $alias = '';
    $tables =&amp; $query-&gt;getTables();
    foreach ($tables as $i =&gt; $table) {
        if (strpos($table['table'], 'taxonomy_term_') === 0) {
            $alias = $table['alias'];
        }
    }
    if (empty($alias)) {
        return;
    }

    //store once obtained results
    static $mymodule_tids = null;
    if($mymodule_tids == null){
        //set the recursion flag
        $mymodule_recursion_flag = TRUE;
        // Fetch a list of all terms the user should not see
        $mymodule_tids = mymodule_get_taxonomy_black_list();
        //unset the recursion flag
        $mymodule_recursion_flag = FALSE;
    }
    // No restrictions - user can list all terms
    if (empty($mymodule_tids)) {
        return;
    }
    // Otherwise, filter the terms
    else {
        $query-&gt;condition($alias . ".tid", $mymodule_tids, "NOT IN");
    }
}