diff --git a/og.rules.inc b/og.rules.inc index 5afb094..d27b997 100644 --- a/og.rules.inc +++ b/og.rules.inc @@ -223,6 +223,36 @@ function og_rules_action_info() { 'access callback' => 'og_rules_integration_access', ); + $defaults = array( + 'group' => t('Organic groups'), + 'access callback' => 'og_rules_integration_access', + 'parameter' => array( + 'account' => array( + 'type' => 'user', + 'label' => t('User'), + 'description' => t('The user whose group roles should be changed.'), + 'save' => TRUE, + ), + 'group' => array( + 'type' => 'group', + 'label' => t('Group'), + ), + 'roles' => array( + 'type' => 'list', + 'label' => t('Group roles'), + 'options list' => 'og_get_global_roles', + ), + ), + ); + $items['og_add_role'] = $defaults + array( + 'label' => t('Add group role to user'), + 'base' => 'og_rules_action_user_add_group_role', + ); + $items['og_remove_role'] = $defaults + array( + 'label' => t('Remove group role from user'), + 'base' => 'og_rules_action_user_remove_group_role', + ); + return $items; } @@ -327,6 +357,34 @@ function og_rules_remove_entity_from_group(EntityDrupalWrapper $entity, $group) } /** + * Action: Adds group roles to a particular user within a group context. + */ +function og_rules_action_user_add_group_role($account, $group, $roles) { + if ($account->uid) { + foreach ($roles as $rid) { + og_role_grant($group->gid, $account->uid, $rid); + } + } + else { + return FALSE; + } +} + +/** + * Action: Removes group roles from a particular user within a group context. + */ +function og_rules_action_user_remove_group_role($account, $group, $roles) { + if ($account->uid) { + foreach ($roles as $rid) { + og_role_revoke($group->gid, $account->uid, $rid); + } + } + else { + return FALSE; + } +} + +/** * OG Rules integration access callback. */ function og_rules_integration_access($type, $name) {