A question if I am on the right track.

Events happening in the community are now at Drupal community events on www.drupal.org.
paul_constantine's picture

Hello all,

I don't really know if my question is right here. So I'll just go ahead and ask. I've been building a little social site for friends and family. But I am having a hard time setting up certain rules.

This may be because what I am trying to is not possible with rules. Or because my understanding of rules and the language used within isn't adequate. Anyway here it goes:

As with most social sites my site (https://www.zooot.net) is very selective about who gets to see what. To achieve that I based my whole site on "Organic Groups".

  • Everyone who registers at the site automatically gets his own private group with his own name (registration name = group name). This I managed to set up with rules.
  • All the nodes are group-nodes which you may post into your original private group or in any private groups you create after you join.
  • I integrated "User Relationships" and "Invite" to allow users to invite others and to form relationships with them.

What I am trying to do: when two users approve a two-way relationship I would like a Rule to automatically add them to each others original private groups as members.

To prevent spam another Rule should forbid site members from adding other site members to their groups UNLESS they have formed a confirmed two-way relationship with UR.

This I can not get working.

Is that possible?

Best wishes,
Paul

Comments

You will need to outline what

Bob Newby's picture

You will need to outline what is not working.

Bob

I've never used Organic

Funksmaname's picture

I've never used Organic Groups - but as a possible nudge in the right direction you might use user flags (flags module) to let people flag eachother, and trigger rules on when a user is flagged IF they are already flagged by the first user.

Once you have the two users in scope you should be able to load each users group and add eachother to them

Flags

paul_constantine's picture

Hello Funksmaname,

Thank your for your Idea. I will look into the possibilities of flags.

Don't know if that will solve my problem though, since my users are already using the "Invite" and "UR" module on the site, so bringing in a third method to friend each other might be a little confusing. But I'll have a look anyway.

Have a nice Tuesday,
Paul

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Data selector confusion.

paul_constantine's picture

Hi Bob,

my problem is that after a certain point I can not make heads or tails of the data selections offered be the rules system. In my example of trying to auto-add confirmed two-way relationships to each others private groups I start like this.

  • Create a rule, i.e. "Add contacts to groups".
  • React on event: "A user relationship has been approved"
  • Save
  • Action: "Subscribe user to group"
  • User, Data selector: "site:current-user"
  • Group, Data selector: "???"
  • ...

Somehow I have the feeling that I am not really setting this up the right way at all. And the options ins the data selectors don't make any sense to me at all.

Have a nice Tuesday,
Paul

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Another try, another fail :-/

paul_constantine's picture

Tried it again today. But am not able to define the propper groups.

{ "rules_add_contacts_to_groups_" : {
    "LABEL" : "Add contacts to groups.",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "og", "user_relationships_rules" ],
    "ON" : [ "user_relationships_approve" ],
    "DO" : [
      { "og_group_content_add" : {
          "entity" : [ "requester" ],
          "group" : [ "requestee:og-user-group-ref:3" ]
        }
      },
      { "og_group_content_add" : {
          "entity" : [ "requestee" ],
          "group" : [ "requester:og-user-group-ref:3" ]
        }
      }
    ]
  }
}

Each user has a private group that has the same name as the user. I found that I can define the "requester:name" and the "requestee:name" but I couldn't insert it anywhere.

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Finally nailed it.

paul_constantine's picture

Now it works. It was just a matter of trying out the different selectors.

{ "rules_add_contacts_to_groups_" : {
    "LABEL" : "Add contacts to groups.",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "og", "user_relationships_rules" ],
    "ON" : [ "user_relationships_approve" ],
    "DO" : [
      { "og_group_content_add" : {
          "entity" : [ "requester" ],
          "group" : [ "requestee:og-user-group-ref:1" ]
        }
      },
      { "og_group_content_add" : {
          "entity" : [ "requestee" ],
          "group" : [ "requester:og-user-group-ref:1" ]
        }
      }
    ]
  }
}

Now I just have to write a removal rule for when two members break their relationship.

