Skip to:
Content

BuddyPress.org

Ticket #6025: 6025.01-post-5911.patch

File 6025.01-post-5911.patch, 4.6 KB (added by dcavins, 12 years ago)

Requires math's changes in #5911

  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index 330b5ca..5afe41f 100644
    function groups_send_invites( $user_id, $group_id ) {  
    10571057        do_action( 'groups_send_invites', $group_id, $invited_users );
    10581058}
    10591059
     1060/**
     1061 * Send specific pending group invitations keyed by group, invitee and inviter id
     1062 *
     1063 * @param int   $group_id       ID of the group.
     1064 * @param int   $invitee_id ID of the invited user.
     1065 * @param int   $inviter_id ID of the user who created the invitation.
     1066 * @param bool  $resend         Whether to resend notification email if already sent.
     1067 *
     1068 * @since BuddyPress (2.2.0)
     1069 */
     1070function groups_send_invite_by_invitee( $group_id, $invitee_id, $inviter_id, $resend = false ) {
     1071
     1072        if ( empty( $group_id ) || empty( $invitee_id ) || empty( $inviter_id ) ) {
     1073                return false;
     1074        }
     1075
     1076        // Check that an invitation exists for this invitee/group/inviter combination.
     1077        // $type = 'all' checks for sent or unsent invitations.
     1078        if ( ! groups_check_user_has_invite( $invitee_id, $group_id, $type = 'all', $inviter_id ) ) {
     1079                return false;
     1080        }
     1081
     1082        $group = groups_get_group( array( 'group_id' => $group_id ) );
     1083        $member = new BP_Groups_Member( $invitee_id, $group_id );
     1084
     1085        // Send the invitation email.
     1086        groups_notification_group_invites( $group, $member, $inviter_id, $resend );
     1087
     1088        $member->invite_sent = 1;
     1089        $member->save();
     1090
     1091        // Invoke the same action as groups_send_invites().
     1092        do_action( 'groups_send_invites', $group_id, array( $invitee_id ) );
     1093}
     1094
    10601095function groups_get_invites_for_group( $user_id, $group_id ) {
    10611096        return BP_Groups_Group::get_invites( $user_id, $group_id );
    10621097}
  • src/bp-groups/bp-groups-notifications.php

    diff --git src/bp-groups/bp-groups-notifications.php src/bp-groups/bp-groups-notifications.php
    index c4b1a48..a01dd91 100644
    add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10,  
    296296 *
    297297 * @since BuddyPress (1.0.0)
    298298 *
    299  * @param BP_Groups_Group $group Group object.
    300  * @param BP_Groups_Member $member Member object.
    301  * @param int $inviter_user_id ID of the user who sent the invite.
    302  * @return bool|null False on failure.
     299 * @param       BP_Groups_Group  $group  Group object.
     300 * @param       BP_Groups_Member  $member  Member object.
     301 * @param       int  $inviter_user_id  ID of the user who sent the invite.
     302 * @param       bool  $resend  Whether to resend notification email if already sent.
     303 * @return      bool|null       False on failure.
    303304 */
    304 function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
     305function groups_notification_group_invites( &$group, &$member, $inviter_user_id, $resend = false ) {
    305306
    306         // Bail if member has already been invited
    307         if ( ! empty( $member->invite_sent ) ) {
     307        // Bail if member has already been invited, and $resend isn't specified.
     308        if ( ! $resend && ! empty( $member->invite_sent ) ) {
    308309                return;
    309310        }
    310311
  • tests/phpunit/testcases/groups/class-bp-groups-member.php

    diff --git tests/phpunit/testcases/groups/class-bp-groups-member.php tests/phpunit/testcases/groups/class-bp-groups-member.php
    index 7d1aad3..7407587 100644
    class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase {  
    1212                parent::tearDown();
    1313        }
    1414
    15         public static function invite_user_to_group( $user_id, $group_id, $inviter_id ) {
     15        public static function invite_user_to_group( $user_id, $group_id, $inviter_id, $draft = false ) {
    1616                $invite                = new BP_Groups_Member;
    1717                $invite->group_id      = $group_id;
    1818                $invite->user_id       = $user_id;
    1919                $invite->date_modified = bp_core_current_time();
    2020                $invite->inviter_id    = $inviter_id;
    2121                $invite->is_confirmed  = 0;
    22                 $invite->invite_sent   = 1;
     22                $invite->invite_sent   = $draft ? 0 : 1;
    2323
    2424                $invite->save();
    2525                return $invite->id;
    … … class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase {  
    127127                $ids = wp_list_pluck( $mm, 'user_id' );
    128128                $this->assertEquals( array( $u2 ), $ids );
    129129        }
     130
     131        public function test_groups_send_invite_by_invitee() {
     132                $g1 = $this->factory->group->create();
     133
     134                $u1 = $this->factory->user->create();
     135                $u2 = $this->factory->user->create();
     136                self::add_user_to_group( $u1, $g1 );
     137
     138                // Create unsent invitation
     139                self::invite_user_to_group( $u2, $g1, $u1, $draft = true );
     140                $this->assertTrue( is_null( groups_check_user_has_invite( $u2, $g1, $type = 'sent', $u1 ) ) );
     141
     142                groups_send_invite_by_invitee( $g1, $u2, $u1 );
     143
     144                $this->assertTrue( is_numeric( groups_check_user_has_invite( $u2, $g1, $type = 'sent', $u1 ) ) );
     145
     146        }
    130147}
    131148