Thanks for a great module. Putting it to excellent use.

I wish that when clicking "Add a widget", it would not show blocks that the user does not have permission to.

Here's what I did to get around this issue in homebox.module:

..
function homebox_build($page) {
..
  // Extract blocks from the page
  $blocks = $page->settings['blocks'];
  
  // Build an array of roles for each block
  $block_roles = array();
  $result = db_query('SELECT module, delta, rid FROM {block_role}');
  foreach ($result as $record)
    $block_roles[$record->module][$record->delta][] = $record->rid;
  $user_roles_keys = array_keys($user->roles);    
        
  // Determine which are allowed
  $allowed_blocks = array();
  $info = array();
  foreach ($blocks as $key=>$block) {
    $m = $block['module'];
    $d = $block['delta'];

    // Remove blocks the user does not have access to
    if (isset($block_roles[$m][$d])
      && !array_intersect($block_roles[$m][$d], $user_roles_keys)) {
      unset($blocks[$key]);
      continue;
    }

    // Add block to allowed list
    if (!isset($info[$m])) 
      $info[$m] = module_invoke($m, 'block_info');
    if (isset($info[$m][$d])) {
      $allowed_blocks[$m][$d] = $info[$m][$d];
      if (!empty($block['title']))
        $allowed_blocks[$m][$d]['info'] = $block['title'];
    }
  }

  // Get user settings, so custom blocks are placed in regions.
  $user_blocks = _homebox_get_user_settings($page);

..

It does not, however, factor in Views role permissions, just specific role permissions applied to a block. This might be worth fleshing out some more.

Comments

Andy_D’s picture

The fact that I posted this without properly investigating my own problem is more of an issue - apologies!

Anybody’s picture

Status: Active » Closed (won't fix)

Please create a new Drupal 8+ (3.0.x) issue, referencing this one, if this is still relevant for Drupal 8+ (3.0.x).

As this issue was created for Drupal 7 which is close to EOL and won't receive any new features here anymore (unless someone implements them or sponsors development) I'm closing this issue for cleanup now.

If anyone works on this or has a solution, feel free to reopen! :)
Thank you.