Hello

I'm a bit unaware of a rules integration. Has this been partially implemented?

Some possible use cases:

  • create any kind of rule to affect groups or their content
  • cycle through groups and send email, update content, etc (via views_rules)
  • Import groups from LDAP server (via rules + views + feeds)

Comments

lpalgarvio created an issue. See original summary.

kristiaanvandeneynde’s picture

The module already supports Rules as far as Rules works with entities provided by Entity API.

Meaning you can already use Rules to:

  • Add a new Group
  • Create a new GroupMembership and save it (the equivalent of $group->addMember())
  • Add or remove a GroupRole from a GroupType
  • React on new GroupMembership or Group entities

What hasn't been done yet is custom Rules actions or conditions. Seeing as 90%+ of Group is pure Entity API CRUD-operations, there has been no custom Rules code yet given how much you can already accomplish out-of-the-box.

Useful Rules we may add could be:

  • E-mail all members of a Group, optionally filtered by GroupRole
  • Easier-to-understand labels for the above list: "Member joined group" sounds easier than "GroupMembership entity is created"
  • Feel free to add here
lpalgarvio’s picture

that's great :)

when i have the chance i will explore these.

shas3n’s picture

Rules integration will be really welcome!

Currently this is what I am trying to achieve with rule (and failing): When a group gets updated, the roles of all members should change based on a field value of the group.

I am trying to sell different kinds of groups (same group type, but different value on a list field) and the permissions for all users within this group will be different based on the value on the parent group's list field.

I was hoping to achieve this by defining different roles within the group and assign all users the roles based on the value of the field in the parent node.

kristiaanvandeneynde’s picture

Try this component to get you started:

{ "rules_add_role_to_group_members" : {
    "LABEL" : "Add role to group members",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "group" : { "label" : "Group", "type" : "group" },
      "group_role" : { "label" : "Group role", "type" : "group_role" }
    },
    "ACTION SET" : [
      { "entity_query" : {
          "USING" : {
            "type" : "group_membership",
            "property" : "group",
            "value" : [ "group" ],
            "limit" : "1000"
          },
          "PROVIDE" : { "entity_fetched" : { "group_memberships" : "Group memberships" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "group-memberships" ] },
          "ITEM" : { "group_membership" : "Group membership" },
          "DO" : [
            { "list_add" : {
                "list" : [ "group-membership:roles" ],
                "item" : [ "group-role" ],
                "unique" : "1"
              }
            },
            { "entity_save" : { "data" : [ "group-membership" ] } }
          ]
        }
      }
    ]
  }
}
shas3n’s picture

WoW! That was blazing fast!

Unfortunately I could not import the component in 7.x-1.0-beta6 or 7.x-1.0-beta6+8dev

I get error
Integrity check for the imported configuration failed. Error message: Data selector <em class="placeholder">group-membership:role</em> for parameter <em class="placeholder">list</em> is invalid..

I directly tried to import a component with the Rules UI. Am I doing something wrong?

kristiaanvandeneynde’s picture

Did you enable Entity Token? If so, try clearing caches.

shas3n’s picture

Entity tokens was enabled. Clearing cache did not help either. I am on Rule 7.x-2.9. I will try again after sometime.
Thanks again for your quick help.

kristiaanvandeneynde’s picture

Looking at your error more closely, I don't know why it says "group-membership:role" as it should clearly be group-membership:roles as shown in my export. If it still doesn't work, you should open a support request as this issue is getting derailed.

shas3n’s picture

I will open a new issue. [The roles->role was something with my own fiddling. The error is reappears with 'roles' too].

Rustan’s picture

When trying to import #5 I get the same error as #6, using current dev:

Integrity check for the imported configuration failed. Error message: Data selector <em class="placeholder">group-membership:roles</em> for parameter <em class="placeholder">list</em> is invalid..

kristiaanvandeneynde’s picture

Status: Active » Fixed

Hi, it looks like this is a bug in Rules.

I just tried to import the rule myself and got the same error. When I remove the offending action from the loop, I can import the rule just fine and add the action back in manually. So it really seems like Rules chokes on importing a component which manipulates data in a loop.

It could be worth browsing through https://www.drupal.org/project/issues/rules?text=import+loop&status=All

Closing this particular issue as fixed for the time being, unless it turns out to be a Group issue after all. Even though I really doubt it is.

Try importing the rule below and then manually adding the final piece to the loop:

{ "rules_add_role_to_group_members" : {
    "LABEL" : "Add role to group members",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "group" : { "label" : "Group", "type" : "group" },
      "group_role" : { "label" : "Group role", "type" : "group_role" }
    },
    "ACTION SET" : [
      { "entity_query" : {
          "USING" : {
            "type" : "group_membership",
            "property" : "group",
            "value" : [ "group" ],
            "limit" : "1000"
          },
          "PROVIDE" : { "entity_fetched" : { "group_memberships" : "Group memberships" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "group-memberships" ] },
          "ITEM" : { "group_membership" : "Group membership" },
          "DO" : [
            { "entity_save" : { "data" : [ "group-membership" ] } }
          ]
        }
      }
    ]
  }
}
Rustan’s picture

Importing the component in #12 works fine. I was trying this out while trying to solve another issue, cannot comment on how well it works for #4.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Pierre.Vriens’s picture

As a followup to the bullet "E-mail all members of a Group, optionally filtered by GroupRole" in comment #2, have a look at the answer to "How to send an email to all members of a group after the group is flagged?". The Rule and Rules Component include there are pretty close to what's needed: using a flag (to trigger the Rule), an eMail is deivered to all group members. The only thing it doesn't do is to filter it by some GroupRole, which you can do by simply adding that as an extra Rules Condition in the Rues Component.