I've fiddled around with the access control panel and unchecked everything for anonymous users. Basically, I don't want the anonymous user to see anything except "You're not authorized" , my logo and a sign-in box.

My problems started when I added some items to the Navigation menu - and created a new menu tree which I added as a block. Now anonymous users can see one random item in the main nav menu, and the header, but nothing else, in the new block.

Any idea how I limit access to those blocks given that every single thing is unchecked for anonymous users in the access control menu.

Comments

gabriella’s picture

You could look at the front page module,

The Front Page module allows user to specify splash pages or front pages to their site that are different in layout to the default theme/style and also offers the option to display different front pages to Authenticated Users (logged in) and Anonymous users (not logged in).

capmex’s picture

Are you sure about this? search engine crawlers won't be able to index your site, only this page and the login ones.

Basically, I don't want the anonymous user to see anything except "You're not authorized" , my logo and a sign-in box.

One way to do this is to modify your theme adding a conditional php code to test for anonymous users. Check the code php snippets for ideas.

A snippet that may help you:
Show block to certain users or roles only

--
Webmaster Resources | Canadian Directory

miggidy’s picture

Yeah, it's a corporate intranet - less people see it the better :) Thanks for the links, but what I need is a way of editting non-custom blocks -that is, blocks defined by Drupal like the navigation menu or a menu I've created.

bonobo’s picture

If you edit the settings for a block (admin-->block, then "configure" for each individual block) you can determine block visibility through php snippets -- if the snippet evaluates to true, the block is displayed.

Hope this helps.

Cheers,

Bill

-------
http://www.funnymonkey.com
Tools for Teachers

Sam308’s picture

I am currently in the same situation as you, but I need a way to have menus, not blocks that are only accessible to specific user roles

Anyways, below is the php block code for your situation. It supports multiple user roles and includes three sample menu items. Only the user roles, Employees, Engineering, and Sales, shown in the example code below, can view this block only after they have logged in.

Just modify the code for your needs.

<?php
global $user;
$output ='';
$approved_roles = array('Employees','Engineering','Sales');
if (is_array($user->roles)) {
  if (count(array_intersect($user->roles, $approved_roles)) > 0) {
  $output .= '<DIV class=item-list><UL>';
  $output .= '<LI><A href="/?q=node/50">Employee Section</A>';
  $output .= '<LI><A href="/?q=node/51">Engineering Department</A></LI>';
  $output .= '<LI><A href="/?q=node/52">Sales Department</A></LI>';
  $output .= '</UL></DIV>';
  }
}
return $output;   
?>

Form my situation....
Ideally, I would like to have an "Internal Affairs" Menu block that is only visible to the Employees, Engineering, and / or Sales user roles, but.... also be able to simply add menu items for the node pages as easily as you can with the regular menus within the Drupal website.

What is the best way to achieve this goal?

Please help if you can.

Sam Raheb (Sam308)

heine’s picture

Is to make several custom menu's using the menu.module (a core module) with easy titles eg Sales, Engineering

Then make a block:


global $user;
$output ='';

// Generate an associative array mapping menu_id and menu_title
$mid_by_title = array();
$menu = module_invoke('menu', 'block', 'list');
foreach($menu as $mid => $value) {
  $mid_by_title[$value['info']] = $mid;
} 

if(is_array($user->roles)){
  if( in_array('Sales', $user->roles)){
    $block = module_invoke('menu', 'block', 'view', $mid_by_title['Sales']);
    $output = $block['content'];
  } elseif (in_array('Engineering', $user->roles)) {
    $block = module_invoke('menu', 'block', 'view', $mid_by_title['Engineering']);
    $output = $block['content'];

  } elseif( ad nauseam ) {
    $block = module_invoke('menu', 'block', 'view',  $mid_by_title['Whatever title']);
    $output = $block['content'];
  } else {
    // Menu block for others
  }
}
return $output;

Of course, you may want to include some in_array checks eg to check that Sales is indeed in the mid_by_title array.

To check for multiple roles at once, use count(array_intersect())>0.

--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

thrice’s picture

Where do I put this code?

heine’s picture

You can put the code in a custom block; make sure to set it to php. The drawback of this approach is that the title of the block is fixed.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.