Are there plans for Rules integration? specifically, we're looking for an event based on a user accepting an invite.

The use case is that we'd like to allow people to invite friends to the site, then using rules automatically flag those two users as friends. We're using Flag_friend for the friending side of things, so we can use rules to handle that side. It seems that the two things we would need via rules are:

1) an event based on one user accepting another user's invite
2) some way of accessing the uid of the person who issued the invite

That said, we can envision other scenarios where it might be useful to trigger off rules actions based on invites (like when invites expire, or when the invite limit for a user has been reached).

If this isn't planned, we can use some eval'd php code in rules to test whether a new user was invited. Is there something we can look for in the $user object at the point a new user is created that will indicate that he was invited to the site?

Comments

YK85’s picture

subscribing

Bilmar’s picture

+1 subscribing

smk-ka’s picture

Rules support would definitely be nice.

adub’s picture

+1

codevoice’s picture

+1

EmanueleQuinto’s picture

Version: 6.x-2.0-alpha1 » 6.x-2.0-beta2

Maybe this could help for a patch.

Based on Developer Documentation Adding new events.

Add the event invoking creation in invite_user() after the user save, before the latest unset($_SESSION[INVITE_SESSION]), around line 493 in invite.module.

  rules_invoke_event('user_invited', $account, $invite->inviter); 

Then somewhere in the module implement the hook_rules_event_info to let Drupal acknowledge the new event with its payload (user invited and inviter).

/**
* Implementation of hook_rules_event_info().
* @ingroup rules
*/
function invite_rules_event_info() {
  return array(
    'user_invited' => array(
      'label' => t('UserA accepts userB invite and completes registration'),
      'module' => 'Buddylist',
      'arguments' => array(
        'userA' => array('type' => 'user', 'label' => t('UserA, which is invited by userB.')),
        'userB' => array('type' => 'user', 'label' => t('UserB, which invites UserA.')),
      ),
    ),
  );
}
YK85’s picture

Title: Rules Integration? » Rules Integration
Status: Active » Needs review
robby.smith’s picture

this feature would be very very helpful!
subscribing

YK85’s picture

Status: Needs review » Reviewed & tested by the community

I tested this awhile ago and forgot to post back.
May the maintainer take a look and commit when possible?

Happy holidays!!

that0n3guy’s picture

Subscribing. This will also allow us to easily take care of the og_invites issues here: http://drupal.org/node/170332

chuckbar77’s picture

Great work! RTBC

paulap’s picture

Title: Rules Integration » Rules Integration - YESSSSS

Yes!

YK85’s picture

Please please commit =) This is great!

rjbrown99’s picture

Status: Reviewed & tested by the community » Active

Guys, this isn't RTBC because there is no patch attached to the issue. If #6 is the code change that solves this, the best bet would be to create a patch, attach it to this issue, and then mark it as "needs review". Once a few people have applied said patch, then move it to RTBC.

YK85’s picture

Could someone please kindly provide the code as a patch?
Further development of the Invite module would be awesome =)

owen barton’s picture

Title: Rules Integration - YESSSSS » Rules Integration
jordojuice’s picture

I like this idea and I think I'm going to work on this. I'm really into the Rules thing lately and I'm glad to contribute!

jordojuice’s picture

StatusFileSize
new88.12 KB

This patch is not fully functional, but it is not dangerous.
I put some rules together, however not all are operable. I haven't been coding Drupal modules for long, and I think I'm likely having trouble with the invite objects. I doubt it accurately obtains the user data, but I have written rules modules before and a lot of the right framework is in place in this patch nevertheless.
There are a few events:
User accepted invitation
User canceled invitation
User sent invitation
One condition:
Inviter has role
This condition has an altered form that retrieves available roles from the database and compares the selected role against a query on the inviter
And a couple actions:
Load invited user (only applies if an invite was accepted and completed)
Load inviting user
These I seem to be having trouble with, but I thought it would be good to post the patch here in case anyone can give some valuable input.
If anyone has suggestions for any other events, conditions, or actions then I'll be glad to look into it.

jordojuice’s picture

Component: Miscellaneous » Code
Status: Active » Needs work
that0n3guy’s picture

jordojuice, thats a pretty rough patch. It just removes everything and then re-adds it. Can you try redoing the patch so that we can just see what was added?

jordojuice’s picture

Yeah... so uhh that pretty much defeats the purpose! I'll get a good patch going when I'm back in town.

that0n3guy’s picture

Lol, yeah. I'll be testing it when you get it up. I have a project coming my way where this would be handy.

mattcasey’s picture

subscribing

brunorios1’s picture

subscribing...

isaac.niebeling’s picture

@jordojuice - Have you had a chance to work on this any more? It looks like your patch is just to the invite.module file, so aside from it replacing everything, the actual rules integration is missing. I'd love to help test once the patch is fixed.

