Hi,

We use node access to restrict certain pages from certain roles, say pages 4-6 are viewable only by an authorised user.

If an anonymous user then uses our search facility the nodes 4-6 still show up in the search results, although when an anonymous user then goes to view the page, the site denies access.

When I have looked into this it seems as though it shouldnt happen... yet it does?

I wonder if anyone has any advice, the search settings are limited and node access is meant to support this.

Probably missing something simple but I'm not sure what?

Many thanks

Chris

Comments

Diegen’s picture

hard to say exactly without more info, Id recommend creating content types instead that are not available for certain roles, then you could just use search restrict module to keep them from getting listed in the search.

chrispeat’s picture

We already have a lot of content created, and have gone live with the system. We also have views, which could only be views so need to try and get around this another way if at all possible.

Any ideas on this would be great as it seems simple enough and must be a common issue?

Thanks for the tip about types though, in other scenarios this would definately be the way to go....

Chris

rishius’s picture

Why don't you try to customize your search results page? If will be more simple. Say you don't want the pages 4-6 to be displayed, you can set it using the if conditions in the search-result.tpl.php...

  foreach($result as $res){    
     if(($type=='content_type')$$(($user->id)=='user-id')){
       //make a print_r() to show the available variables to be printed.
     }
  }
    

hope you understand what i mean...

chrispeat’s picture

Thanks thats great, I'm not ever so familiar with customizing pages but ive done a few now and this seems pretty logical to me. It is also a leaner approach and could be very worthwhile!

Great tip!

The next quesiton would be how to code the IF statement

it would need to say

if(NODE ROLE PERMISSION = CURRENT USER ROLE) {

}

although I'm not sure how I would do that yet? I can get the search results template from the search module itself.

rishius’s picture

ok... go to your root directory and find modules folder. You'll find some *.tpl.php files there. The one that interests un is the 'search-result.tpl.php'. The 'search-result.tpl.php' is the file which used to display each result and the 'search-results.tpl.php' is the file that compresses each search result and put in one single file.

copy the search-result.tpl.php and paste it in your sites/all/themes/themename/

Things get complicated now. The things you want to do requires user information, if you just do a print_r($res); you will note get the required information... You should try to use the user_load() function. try to do a print_r($user) after the user_load() to see if you get the arrays(). I've never done this so far, but thats the way to get the user role and current user info in the search-result.tpl.php

WorldFallz’s picture

If an anonymous user then uses our search facility the nodes 4-6 still show up in the search results, although when an anonymous user then goes to view the page, the site denies access.

What node access module(s) are you using? I use content_access and this does not happen. It works as expected-- no nodes that the anonymous role doesn't have access to show up in search results.