0

So far, I have been reading some similar questions but I haven't found an elegant and simple way of doing this (if there is any). As I say in the question title, I don't want anonymous users to access the complete list of nodes (in node/) nor a particular node (under node/%nid), nor even a particular taxonomy term. :)

My approach to this is as follows. As far as I know, I can override the default node/%nid system page using a variant in Drupal panels. I actually did this and, if the user is not logged in, when he/she tries to access the node/%nid he/she will see a log in box. For the list of nodes, I removed from the front page all of the nodes and none is shown. I would expect to do with taxonomy/term/%tid the same as I did with node/%nid but, for a strange reason, Drupal panels is not able to create the variant (not sure if it is a bug).

Anyway, I would like to know if you have a more elegant or simpler approach to this (no matter if using panels or not).

Thanks in advance for your help!

1
  • I've hacked the Securesite module to only protect certain paths. You might also be able to use the Redirect module to redirect users who don't have the right roles to a different page if they try to view those.
    – beth
    Commented Jun 21, 2013 at 22:44

2 Answers 2

0

Have you tried in the template.php? what if you do something like:

function yourtheme_preprocess_page(&$variables, $hook){
   if(!$user->uid){
      if((arg(0) == 'node') || (arg(0) == 'taxonomy')){
         //redirect to login
      }
   }
}
1
  • 1
    The theme layer isn't the best place for access control. Commented Jun 22, 2013 at 4:12
0

If you're using Panels, it can be done that way by using the default pages:

  • node_view
  • term_view

The trick with term_view is to enable the default taxonomy_term View, give it a different path, e.g 'view/taxonomy/term/%' and embed that in the term_view Panel.

Lastly, make sure you add a catch all "HTTP Response Code: 403" variant to your Panel page to catch those that don't have access to view the content.

Another option is

and added your own access callback to the node view and taxonomy term view menu items.

For example, to disable access to '/node'

/**
 * Implements hook_menu_alter
 */
function MODULE_menu_alter(&$items){
  $items['node']['access callback'] = FALSE;
}

Lastly with node view it's also possible to use the comprehensive

2
  • I will take a look at this way David, and see what happens. Thanks for taking time to reply.
    – José L.
    Commented Jun 24, 2013 at 11:57
  • 'Lastly, make sure you add a catch all "HTTP Response Code: 403" variant to your Panel page to catch those that don't have access to view the content.' I can't find a way of doing this with panels. Can you give me some orientation please?
    – José L.
    Commented Jun 24, 2013 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.