Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/12/2014 01:26:36 AM (12 years ago)
Author:
boonebgorges
Message:

Overhaul access and visibility control for group tabs

Previously, access control to group tabs was handled in two ways:

  • for BP_Group_Extension tabs, the 'enable_nav_item' and 'visibility' provided some control over access to plugin developers, though it was inconsistent, buggy, and difficult to implement properly
  • for tabs provided by bp-groups, access to the tabs of non-public groups was controlled directly in the BP_Groups_Component::setup_globals() method

Aside from being unclear for developers, this technique for controlling access
was also inflexible. For non-public groups, tab access was hardcoded and
handled before BP_Group_Extension plugins even had a chance to load. As a
result, it was essentially impossible to add public tabs to non-public groups
(among other non-standard customizations).

The current changeset comprises a number of changes that make tab access more
consistent and flexible:

  • Access control is moved to the new bp_groups_group_access_protection() function. This function has the necessary filters to customize access protection in arbitrary ways. And because it loads at 'bp_actions' - just before the page begins to render - all extensions have had a chance to load and register themselves with the desired access settings.
  • The 'visibility' and 'enable_nav_item' properties of BP_Group_Extension are phased out in favor of 'access' and 'show_tab' params. 'access' controls who can visit the tab, while 'show_tab' controls who can see the item in the navigation. These new properties have intelligent defaults (based on the privacy level of the group), but can be overridden with a number of custom settings: 'admin', 'mod', 'member', 'loggedin', 'anyone', or 'noone'. Backward compatibility is maintained, so that existing BP_Group_Extension plugins that use enable_nav_item or visibility will continue to work as before.

Fixes #4785

Props boonebgorges, dcavins, imath

File:
1 edited

Legend:

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

    r8568 r8605  
    269269        }
    270270
    271         // Group access control
    272         if ( bp_is_groups_component() && !empty( $this->current_group ) ) {
    273             if ( !$this->current_group->user_has_access ) {
    274 
    275                 // Hidden groups should return a 404 for non-members.
    276                 // Unset the current group so that you're not redirected
    277                 // to the default group tab
    278                 if ( 'hidden' == $this->current_group->status ) {
    279                     $this->current_group = 0;
    280                     $bp->is_single_item  = false;
    281                     bp_do_404();
    282                     return;
    283 
    284                 // Skip the no_access check on home and membership request pages
    285                 } elseif ( !bp_is_current_action( 'home' ) && !bp_is_current_action( 'request-membership' ) ) {
    286 
    287                     // Off-limits to this user. Throw an error and redirect to the group's home page
    288                     if ( is_user_logged_in() ) {
    289                         bp_core_no_access( array(
    290                             'message'  => __( 'You do not have access to this group.', 'buddypress' ),
    291                             'root'     => bp_get_group_permalink( $bp->groups->current_group ) . 'home/',
    292                             'redirect' => false
    293                         ) );
    294 
    295                     // User does not have access, and does not get a message
    296                     } else {
    297                         bp_core_no_access();
    298                     }
    299                 }
    300             }
    301 
    302             // Protect the admin tab from non-admins
    303             if ( bp_is_current_action( 'admin' ) && !bp_is_item_admin() ) {
    304                 bp_core_no_access( array(
    305                     'message'  => __( 'You are not an admin of this group.', 'buddypress' ),
    306                     'root'     => bp_get_group_permalink( $bp->groups->current_group ),
    307                     'redirect' => false
    308                 ) );
    309             }
    310         }
    311 
    312271        // Preconfigured group creation steps
    313272        $this->group_creation_steps = apply_filters( 'groups_create_group_steps', array(
     
    482441                'position'        => 60,
    483442                'user_has_access' => $this->current_group->user_has_access,
    484                 'item_css_id'     => 'members'
     443                'item_css_id'     => 'members',
     444                'no_access_url'   => $group_link,
    485445            );
    486446
     
    494454                    'item_css_id'     => 'invite',
    495455                    'position'        => 70,
    496                     'user_has_access' => $this->current_group->user_has_access
     456                    'user_has_access' => $this->current_group->user_has_access,
     457                    'no_access_url'   => $group_link,
    497458                );
    498459            }
     
    508469                    'position'        => 1000,
    509470                    'user_has_access' => true,
    510                     'item_css_id'     => 'admin'
     471                    'item_css_id'     => 'admin',
     472                    'no_access_url'   => $group_link,
    511473                );
    512474            }
Note: See TracChangeset for help on using the changeset viewer.