Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assume BP Docs is not enabled unless explicitly enabled. #461

Open
wants to merge 2 commits into
base: 1.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions includes/integration-groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,6 @@ function user_can( $user_can, $action, $user_id, $doc_id = false ) {
case 'associate_with_group' :
$group_settings = bp_docs_get_group_settings( $group_id );

// Provide a default value for legacy backpat
if ( empty( $group_settings['can-create'] ) ) {
$group_settings['can-create'] = 'member';
}

if ( !empty( $group_settings['can-create'] ) ) {
switch ( $group_settings['can-create'] ) {
case 'admin' :
Expand Down Expand Up @@ -536,14 +531,12 @@ public static function user_can_associate_doc_with_group( $user_id, $group_id )
return false;
}

// Check against group settings. Default to 'member'
// @todo Abstract default settings out better
// Check against group settings.
$group_settings = bp_docs_get_group_settings( $group_id );
$can_create = isset( $group_settings['can-create'] ) ? $group_settings['can-create'] : 'member';

if ( 'admin' == $can_create ) {
if ( 'admin' == $group_settings['can-create'] ) {
return (bool) groups_is_user_admin( $user_id, $group_id );
} else if ( 'mod' == $can_create ) {
} else if ( 'mod' == $group_settings['can-create'] ) {
return groups_is_user_admin( $user_id, $group_id ) || groups_is_user_mod( $user_id, $group_id );
}

Expand Down Expand Up @@ -1625,7 +1618,7 @@ function bp_docs_get_group_settings( $group_id ) {
}

$parsed_settings = wp_parse_args( $settings, array(
'group-enable' => 1,
'group-enable' => 0,
'can-create' => 'member',
) );

Expand Down
21 changes: 21 additions & 0 deletions tests/test-bp-docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,27 @@ function test_bp_docs_remove_group_related_doc_access_settings() {

$this->assertEqualSetsWithIndex( $expected_settings, $modified_settings );
}

/**
* @see issue #460
*/
public function test_bp_docs_is_docs_enabled_for_group_should_not_assume_enabled() {
$group = $this->factory->group->create();
$doc_id = $this->factory->doc->create( array( 'group' => $group ) );

$settings = array(
'group-enable' => 1,
'can-create' => 'member',
);
groups_update_groupmeta( $group, 'bp-docs', $settings );

$this->assertTrue( bp_docs_is_docs_enabled_for_group( $group ) );

// What happens when no group meta is saved for this group?
groups_delete_groupmeta( $group, 'bp-docs', $settings );

$this->assertFalse( bp_docs_is_docs_enabled_for_group( $group ) );
}
}