Currently when using Rules with OG, if use the action 'Get group members from group audience' we will get a list of members which includes both pending and blocked users.

If we are using this action as part of a rule to send out content notifications, then this as bad as these notifications will be going to blocked and pending members. It's doubly bad if this is a private group.

I note in og_rules_action_info() that this 'todo' has been noted:

function og_rules_action_info() {
  $items = array();
  $items['og_get_members'] = array(
    'label' => t('Get group members from group audience'),
    'group' => t('Organic groups'),
    'parameter' => array(
      'group_content' => array(
        'type' => 'entity',
        'label' => t('Group content'),
        'description' => t('The group content determining the group audience.'),
      ),
      // @todo: Add option to filter by member-state?
    ),
    'provides' => array(
      'group_members' => array('type' => 'list<user>', 'label' => t('List of group members')),
    ),
    'base' => 'og_rules_get_members',
    'access callback' => 'og_rules_integration_access',
  );

Has there been any work towards completing this todo? If not, I'm happy to have a stab. Any pointers as to how best to go about this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

torrance123’s picture

Assigned: Unassigned » torrance123
Status: Active » Needs review
FileSize
1.77 KB

Please see attached patch of my first attempt.

This is against OG 7.x-2.x HEAD but it looks like it could be patched against OG 1.x too without issue.

amitaibu’s picture

Assigned: torrance123 » Unassigned
Category: feature » support
Priority: Major » Normal
Status: Needs review » Fixed

In 2.x you can already filter by member state using the wrapper (which should be exposed to Rules). For example -- $wrapper->{'og_membership__' . OG_STATE_ACTIVE}->value();

See og_entity_property_info()

torrance123’s picture

Status: Fixed » Needs work

Hi Amitaibu,

I'm confused. Are you suggesting I alter the patch to use the wrapper, or are you suggesting that the patch is unnecessary/the wrong way and the use case should be addressed by 'exposing' the wrapper to Rules?

Either way, our issue with the "Get group members from group audience" action appears to still remain — I don't think this is 'fixed'.

I'm still keen to make this work for us, but I need a little more guidance than looking at the code of og_entity_property_info().

torrance123’s picture

In 2.x you can already filter by member state using the wrapper (which should be exposed to Rules). For example -- $wrapper->{'og_membership__' . OG_STATE_ACTIVE}->value();

Or by this do you mean it's already possible to do this in Rules? I can see that I can filter og_membership by state, however the rule "Get group members from group audience" loads up users, not og_membership entities, and I'm not at all sure how to inject a state filter into that pipeline.

dooleysarahe’s picture

Did anything ever come of this? I am trying to figure out how to do the same thing.

jojonaloha’s picture

Category: Support request » Feature request
Issue summary: View changes
Status: Needs work » Needs review
FileSize
3.05 KB

I think torrance123 is right, I can't figure out how to do this through Rules UI at all. I've attached an updated patch that also adds the ability to filter by the Role in the group when getting a list of members.

Once you apply the patch, there are two new options in the "Get group members from group audience" action to filter the member list "Membership States" (thanks to torrance123) and "Group Roles".

shushu’s picture

Status: Needs review » Needs work

I think the feature request is decent, and checking the patch it seems to work as expected.
I think adding a "negative" checkbox to the "Membership states" condition will even make it stronger.
@jojonaloha, can you please add it ?

jojonaloha’s picture

I added two checkbox options for the action to allow loading users not in the selected state and/or not in the selected roles.

I also noticed a missing t() call in my previous patch.

shushu’s picture

Status: Needs review » Reviewed & tested by the community

Tested with several of the different options, all seems to work as expected.

Marko B’s picture

A Little hijack (sorry) but I when I use this action, I can't find proper data selector and nobody is mentioning this, I am trying og-membership:group but I get Unable to get variable group_members, it is not defined.

Marko B’s picture

Seems that [og-membership:entity] is the answer I was looking for. But please tell me if I am doing it wrong. sorry for inconvenience.

ZenLax’s picture

Saved my bacon. THANK YOU!!!

gatorjoe’s picture

#8 works perfectly for me. Thank you!

tony.herr’s picture

Has this patch been incorporated into any release yet?

travelertt’s picture

Patch #8 works for us.

jojonaloha’s picture

Sorry for adding new features to an existing issue. I would create a new issue but it would require this patch to be committed first. I also would not like to have this patch hold up #8 from being committed.

The new patch adds the ability to filter by User role as well, not just the group membership role. It could also be that we could do this another way in Rules.

Leaving in RTBC for #8. Will open a new issue if it gets committed.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 17: og-rules_filter_by_og_state_and_role-1859698-17.patch, failed testing.

dureaghin’s picture

Patch #8 works for us too. Thanks.

kyledesu’s picture

I haven't been successful on getting 8 to work on mine it still continues to pull all members.

aperedos’s picture

Patch #17 works for me. Thanks

Jan-E’s picture

FWIW: I re-applied patch #8 to OG 7.x-2.11.