diff --git a/og.rules.inc b/og.rules.inc index f7bfa0a..c7eab2e 100644 --- a/og.rules.inc +++ b/og.rules.inc @@ -237,9 +237,8 @@ function og_rules_action_info() { 'wrapped' => TRUE, ), 'roles' => array( - 'type' => 'list', + 'type' => 'list', 'label' => t('Group roles'), - 'description' => t('Default roles will not be granted if they are being overridden in the group\'s settings.'), 'options list' => 'og_rules_group_roles_options_list', 'restriction' => 'input', ), @@ -371,8 +370,12 @@ function og_rules_remove_entity_from_group(EntityDrupalWrapper $entity, EntityDr * Action: Grant OG role. */ function og_rules_grant_og_role(EntityDrupalWrapper $account, EntityDrupalWrapper $group, $roles) { - foreach ($roles as $rid) { - og_role_grant($group->type(), $group->getIdentifier(), $account->getIdentifier(), $rid); + $group_roles = og_roles($group->type(), NULL, $group->getIdentifier()); + foreach ($roles as $role) { + $rid = array_search($role, $group_roles); + if ($rid !== FALSE) { + og_role_grant($group->type(), $group->getIdentifier(), $account->getIdentifier(), $rid); + } } } @@ -380,52 +383,24 @@ function og_rules_grant_og_role(EntityDrupalWrapper $account, EntityDrupalWrappe * Action: Revoke OG role. */ function og_rules_revoke_og_role(EntityDrupalWrapper $account, EntityDrupalWrapper $group, $roles) { - foreach ($roles as $rid) { - og_role_revoke($group->type(), $group->getIdentifier(), $account->getIdentifier(), $rid); + $group_roles = og_roles($group->type(), NULL, $group->getIdentifier()); + foreach ($roles as $role) { + $rid = array_search($role, $group_roles); + if ($rid !== FALSE) { + og_role_revoke($group->type(), $group->getIdentifier(), $account->getIdentifier(), $rid); + } } } /** * Options list callback for group roles. - * - * Note: Not all roles will be compatible with the group entity being - * evaluated. For instance, a role that is part of a default set will not - * be granted if the group being evaluated has its default roles and - * permissions overridden. Our options list will include the bundle name - * and, in cases where default roles are being overridden for a group - * entity, the entity's id. It will be up to the administrator to use - * this information to select the correct role. */ function og_rules_group_roles_options_list($element) { - $og_roles = array(); - - foreach (og_get_all_group_bundle() as $group_type => $bundles) { - foreach ($bundles as $bundle => $label) { - - $query = db_select('og_role', 'ogr') - ->distinct() - ->fields('ogr', array('gid', 'group_type')) - ->condition('group_bundle', $bundle, '=') - ->orderBy('gid', 'ASC'); - - $result = $query->execute(); - while ($row = $result->fetchAssoc()) { - - $label_append = $row['gid'] ? $row['group_type'] . ':' . $row['gid'] : t('Defaults'); - - $roles = array(); - $bundle_roles = og_roles($group_type, $bundle, $row['gid']); - foreach ($bundle_roles as $rid => $name) { - // Don't return anonymous and authenticated member roles. - if (!in_array($name, array(OG_ANONYMOUS_ROLE, OG_AUTHENTICATED_ROLE))) { - $roles[$rid] = $name; - } - } - if (!empty($roles)) { - $og_roles[$label . ' (' . $label_append . ')'] = $roles; - } - } + $unique_roles = array_unique(og_get_user_roles_name()); + foreach ($unique_roles as $role) { + if (!in_array($role, array(OG_ANONYMOUS_ROLE, OG_AUTHENTICATED_ROLE))) { + $og_roles[$role] = $role; } } return $og_roles; @@ -558,7 +533,7 @@ function og_rules_condition_info() { 'wrapped' => TRUE, ), 'roles' => array( - 'type' => 'list', + 'type' => 'list', 'label' => t('Group roles'), 'options list' => 'og_rules_group_roles_options_list', 'restriction' => 'input', @@ -644,7 +619,7 @@ function og_rules_entity_is_group_content_help() { */ function og_rules_condition_user_has_role(EntityDrupalWrapper $account, EntityDrupalWrapper $group, $roles) { $user_roles = og_get_user_roles($group->type(), $group->getIdentifier(), $account->getIdentifier()); - return !array_diff_key($roles, $user_roles); + return !array_diff($roles, $user_roles); } /**