Update: Spoke too soon. It is working alright, but it picks the group to which to add in alphabetical order. So I need to find a way to define the name of the group (group name = requestee/requester name).

Any ideas anyone?

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Another try.

paul_constantine's picture

This looked promising, unfortunately it does not do anything.

At least it feels like I am getting closer.

{ "rules_add_contacts_to_groups_" : {
    "LABEL" : "Add Relationships to Private Groups",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "UR OG Rules" ],
    "REQUIRES" : [ "rules", "og", "user_relationships_rules" ],
    "ON" : [ "user_relationships_approve" ],
    "DO" : [
      { "entity_query" : {
          "USING" : {
            "type" : "node",
            "property" : "group_group",
            "value" : [ "requester:name" ],
            "limit" : "1"
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "entity-fetched" ] },
          "ITEM" : { "list_item_requester" : "Current list item" },
          "DO" : [
            { "og_group_content_add" : { "entity" : [ "requestee" ], "group" : [ "list-item-requester" ] } }
          ]
        }
      },
      { "entity_query" : {
          "USING" : {
            "type" : "node",
            "property" : "group_group",
            "value" : [ "requestee:name" ],
            "limit" : "1"
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched_requestee" : "Fetched entity_requestee" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "entity-fetched-requestee" ] },
          "ITEM" : { "list_item_requestee" : "Current list item" },
          "DO" : [
            { "og_group_content_add" : { "entity" : [ "requester" ], "group" : [ "list-item-requestee" ] } }
          ]
        }
      }
    ]
  }
}

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Rules loops versus custom flags

Bob Newby's picture

Paul,

I have never had any success with Rules loops, so I don't use them. Therefore, unfortunately I cannot help you navigate the territory you're in.

FYI, I use flags and custom code to manage various business rules, with the flags usually set using Rules and the custom code triggered by hook_cron implementations. Depending on the case, the custom code leverages the APIs of other modules and/or Drupal's database API.

Cheers,

Bob

Way over my head.

paul_constantine's picture

Hello Bob,

my skills as a programmer are way below "...custom code triggered by hook_cron implementations..." so I will have to stick with rules for the time being.

My exploits so far showed me that rules should be able to do what I want. It is just a matter of selecting the right groups that makes this a real headache for me (the rules data selectors for OG might as well be in Chinese).

Coming back to flags.

Is there is a way to automatically add a flag to the private group that is auto-created during registration for each user? Can rules identify that flag (without showing endless pages of totally incomprehensible data-options like OG-Rules)?

Cheers,
Paul

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Flags

Bob Newby's picture

Re: "Is there is a way to automatically add a flag to the private group that is auto-created during registration for each user? Can rules identify that flag (without showing endless pages of totally incomprehensible data-options like OG-Rules)?"

Yes there is. Assuming you are on D7...

You can add whatever flags you need -- such as a flag named "New Private Group" -- at admin/structure/flags. Now you can "flag" or "unflag" each Private Group node whenever you need to.

Note that each flag is a Drupal entity, meaning you can also add fields to it, just like you can with each Drupal content type.

Now the flag is available so that a rule can "flag" or "unflag" a Private Group upon various events, as needed. When "flagging" a PG the values of the flag's custom fields can also be set.

Unfortunately the term flag is overloaded in Drupal-speak, which is why I used quotes above.