jordojuice’s picture

Status: Needs work » Needs review
StatusFileSize
new89.79 KB
new34.58 KB

Alright, so I have indeed been working on it. This rules integration is really pretty simple, but more work may need to be done depending on whether anyone can think of more rules to add. Basically, the rules that exist deal with the inviter and invitee respectively. This is why it's quite easy. No conditions or actions were written because the core user conditions and actions are already available. The module simply loads the user and passes it to rules when an invite is sent, accepted, or cancelled. Accepted invites can have the inviter or invitee as arguments, while the other two only concern the inviter. Do let me know if you have any ideas for other rules.

I don't know why, but every time I try to create a patch git removes all the lines in invite.module and adds them, even though I only added three rules_invoke_event() calls to the file. They were basically added in the same places where Invite already calls module_invoke_all() on those events. So, this is all it is in those places:

if (module_exists('rules')) {
  rules_invoke_event('invite_invite_action', user_load($invite->inviter->uid));
}

I would guess you could probably just use $invite->inviter instead as I assume the object comes from global $user, right?

Anyways, I'll post the patch that I did get here. invite.rules.inc is at the bottom of the patch file and is surprisingly small for all it can do for the module. It's only an implementation of hook_rules_event_info() to identify the data types as user and gain access to all the rules user conditions and actions. I'll also post a zip file for convenience.

P.s. Any tips or suggestions on why I am not creating proper patches would be greatly appreciated. I'm admittedly new to git, but I followed the documentation at http://drupal.org/node/1054616 precisely and numerous times to no avail. It just believes I removed all the lines for some reason.

Talk to you soon!

jordojuice’s picture

If there are any conditions or actions anyone could think of that could make use of the $invite object (other than the users inviting and invited) I wrote a rules data type for "invite". I just haven't thought of any good reason to use the data type as these events are called on invites sent, accepted, or cancelled, so I saw no reason to manipulate the invite again. Maybe other users might have a condition or action suggestion? If so, please express that!

jordojuice’s picture

StatusFileSize
new3.32 KB

Got it. So, git was basically not working nicely with windows. It was using /n, thus replacing every line of the file so I turned that off. Attached is a proper, working patch for 6.x-2.x. I'll be posting a 7.x-2.x patch shortly after I test it.

jordojuice’s picture

StatusFileSize
new3.09 KB

And here's the 7.x-2.x patch. Any tests and feedback would be greatly appreciated. I'd be glad to implement any conditions or actions beyond what the 'user' data type provides by default if any Invite users have suggestions.

jordojuice’s picture

StatusFileSize
new3.09 KB

Ignore last patch. Forgot to convert tabs to spaces in Dreamweaver.

jordojuice’s picture

StatusFileSize
new5.48 KB

Ugh... and again 7.x-2.x patch to patch the patch. Just coding standards issues no substantive changes. Sloppy!

brunorios1’s picture

jordo, what steps should i do to add this integration?

you posted one zip file and two patches, i'm lost...

can i add this feature to 6.x-2.0-beta3?

thank you!

jordojuice’s picture

For 6.x the patch in #28 is good for Invite 6.x-2.x. Apply that patch only and it will add events for "Invitation was sent", "Invitation was accepted", and "Invitation was cancelled". These three events will give you access to the user that sent the invitation - or in the case of "Invitation was selected" the user that accepted the invitation. The other two patches were for the 7.x branch.

ezeedub’s picture

StatusFileSize
new2.84 KB

Here's a patch against 6.x-2.0-beta3.

To be honest, I'm still a bit sketchy on creating patches with git. The documentation appears to assume you're building a patch off a git checkout, but I'm doing so off a regular drupal.org download.

My method was to just read the beta2 patch, and duplicate it in my own install, and then create a patch. I tried testing that the patch I created worked, and, well, it didn't... :(

I tried a few things. One was to edit the patch file with

new file mode 100755
index 0000000..2cecdca
--- /dev/null

Anyway, my problem is either in how I'm creating the patch, or how I'm applying the thing... If anyone has advice, I'd appreciate it!

Cheers

bjalford’s picture

could someone post a patch fro d7 to test?

Sylense’s picture

+1 for D7 integration. The patches in #30 and #31 do not work with the newest dev.

milesw’s picture

Posted a new patch for D7 here: #1539336: Rules integration for D7

Let's leave this issue for D6.

svinod999’s picture

Have implemented the patch by Jordo in #28, the 6.x version... It works and emails get triggered using rules for the defined events (invites sent, accepted and cancelled). For the invites sent and cancelled, how can the invited email id be included in the mail body?

avpaderno’s picture

Version: 6.x-2.0-beta2 » 6.x-2.x-dev
Issue summary: View changes
Status: Needs review » Closed (outdated)

I am closing this issue, since it's for a Drupal version no longer supported.