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

Bugfix/disable authentication #93

Merged
merged 7 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 16 additions & 0 deletions src/Provider/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@
* @since 0.3.0
*/
class Capabilities extends AbstractHookProvider {
protected $disable_authentication;

public function __construct( bool $disable_authentication = false ) {
$this->disable_authentication = $disable_authentication;
}

/**
* Register hooks.
*
* @since 0.3.0
*/
public function register_hooks() {
add_filter( 'map_meta_cap', [ $this, 'map_meta_cap' ], 10, 4 );
add_filter( 'user_has_cap', [ $this, 'user_has_cap' ], 10, 3 );
}

/**
Expand All @@ -51,4 +58,13 @@ public function map_meta_cap( array $caps, string $cap ): array {

return $caps;
}

public function user_has_cap( array $allcaps, array $caps, array $args ) {
if ( $this->disable_authentication ) {
$allcaps[Caps::DOWNLOAD_PACKAGES] = true;
$allcaps[Caps::VIEW_PACKAGES] = true;
}

return $allcaps;
}
}
13 changes: 11 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public function register( PimpleContainer $container ) {
);
};

$container['authentication.disable'] = function( $container ) {
$server_count = \iterator_count( $container['authentication.servers'] );
if ( 0 >= $server_count ) {
bradyvercher marked this conversation as resolved.
Show resolved Hide resolved
return true;
} else {
return false;
}
};

$container['authentication.unauthorized'] = function( $container ) {
return new Authentication\UnauthorizedServer(
$container['http.request']
Expand All @@ -102,8 +111,8 @@ public function register( PimpleContainer $container ) {
return new Provider\Authentication( $container['authentication.servers'] );
};

$container['hooks.capabilities'] = function() {
return new Provider\Capabilities();
$container['hooks.capabilities'] = function( $container ) {
return new Provider\Capabilities( $container['authentication.disable'] );
};

$container['hooks.custom_vendor'] = function() {
Expand Down