I'm getting stumped by this one. Let's say I have two groups on the system, ('newbie' and 'oldie'). When a user is created, I want them to be assigned to the 'newbie' group automatically.

I create a rule, select event "After saving a new user account"

Conditions: none (any conditions I can think of would apply to the group selection, not the user)

Actions: "Subscrbe user to group"
-> User->Data selector = "account"
-> Group -> Data selector = "???"

Comments

john.p.baldwin.jr’s picture

Category: support » bug

I've decided I believe this feature isn't working properly yet (hence the category change). I installed the 7.1 branch and the behavior is similar to what's available in Drupal 6, where assigning a user to a group can be done with a select menu.

I am willing to work on patches to improve rules integration if it won't conflict with anybody else's work.

svnindia’s picture

hi,

//where assigning a user to a group can be done with a select menu.//

could you tell me how to assign a private group to a user

john.p.baldwin.jr’s picture

Status: Active » Needs review
StatusFileSize
new2.33 KB

I've attached a preliminary patch to see if this direction is desirable.

I was able to create a rule to assign a user to a group when an account is created.

Event: After saving a new user account
Condition: None
Action: Assign user to group (User set to "account", Group chosen from the drop-down menu).

After doing this, the newly created user was indeed assigned to the group selected.

John

altbzh’s picture

Hi,

With what version does your patch work, please ?

Thank you

john.p.baldwin.jr’s picture

I applied this patch against the latest version under git.

If you go to this url:

http://drupal.org/project/og/git-instructions

And select the 7.x-2.x version, the patch should work.

altbzh’s picture

ok thank you, I will try.

JohnnyX’s picture

I'll try to build a widget to add/ remove users (for example at profile) to own groups. I'll give it a try with your patch as starting point...

JohnnyX’s picture

Any idea how the group which the user should un-/subscribe could be selected instead to define it inside the rule?

So user should select the group(s) the user (which profile is viewed) added to/ removed from...

amitaibu’s picture

Status: Needs review » Closed (works as designed)

-> Group -> Data selector = "???"

You should load the entity that is a group, one action before, so it can be provided in the data selector.
(btw, The patch in #3 isn't scalable -- image 100K groups...)

marqpdx’s picture

I applied the patch from #3 above and it appears to work.
I had to make sure to be in direct Input mode in the rule setting (Action step) for the group dropdown to show up.

Also, i had it setup to run after saving a new user, but the didn't work, b/c (when i checked the db) there was a 0 for the entity ID in the group membership.

So i changed our workflow. I require people to change their password to activate their account, and i changed the rule to automatically add them to the group when they update their user account. It added them successfully to the group.

Thanks,
m

Marfio’s picture

First of all, thank you for the patch.

I used it to subscribe an user role into a group. It works fine.

The only thing you have to be careful is to don't have the "Organic groups context" module active. I couldn't run the patch with that module active.

If anyone needs the rule, Insert an specific role to a group

Event
After update user count
Conditions:
User have roles
User:Account
Rols: YOUR ROLE
Acitions
Subscribe user to group
User:Account
Group:Choose from the list

jcarrothers’s picture

Did this patch ever make it into a release?

I attempted to use this functionality on my own site with 7.x-2.4 and I discovered, upon checking the module source code, that this patch doesn't seem to have been applied to the current release.

farshid’s picture

Adding my 2 cents:
In my case I wanted to subscribe a user to a group, and I was getting an error in dblog, something about anonymous user... and that the subscription can't be done, don't recall the exact error, I added a save entity action on newly created user before og subscribe to group action and it was done.

jeroenmarinus’s picture

Issue summary: View changes
Status: Closed (works as designed) » Needs review

I can confirm this patch works, but has not made it into a release.

Therefore, reopening the issue to be tested a bit more and then hopefully get committed.

ybabel’s picture

"Fetch entity by ID" can do the job. No really need for this patch.

docans’s picture

Hi

I am using drupal commons for my site and i need to automatically assign my user to a particular group base on the taxonomy terms they select

I have a taxonomy term of "states" which shows up on both the user registration form and is also associated to each group

So during a new user registration, when the user select the state of "new york" which has term ID of 15 ,He is automatically assigned to the "new york community" group because the "new york community" group also has been tagged to the "new york" tag.

Any Ideas on how to do this.

Thanks

cassio’s picture

Digging around in other threads, it seems like the user does not have the right role initially to be added to the group. (starts out as anonymous)

rsbecker’s picture

This patch works well for its intended purpose. But there is still a problem.

I have a rule that fires when a person is added to a group. That rule flags the user to receive email notifications about new group content.

If I manually add a user to a group, the flags are set and the email subscription shows up in the user profile. But if I use the rule to add a new user to a group, the "User has become a group member" event appears not to occur. So the user is added to the group but the email subscription isn't created.

edunick’s picture

This patch works only one group. For multiple group, I modify the next code:

function og_rules_add_entity_to_group(EntityDrupalWrapper $entity, /* EntityDrupalWrapper */ $group) {
  // TODO: Add field-name.
  $values = array(
    'entity_type' => $entity->type(),
    'entity' => $entity->value(),
  );
  list($group_type, $gid) = preg_split('/:/', $group);
  if($gid=='all'){// if selected all groups, get all groupt and run og_group() for each group
    $entity_groups = og_get_all_group($group_type);
    foreach ($entity_groups as $entity_id) {
      og_group($group_type, $entity_id, $values);
    }
  }else{
    og_group($group_type, $gid, $values);
  }
  // og_group($group->type(), $group->getIdentifier(), $values);
}
function og_rules_get_groups_by_entity_type() {
  $groups_by_entity = array();
  $group_entity_types = og_get_all_group_entity();
  foreach ($group_entity_types as $entity_key => $entity_label) {
    $entity_groups = og_get_all_group($entity_key);
    $groups_by_entity[$entity_label][$entity_key . ':all'] = t('All');// for each type group, add option "All"
    foreach ($entity_groups as $entity_id) {
      $group_entity = entity_object_load($entity_id, $entity_key);
      $groups_by_entity[$entity_label][$entity_key . ':' . $entity_id] = $group_entity->title; 
    }
  }
  return $groups_by_entity;
}