Skip to content

Commit

Permalink
experimental access control
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanReeve committed Oct 31, 2014
1 parent 57962b9 commit 8454fbf
Showing 1 changed file with 68 additions and 9 deletions.
77 changes: 68 additions & 9 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,73 @@ function bp_docs_get_doc_settings( $doc_id = 0 ) {
$saved_settings = array();
}

$default_settings = array(
'read' => 'anyone',
'edit' => 'loggedin',
'read_comments' => 'anyone',
'post_comments' => 'anyone',
'view_history' => 'anyone',
'manage' => 'creator',
);
// First, try to set the preselected group by looking at the URL params
$selected_group_slug = isset( $_GET['group'] ) ? $_GET['group'] : '';

// Support for BP Group Hierarchy
if ( false !== $slash = strrpos( $selected_group_slug, '/' ) ) {
$selected_group_slug = substr( $selected_group_slug, $slash + 1 );
}

$selected_group = BP_Groups_Group::get_id_from_slug( $selected_group_slug );
if ( $selected_group && ! BP_Docs_Groups_Integration::user_can_associate_doc_with_group( bp_loggedin_user_id(), $selected_group ) ) {
$selected_group = 0;
}

// If the selected group is still 0, see if there's something in the db
if ( ! $selected_group && is_singular() ) {
$selected_group = bp_docs_get_associated_group_id( get_the_ID() );
}

// @todo: get the type (public, private, hidden) of the group

_log( 'selected group is:' );
_log( $selected_group );
_log( 'group meta:' );
$group = groups_get_group( array( 'group_id' => $selected_group ) );
_log( $group );
_log( 'group status:' );
_log( $group->status );
switch ( $group->status ) {
case 'public':
$default_settings = array(
'read' => 'anyone',
'edit' => 'loggedin',
'read_comments' => 'anyone',
'post_comments' => 'loggedin',
'view_history' => 'anyone',
'manage' => 'creator',
);
case 'private':
$default_settings = array(
'read' => 'anyone',
'edit' => 'group-members',
'read_comments' => 'anyone',
'post_comments' => 'group-members',
'view_history' => 'anyone',
'manage' => 'creator',
);
case 'hidden':
_log( 'hidden group!' );
$default_settings = array(
'read' => 'group-members',
'edit' => 'group-members',
'read_comments' => 'group-members',
'post_comments' => 'group-members',
'view_history' => 'group-members',
'manage' => 'group-members',
);
default:
$default_settings = array(
'read' => 'anyone',
'edit' => 'loggedin',
'read_comments' => 'anyone',
'post_comments' => 'loggedin',
'view_history' => 'anyone',
'manage' => 'creator',
);
}


$doc_settings = wp_parse_args( $saved_settings, $default_settings );

Expand Down Expand Up @@ -521,7 +580,7 @@ function bp_docs_get_access_options( $settings_field, $doc_id = 0, $group_id = 0
),
90 => array(
'name' => 'creator',
'label' => __( 'The Doc author only', 'bp-docs' )
'label' => __( 'The doc author only', 'bp-docs' )
),
);

Expand Down

0 comments on commit 8454fbf

Please sign in to comment.