Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/03/2014 12:04:40 PM (11 years ago)
Author:
boonebgorges
Message:

Introduce 'no_access_url' param to bp_core_new_subnav_item()

bp_core_new_subnav_item() allows access to be controlled using the
'show_for_displayed_user' parameter. When this param is false for a given user,
the function attempts to determine a proper redirect URL. But this URL
determining logic assumes that we are looking at a user profile, while BP uses
bp_core_new_subnav_item() for group navigation as well. Rather than attempting
to bake more URL determination logic into bp_core_new_subnav_item() itself, we
introduce a 'no_access_url' parameter that allows calling functions to specify
dynamically the URL that users should be directed to when they do not have
permission to access a requested subnav item.

Fixes #5720

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/nav.php

    r8545 r8556  
    285285        buddypress()->bp_nav = $old_bp_nav;
    286286    }
     287
     288    /**
     289     * @group bp_core_maybe_hook_new_subnav_screen_function
     290     */
     291    public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_group() {
     292        $u = $this->create_user();
     293        $g = $this->factory->group->create();
     294        $old_current_user = get_current_user_id();
     295        $this->set_current_user( $u );
     296
     297        $group = groups_get_group( array(
     298            'group_id' => $g,
     299        ) );
     300
     301        $this->go_to( bp_get_group_permalink( $group ) );
     302
     303        $subnav_item = array(
     304            'user_has_access' => false,
     305            'no_access_url' => bp_get_group_permalink( $group ),
     306        );
     307
     308        // Just test relevant info
     309        $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
     310        $this->assertSame( 'failure', $found['status'] );
     311        $this->assertSame( bp_get_group_permalink( $group ), $found['redirect_args']['root'] );
     312
     313        // Clean up
     314        $this->set_current_user( $old_current_user );
     315    }
     316
     317    /**
     318     * @group bp_core_maybe_hook_new_subnav_screen_function
     319     */
     320    public function test_maybe_hook_new_subnav_screen_function_user_has_access_false_user_logged_in_group_no_redirect_url_provided() {
     321        $u = $this->create_user();
     322        $g = $this->factory->group->create();
     323        $old_current_user = get_current_user_id();
     324        $this->set_current_user( $u );
     325
     326        $group = groups_get_group( array(
     327            'group_id' => $g,
     328        ) );
     329
     330        $this->go_to( bp_get_group_permalink( $group ) );
     331
     332        $subnav_item = array(
     333            'user_has_access' => false,
     334        );
     335
     336        // Just test relevant info
     337        $found = bp_core_maybe_hook_new_subnav_screen_function( $subnav_item );
     338        $this->assertSame( 'failure', $found['status'] );
     339        $this->assertSame( bp_get_root_domain(), $found['redirect_args']['root'] );
     340
     341        // Clean up
     342        $this->set_current_user( $old_current_user );
     343    }
    287344}
Note: See TracChangeset for help on using the changeset viewer.