Skip to:
Content

BuddyPress.org

Changeset 13874


Ignore:
Timestamp:
05/26/2024 04:56:49 AM (9 months ago)
Author:
imath
Message:

Groups: joining a group needs to wait for group status to be defined

When the group create first step is completed, the group's status has not been defined by the group creator yet and defaults to public. As the group status & the invite status are set once the group create second step is completed, we need to wait for this step to be achieved to let users join the group being created otherwise it would be possible for a user to "pre-join" a private/hidden group. Checking if the invite status is set is the only way to make sure this second step has been completed. If it's not the case, no need to go further in groups_join_group().

Fixes #9162
Closes https://github.com/buddypress/buddypress/pull/294

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r13873 r13874  
    662662    $group = bp_get_group( $group );
    663663
    664     if ( empty( $group->id ) ) {
     664    /*
     665     * When the group create first step is completed, the group's status has not been defined by the
     666     * group creator yet and defaults to public. As the group status & the invite status are set once
     667     * the group create second step is completed, we need to wait for this step to be achieved to let
     668     * users join the group being created otherwise it would be possible for a user to "pre-join" a
     669     * private/hidden group. Checking if the invite status is set is the only way to make sure this
     670     * second step has been completed. If it's not the case, no need to go further.
     671     */
     672    if ( empty( $group->id ) || ! groups_get_groupmeta( $group->id, 'invite_status' ) ) {
    665673        return false;
    666674    }
  • trunk/tests/phpunit/includes/factory.php

    r13414 r13874  
    9494
    9595        $this->default_generation_definitions = array(
    96             'name'         => new WP_UnitTest_Generator_Sequence( 'Group %s' ),
    97             'description'  => new WP_UnitTest_Generator_Sequence( 'Group description %s' ),
    98             'slug'         => new WP_UnitTest_Generator_Sequence( 'group-slug-%s' ),
    99             'status'       => 'public',
    100             'enable_forum' => true,
    101             'date_created' => bp_core_current_time(),
     96            'name'          => new WP_UnitTest_Generator_Sequence( 'Group %s' ),
     97            'description'   => new WP_UnitTest_Generator_Sequence( 'Group description %s' ),
     98            'slug'          => new WP_UnitTest_Generator_Sequence( 'group-slug-%s' ),
     99            'status'        => 'public',
     100            'enable_forum'  => true,
     101            'date_created'  => bp_core_current_time(),
     102            'invite_status' => 'members',
    102103        );
    103104    }
     
    131132        $last_activity = isset( $args['last_activity'] ) ? $args['last_activity'] : bp_core_current_time();
    132133        groups_update_groupmeta( $group_id, 'last_activity', $last_activity );
     134        groups_update_groupmeta( $group_id, 'invite_status', $args['invite_status'] );
     135
    133136
    134137        return $group_id;
  • trunk/tests/phpunit/testcases/groups/cache.php

    r13592 r13874  
    4242                    $time,
    4343                ),
     44                'invite_status' => array(
     45                    'members',
     46                ),
    4447                'foo' => array(
    4548                    'bar',
     
    5255                'last_activity' => array(
    5356                    $time,
     57                ),
     58                'invite_status' => array(
     59                    'members',
    5460                ),
    5561                'foo' => array(
  • trunk/tests/phpunit/testcases/groups/class-bp-groups-member.php

    r13437 r13874  
    208208        // Test with no status
    209209        // In bp_group_get_invite_status(), no status falls back to "members"
    210         $this->assertTrue( '' == groups_get_groupmeta( $g, 'invite_status' ) );
    211210        $this->assertFalse( bp_groups_user_can_send_invites( $g, $u_nonmembers ) );
    212211        $this->assertTrue( bp_groups_user_can_send_invites( $g, $u_members ) );
Note: See TracChangeset for help on using the changeset viewer.