0

How can I create a view that lists all users with a certain permission?

When I use permission as a filter criteria in Views, only admin account is displayed for some reason.

I'm probably missing something too obvious, but can't figure it out for some time.

Here's an export of a very basic view. Try it out on a website that has more than 1 user who can access published content.

$view = new view();
$view->name = 'temporary';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Temporary';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Temporary';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: User: Permission */
$handler->display->display_options['filters']['permission']['id'] = 'permission';
$handler->display->display_options['filters']['permission']['table'] = 'role_permission';
$handler->display->display_options['filters']['permission']['field'] = 'permission';
$handler->display->display_options['filters']['permission']['value'] = array(
  'access content' => 'access content',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'temporary';

Any ideas?

Thanks!

  • Very interesting. Turns out at least in my case that there is no 'view published content' being stored in the role_permissions table. Does another perm work? – sareed Jan 7 '15 at 21:19
  • Thanks for your message Sareed. It's still the same, no matter which role I use. – Aram Boyajyan Jan 8 '15 at 10:04
  • I tested this and yeah it's weird that it only shows admin. Looks like this is a bug, you should post this in the drupal.org views issues. – No Sssweat Jan 15 '15 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.