Ticket #7423: 7423.02.patch
File 7423.02.patch, 4.2 KB (added by , 8 years ago) |
---|
-
src/bp-groups/bp-groups-screens.php
21 21 */ 22 22 function groups_directory_groups_setup() { 23 23 if ( bp_is_groups_directory() ) { 24 // Set group type if available.25 if ( bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) {26 $matched_types = bp_groups_get_group_types( array(27 'has_directory' => true,28 'directory_slug' => bp_action_variable(),29 ) );30 31 // Redirect back to group directory if no match.32 if ( empty( $matched_types ) ) {33 bp_core_redirect( bp_get_groups_directory_permalink() );34 }35 36 // Set our global variable.37 buddypress()->groups->current_directory_type = reset( $matched_types );38 }39 40 24 bp_update_is_directory( true, 'groups' ); 41 25 42 26 /** -
src/bp-groups/classes/class-bp-groups-component.php
267 267 $this->current_group = 0; 268 268 } 269 269 270 // Set group type if available. 271 if ( bp_is_groups_directory() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) { 272 $matched_types = bp_groups_get_group_types( array( 273 'has_directory' => true, 274 'directory_slug' => bp_action_variable(), 275 ) ); 276 277 // Set 404 if we do not have a valid group type. 278 if ( empty( $matched_types ) ) { 279 bp_do_404(); 280 return; 281 } 282 283 // Set our directory type marker. 284 $this->current_directory_type = reset( $matched_types ); 285 } 286 270 287 // Set up variables specific to the group creation process. 271 288 if ( bp_is_groups_component() && bp_is_current_action( 'create' ) && bp_user_can_create_groups() && isset( $_COOKIE['bp_new_group_id'] ) ) { 272 289 $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id']; … … 297 314 ) ); 298 315 299 316 // If the user was attempting to access a group, but no group by that name was found, 404. 300 if ( bp_is_groups_component() && empty( $this->current_group ) && bp_current_action() && !in_array( bp_current_action(), $this->forbidden_names ) ) {317 if ( bp_is_groups_component() && empty( $this->current_group ) && empty( $this->current_directory_type ) && bp_current_action() && ! in_array( bp_current_action(), $this->forbidden_names ) ) { 301 318 bp_do_404(); 302 319 return; 303 320 } -
tests/phpunit/testcases/routing/groups.php
27 27 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_groups_slug() . '/invites' ); 28 28 $this->assertTrue( bp_is_user_groups() && bp_is_current_action( 'invites' ) ); 29 29 } 30 31 /** 32 * @group group_types 33 */ 34 public function test_group_directory_with_type() { 35 bp_groups_register_group_type( 'foo' ); 36 $this->go_to( bp_get_groups_directory_permalink() . 'type/foo/' ); 37 $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foo', 0 ) ); 38 } 39 40 /** 41 * @group group_types 42 */ 43 public function test_group_directory_with_type_that_has_custom_directory_slug() { 44 bp_groups_register_group_type( 'foo', array( 'has_directory' => 'foos' ) ); 45 $this->go_to( bp_get_groups_directory_permalink() . 'type/foos/' ); 46 $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foos', 0 ) ); 47 } 48 49 /** 50 * @group group_types 51 */ 52 public function test_group_directory_should_404_for_group_types_that_have_no_directory() { 53 bp_register_member_type( 'foo', array( 'has_directory' => false ) ); 54 $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' ); 55 $this->assertTrue( is_404() ); 56 } 57 58 /** 59 * @group group_types 60 */ 61 public function test_group_directory_should_404_for_invalid_group_types() { 62 $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' ); 63 $this->assertTrue( is_404() ); 64 } 30 65 }