How do we redirect the denied users to be automatically redirected to Register / login page?

Presently, we have some taxonomy terms that cannot be accessed by anonymous users. When an anonymous user clicks the terms the message says, 'There are currently no posts in this category'. We don't want that. We want the users to be redirected to the login/register page. How do we do that?

thanks & regards,
murali.

Comments

Hituro’s picture

I'm having the same problem

I have a 'members' taxonomy term and I have set view to deny for anonymous users. When they click on the taxonomy term I want them to get a login page, not a 'page not found'. Is this a taxonomy_access issue, or a Drupal ACL issue?

Hituro’s picture

We have implemented a fix by altering the taxonomy module. The problem is that when the taxonomy module is asked for a listing page it first checks to see if the term exists AND you have view access to it. If you don't have access to it then it treats it as not found.

We added the following code to the end of taxonomy_term_page() in taxonomy.module

    else {
      /**
       * If taxonomy term exists you get Access Denied , otherwise Not Found
       * Looks for the terms in the term table
       * 02.11.2007
       */
      
      $result = db_query('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN (%s)', implode(',', $terms['tids']));
	  if (db_num_rows($result)) {
	  	 drupal_access_denied();
	  } else {
      	drupal_not_found();
	  }
darumaki’s picture

could you specify exactly where and how you add the code ? i tried adding it but results in blank page

Hituro’s picture

Firstly this is in 5.1

In modules/taxonomy/taxonomy.module around line 1317 in function taxonomy_term_page() there is an if statement starting

    if ($names) {
      $title = check_plain(implode(', ', $names));
      drupal_set_title($title);
      ...

At the end of this if, around line 1413 add the code given above after the ending }

Hope that helps

darumaki’s picture

thanks unfortunately it still results in blank page in 5.5
this is what i have

function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') {
  $terms = taxonomy_terms_parse_string($str_tids);
  if ($terms['operator'] != 'and' && $terms['operator'] != 'or') {
    drupal_not_found();
  }

  if ($terms['tids']) {
    $placeholders = implode(',', array_fill(0, count($terms['tids']), '%d'));
    $result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN ('. $placeholders .')', 't', 'tid'), $terms['tids']);
    $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to.
    $names = array();
    while ($term = db_fetch_object($result)) {
      $tids[] = $term->tid;
      $names[] = $term->name;
    }
 
   if ($names) {
      $title = check_plain(implode(', ', $names));
      drupal_set_title($title);

    else {
     
      $result = db_query('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN (%s)', implode(',', $terms['tids']));
      if (db_num_rows($result)) {
           drupal_access_denied();
      } else {
          drupal_not_found();
      }
xjm’s picture

Status: Active » Closed (duplicate)

There's two parts to this: TAC's handling of what should be 403s, and the redirects.

The latter is beyond the scope of TAC, I think; but the former is related to #573674: Deny access to term page? and #311649: "Page Not Found" error for all non-accessible term pages. Marking duplicate.