I hope that is not too unclear. When used with Rules, the Flag module can be very powerful. Also, you can have users "flag" something, and then capture these "flagging" events in Rules, so as to respond to them. E.g., a user "flags" an item of content as being "offensive"; this event triggers a Rule to respond to it; and the Rule sends you (the site's owner) a suitable email, including the identities of the user and of the piece of content in question...

I hope that helps. As with each of Drupal's powerful modules, there is a non-trivial learning curve.

Bob

Installed Flag.

paul_constantine's picture

Good day Bob,

the more I play around with this the more I come to the conclusion that my difficulty lies within the OG data-selectors.

  • I installed flag - nice module by the way - and activated it. After that I added a global flag for the node type "private group".
  • Then I went to the rules and opened the rule that automatically creates the user's private group upon registration.
  • I tried to add an action that would flag the newly created private group.
  • And here we are again: the totally incomprehensible data-selections of OG.

Rules needs to know which group to flag. Or to add to. No matter what I do, I always hit the wall when I come to the OG data-selectors.

Maybe I am stupid, but these things don't make too much sense to me. I wish there would be some documentation - especially on the meaning of the numbers behind the selectors (i.e. 0, 1, 2, 3, 0:, 1:, 2:, 3:, 1:0, 1:1, 1:2, 1:3, ...). I know that ":" means you can add another selector. But without knowing the system behind the numbers, this is getting me nowhere.

site:current-user
site:current-user:og-user-group-ref:  
site:current-user:og-user-node:   
site:current-user:og-membership:  
site:current-user:og-membership--1:   
site:current-user:og-membership--2:   
site:current-user:og-membership--3:   
site:current-user:og-user-group-ref--og-membership:   
site:current-user:og-user-group-ref--og-membership--1:
site:current-user:og-user-group-ref--og-membership--2:
site:current-user:og-user-group-ref--og-membership--3:
site:current-user:og-user-node--og-membership:
site:current-user:og-user-node--og-membership--1: 
site:current-user:og-user-node--og-membership--2: 
site:current-user:og-user-node--og-membership--3: 
site:current-user:roles:  
account    Registered user
account:og-user-group-ref:0   
account:og-user-group-ref:1   
account:og-user-group-ref:2   
account:og-user-group-ref:3   
account:og-user-group-ref:0:  
account:og-user-group-ref:1:  
account:og-user-group-ref:2:  
account:og-user-group-ref:3:  
account:og-user-node:0
account:og-user-node:1
account:og-user-node:2
account:og-user-node:3
account:og-user-node:0:   
account:og-user-node:1:   
account:og-user-node:2:   
account:og-user-node:3:   
account:og-membership:0   
account:og-membership:1   
account:og-membership:2   
account:og-membership:3   
account:og-membership:0:  
account:og-membership:1:  
account:og-membership:2:  
account:og-membership:3:  
account:og-membership--1:0    
account:og-membership--1:1    
account:og-membership--1:2    
account:og-membership--1:3    
account:og-membership--1:0:       
account:og-membership--1:1:       
account:og-membership--1:2:       
account:og-membership--1:3:       
account:og-membership--2:0    
account:og-membership--2:1    
account:og-membership--2:2    
account:og-membership--2:3    
account:og-membership--2:0:       
account:og-membership--2:1:       
account:og-membership--2:2:       
account:og-membership--2:3:       
account:og-membership--3:0    
account:og-membership--3:1    
account:og-membership--3:2    
account:og-membership--3:3    
account:og-membership--3:0:       
account:og-membership--3:1:       
account:og-membership--3:2:       
account:og-membership--3:3:       
account:og-user-group-ref--og-membership:0
account:og-user-group-ref--og-membership:1
account:og-user-group-ref--og-membership:2
account:og-user-group-ref--og-membership:3
account:og-user-group-ref--og-membership:0:   
account:og-user-group-ref--og-membership:1:   
account:og-user-group-ref--og-membership:2:   
account:og-user-group-ref--og-membership:3:   
account:og-user-group-ref--og-membership--1:0 
account:og-user-group-ref--og-membership--1:1 
account:og-user-group-ref--og-membership--1:2 
account:og-user-group-ref--og-membership--1:3 
account:og-user-group-ref--og-membership--1:0:
account:og-user-group-ref--og-membership--1:1:
account:og-user-group-ref--og-membership--1:2:
account:og-user-group-ref--og-membership--1:3:
account:og-user-group-ref--og-membership--2:0 
account:og-user-group-ref--og-membership--2:1 
account:og-user-group-ref--og-membership--2:2 
account:og-user-group-ref--og-membership--2:3 
account:og-user-group-ref--og-membership--2:0:
account:og-user-group-ref--og-membership--2:1:
account:og-user-group-ref--og-membership--2:2:
account:og-user-group-ref--og-membership--2:3:
account:og-user-group-ref--og-membership--3:0 
account:og-user-group-ref--og-membership--3:1 
account:og-user-group-ref--og-membership--3:2 
account:og-user-group-ref--og-membership--3:3 
account:og-user-group-ref--og-membership--3:0:
account:og-user-group-ref--og-membership--3:1:
account:og-user-group-ref--og-membership--3:2:
account:og-user-group-ref--og-membership--3:3:
account:og-user-node--og-membership:0 
account:og-user-node--og-membership:1 
account:og-user-node--og-membership:2 
account:og-user-node--og-membership:3 
account:og-user-node--og-membership:0:
account:og-user-node--og-membership:1:
account:og-user-node--og-membership:2:
account:og-user-node--og-membership:3:
account:og-user-node--og-membership--1:0  
account:og-user-node--og-membership--1:1  
account:og-user-node--og-membership--1:2  
account:og-user-node--og-membership--1:3  
account:og-user-node--og-membership--1:0: 
account:og-user-node--og-membership--1:1: 
account:og-user-node--og-membership--1:2: 
account:og-user-node--og-membership--1:3: 
account:og-user-node--og-membership--2:0  
account:og-user-node--og-membership--2:1  
account:og-user-node--og-membership--2:2  
account:og-user-node--og-membership--2:3  
account:og-user-node--og-membership--2:0: 
account:og-user-node--og-membership--2:1: 
account:og-user-node--og-membership--2:2: 
account:og-user-node--og-membership--2:3: 
account:og-user-node--og-membership--3:0  
account:og-user-node--og-membership--3:1  
account:og-user-node--og-membership--3:2  
account:og-user-node--og-membership--3:3  
account:og-user-node--og-membership--3:0: 
account:og-user-node--og-membership--3:1: 
account:og-user-node--og-membership--3:2: 
account:og-user-node--og-membership--3:3: 

Another thing: Since every user who registers an account gets his own private group (even with a flag), how will rules pick out the right group when people are members of many groups (each one with a flag)?

Have a nice Thursday,
Paul

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Challenge solved.

paul_constantine's picture

Sometimes you dig and dig and overlook the most obvious solution:

Since the groups in question already have one unique identifyer "their node title, which equals the author's name" I just had to change one little aspect to make this work:

Match node title to the user names.

{ "rules_add_contacts_to_groups_" : {
    "LABEL" : "Add Relationships to Private Groups",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "UR OG Rules" ],
    "REQUIRES" : [ "rules", "og", "user_relationships_rules" ],
    "ON" : [ "user_relationships_approve" ],
    "DO" : [
      { "entity_query" : {
          "USING" : { "type" : "node", "property" : "title", "value" : [ "requestee:name" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched_requestee" : "Fetched entity requestee" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "entity-fetched-requestee" ] },
          "ITEM" : { "list_item_requestee" : "Current list item" },
          "DO" : [
            { "og_subcribe_user" : { "user" : [ "requester" ], "group" : [ "list-item-requestee" ] } }
          ]
        }
      },
      { "entity_query" : {
          "USING" : { "type" : "node", "property" : "title", "value" : [ "requester:name" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched_requester" : "Fetched entity requester" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "entity-fetched-requester" ] },
          "ITEM" : { "list_item_requester" : "Current list item" },
          "DO" : [
            { "og_subcribe_user" : { "user" : [ "requestee" ], "group" : [ "list-item-requester" ] } }
          ]
        }
      }
    ]
  }
}

Many thanks to all and specially to bob for his patience and input.

Paul

Kind regards,
Paul

Zooot Net
Your Own Social Network.


Use secure communication with OpenPGP.

Encrypt with public key: 34A447B1675A9463
Verify key with hash: 570C 0051 3B68 CAFB 98BA 1EEF 34A4 47B1 675A 9463

Congratulations! Isn't it

Bob Newby's picture

Congratulations!

Isn't it weird that the solution to a problem is always the last thing we give a try?

:)

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: