1) I installed og, og_ui, og groups context, and og groups access control modules.
2) Created one content type call group.
3) Create a content of group and added two users to the group
(user 1 has administrator role in the group and user 2 is not granted any role)
4) Created a simple view where I want to view all non admin members of the groups
$view = new view();
$view->name = 'test_og';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'test og';
$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['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$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['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: OG membership: OG Roles from membership */
$handler->display->display_options['relationships']['og_users_roles']['id'] = 'og_users_roles';
$handler->display->display_options['relationships']['og_users_roles']['table'] = 'og_membership';
$handler->display->display_options['relationships']['og_users_roles']['field'] = 'og_users_roles';
$handler->display->display_options['relationships']['og_users_roles']['required'] = TRUE;
/* 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']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
/* Field: OG membership: OG user roles in group */
$handler->display->display_options['fields']['og_roles']['id'] = 'og_roles';
$handler->display->display_options['fields']['og_roles']['table'] = 'og_membership';
$handler->display->display_options['fields']['og_roles']['field'] = 'og_roles';
/* 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: OG user roles: Role Name */
$handler->display->display_options['filters']['name']['id'] = 'name';
$handler->display->display_options['filters']['name']['table'] = 'og_role';
$handler->display->display_options['filters']['name']['field'] = 'name';
$handler->display->display_options['filters']['name']['relationship'] = 'og_users_roles';
$handler->display->display_options['filters']['name']['value'] = array(
'member' => 'member',
);
When I add the filter in views as role of type "member" then shows no result but when I remove this I get one result i.e. user 1 (administrator) and when I make the og_user_role relationship not required then it shows me both members. On further checking the db I found that the og_users_roles table has only the entry of administrator role member and then other entry of "member" is missing.
I tried to add it through code using
$group_type = 'node';
$gid = 1; //my group id is 1
$uid = 2; //uid of user 2
$rid = 2 // rid of member role
og_role_grant($group_type, $gid, $uid, $rid);
still it doesn't make a entry on debugging found that the og_role_grant call og_roles function to validate the role which don't return the OG_AUTHENTICATED_ROLE as the argument of include_all is false.
I may be wrong but think that og_users_roles should have a entry for members too so that the views handler can work.
Comments
Comment #1
amitaibu> I may be wrong but think that og_users_roles should have a entry for members too so that the views handler can work.
OG is following Drupal core, which doesn't save a record for auth users without any other roles.
Comment #2
sadashiv CreditAttribution: sadashiv commentedHi @Amitaibu,
Thanks for the update. I will try for some alternate solution like using og_membership in views to get the desired results.
Thanks,
Sadashiv.
Comment #4
drupal_was_my_past CreditAttribution: drupal_was_my_past commented@amitaibu This views handler is really confusing. I think it should either not display "members" and "non-members" as options since choosing either of those does not work OR it should be smart enough to not join on the og_users_roles table if "members" and "non-members" is selected.
Comment #5
drs2034 CreditAttribution: drs2034 commentedI am having a similar issue. When I add member using role using og_role_grant. It does not populate og_users_roles table because "$og_roles = og_roles($group_type, $bundle, $gid, FALSE, FALSE);" does not return member and non-member from og_role table as $include_all parameter is set to FALSE.
I wonder if there is there way to populate og_users_roles table for member as well adding a membership to group.