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

Support Multiple tokens #73

Merged
merged 76 commits into from
Jul 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
887e73a
Support Multiple tokens
dpanta94 Jul 16, 2024
38e4223
Validate that slug has a value before checking if there is a resource
dpanta94 Jul 16, 2024
f34ebbf
Updated Inteface's delete method
dpanta94 Jul 16, 2024
ba7d0a4
Fix type hint issues with php 7.4
dpanta94 Jul 16, 2024
ea75b63
Check for null prior to array
dpanta94 Jul 16, 2024
f4729e5
Fixing Tests
dpanta94 Jul 16, 2024
6da15d6
Fixing phpstan
dpanta94 Jul 16, 2024
a5fb1fe
Fixing phpstan
dpanta94 Jul 16, 2024
045c129
Fixing more tests
dpanta94 Jul 16, 2024
a93186d
First set of working tests.
redscar Jul 16, 2024
a5e8c38
Method names and switching to @before
redscar Jul 16, 2024
3a8e6e3
Removed the parent:setup().
redscar Jul 16, 2024
e9f8704
Merge pull request #74 from stellarwp/feat/support-multiple-tokens-tests
dpanta94 Jul 16, 2024
0edb446
Added an additional test for backwards compatability.
redscar Jul 17, 2024
8d52c8a
Added support for multisites.
redscar Jul 17, 2024
ac3d458
Merge pull request #75 from stellarwp/feat/support-multiple-tokens-ba…
redscar Jul 17, 2024
84fa56c
Code review changes
dpanta94 Jul 17, 2024
3b67cf6
Removing debug
dpanta94 Jul 17, 2024
01a8976
Updated tests per CR.
redscar Jul 17, 2024
30f1f06
Adding additional tests pertaining to deleting tokens.
redscar Jul 17, 2024
32dfc9b
Fixing storage offset
dpanta94 Jul 17, 2024
8548c52
Changes to get tests passing.
redscar Jul 17, 2024
651ca4a
Fixing phpstan and failing test
dpanta94 Jul 17, 2024
625aa10
Merge pull request #76 from stellarwp/feat/support-multiple-tokens-te…
dpanta94 Jul 17, 2024
dab2f04
Refactor token storage to take a resource and token connection logic
defunctl Jul 17, 2024
14095ff
Fix Authorize_Button_Controller
defunctl Jul 17, 2024
3f8e4d4
Update token auth to include plugin slug
defunctl Jul 18, 2024
ec5db56
update notice to allow some HTML
defunctl Jul 18, 2024
7f3a7d2
Add mock_activate_plugin method
defunctl Jul 18, 2024
fa34dda
Refactor auth to be local. Connect/disconnect to work with multiple p…
defunctl Jul 18, 2024
1df7bf7
add new functions
defunctl Jul 18, 2024
ca635bb
No need to register settings when doing an ajax request
defunctl Jul 18, 2024
cb54230
Add get_auth_url() function
defunctl Jul 18, 2024
a1db9df
Add get_license_domain function
defunctl Jul 18, 2024
834a1f6
Add get/set license key
defunctl Jul 18, 2024
4037f29
Update README.md
defunctl Jul 18, 2024
9032683
Revert back to not found testcase for different PHP versions
defunctl Jul 18, 2024
e84303c
Add docblock to token cache decorator
defunctl Jul 18, 2024
f7fcb75
Update permission error message
defunctl Jul 18, 2024
b78c23b
Fix method name
defunctl Jul 18, 2024
e7231de
Rename variable for clarity
defunctl Jul 18, 2024
f086189
Update action manager to use a slug instead of resource
defunctl Jul 18, 2024
83947ba
Add tests for getting a token from a resource.
defunctl Jul 18, 2024
c774714
Merge pull request #77 from stellarwp/feat/use-resource-for-token-man…
defunctl Jul 18, 2024
a6dd32f
Add missing use statements
defunctl Jul 18, 2024
cdcedfd
Generate disconnect URL from Disconnect_Controller
dpanta94 Jul 18, 2024
4e300aa
Add a filter to help moving from old system to uplink
dpanta94 Jul 18, 2024
12753bc
Fix token being retrived prior save/delete
dpanta94 Jul 18, 2024
5190441
Fix phpstan and tests
dpanta94 Jul 18, 2024
3d38782
Bumb prio of executing store/delete
dpanta94 Jul 18, 2024
2248466
Change Action Prio
dpanta94 Jul 18, 2024
6e8e276
Merge pull request #78 from stellarwp/fix/multiple-tokens-issues
dpanta94 Jul 18, 2024
cdbb66a
Implement storage system and remove all direct transient usage
defunctl Jul 18, 2024
b9ed6cc
Merge branch 'refs/heads/feat/support-multiple-tokens' into feat/mult…
defunctl Jul 18, 2024
5dca88b
Fix test not running in singlesite mode
defunctl Jul 18, 2024
cd04a0d
Allow the storage driver to be configured.
defunctl Jul 18, 2024
38668f9
remove duplicate braces
defunctl Jul 18, 2024
9f2ee7d
Fix phpstan
defunctl Jul 18, 2024
89b7c3c
Remove unneeded setUp method
defunctl Jul 18, 2024
e49088f
Set the default storage option out of the box
defunctl Jul 19, 2024
443d933
Check the configured storage driver before showing litespeed error me…
defunctl Jul 19, 2024
58bab89
Merge pull request #79 from stellarwp/feat/multiple-tokens/storage-st…
defunctl Jul 19, 2024
28eb2a5
Amend CR comments for field/form APIs
dpanta94 Jul 19, 2024
1fd1680
Migrated field/form from admin-views to views
dpanta94 Jul 19, 2024
24b96b8
Updates Field's API
dpanta94 Jul 19, 2024
57183c0
Add method to grab Field instance from resource
dpanta94 Jul 19, 2024
ca61f9d
Fix tests
dpanta94 Jul 19, 2024
a52184a
Remove unnecessary blank line
dpanta94 Jul 19, 2024
3906c2b
Update src/Uplink/Admin/Fields/Field.php
dpanta94 Jul 21, 2024
2555a9b
Update src/Uplink/Admin/Fields/Field.php
dpanta94 Jul 21, 2024
cd5d2c3
Update src/Uplink/Admin/Fields/Field.php
dpanta94 Jul 21, 2024
f64f551
Refactor from get_group_name to get_name
dpanta94 Jul 22, 2024
47207b0
Refactor function get_field
dpanta94 Jul 22, 2024
5b034ea
Fix tests
dpanta94 Jul 22, 2024
9a74d20
Refactor from Assets to Asset_Manager
dpanta94 Jul 22, 2024
a739018
Merge pull request #80 from stellarwp/fix/field-form-api-review
dpanta94 Jul 22, 2024
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
Prev Previous commit
Next Next commit
Code review changes
dpanta94 committed Jul 17, 2024
commit 84fa56cc2c2574392c791694119b293bd24b6e63
3 changes: 2 additions & 1 deletion src/Uplink/Auth/Provider.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
use StellarWP\Uplink\Config;
use StellarWP\Uplink\Contracts\Abstract_Provider;
use StellarWP\Uplink\Pipeline\Pipeline;
use StellarWP\Uplink\Resources\Collection;

final class Provider extends Abstract_Provider {

@@ -25,7 +26,7 @@ public function register() {
$this->container->bind(
Token_Manager::class,
static function ( $c ) {
return new Token\Token_Manager( $c->get( Config::TOKEN_OPTION_NAME ) );
return new Token\Token_Manager( $c->get( Config::TOKEN_OPTION_NAME ), $c->get( Collection::class ) );
}
);

9 changes: 9 additions & 0 deletions src/Uplink/Auth/Token/Contracts/Token_Manager.php
Original file line number Diff line number Diff line change
@@ -46,6 +46,15 @@ public function store( string $token, string $slug = '' ): bool;
*/
public function get( string $slug = '' ): ?string;

/**
* Retrieve all store tokens, indexed by their slug.
*
* @since TBD
*
* @return array<string, string>|array{}
*/
public function get_all(): ?array;

/**
* Deletes the token from the database.
*
48 changes: 27 additions & 21 deletions src/Uplink/Auth/Token/Token_Manager.php
Original file line number Diff line number Diff line change
@@ -23,17 +23,27 @@
*/
protected $option_name;

/**
* Resources collection
*
* @since TBD
*
* @var Collection
*/
protected $collection;

/**
* @param string $option_name The option name as set via Config::set_token_auth_prefix().
*/
public function __construct( string $option_name ) {
public function __construct( string $option_name, Collection $collection ) {
if ( ! $option_name ) {
throw new InvalidArgumentException(
__( 'You must set a token prefix with StellarWP\Uplink\Config::set_token_auth_prefix() before using the token manager.', '%TEXTDOMAIN%' )
);
}

$this->option_name = $option_name;
$this->collection = $collection;
}

/**
@@ -73,6 +83,8 @@
return false;
}

codecept_debug( $slug );

$slug = $this->validate_slug( $slug );

$current_value = $this->get( $slug );
@@ -82,15 +94,14 @@
return true;
}

$data = $this->get_all();
$values = $this->get_all();

if ( ! is_array( $data ) ) {
$data = [];
}
$values[ $slug ] = $token;

$data[ $slug ] = $token;
codecept_debug( $values );
codecept_debug( $slug );

return update_network_option( get_current_network_id(), $this->option_name, $data );
return update_network_option( get_current_network_id(), $this->option_name, $values );
}

/**
@@ -105,33 +116,28 @@
public function get( string $slug = '' ): ?string {
$slug = $this->validate_slug( $slug );

$value = get_network_option( get_current_network_id(), $this->option_name, null );
$values = $this->get_all();

if ( ! $value ) {
if ( ! $values ) {
return null;
}

if ( ! $slug ) {
return is_string( $value ) ? $value : ( array_values( $value )[0] ?? null );
}

if ( is_string( $value ) ) {
// Still using old structure, lets return whatever we found.
return $value;
return array_values( $values )[0] ?? null;

Check failure on line 126 in src/Uplink/Auth/Token/Token_Manager.php

GitHub Actions / phpstan

Offset 0 on non-empty-list<string> on left side of ?? always exists and is not nullable.
}

return $value[ $slug ] ?? null;
return $values[ $slug ] ?? null;
}

/**
* Get all the tokens.
*
* @since TBD
*
* @return null|string|array
* @return array<string, string>|array{}
*/
public function get_all() {
return get_network_option( get_current_network_id(), $this->option_name, [] );
public function get_all(): ?array {

Check failure on line 139 in src/Uplink/Auth/Token/Token_Manager.php

GitHub Actions / phpstan

Method StellarWP\Uplink\Auth\Token\Token_Manager::get_all() never returns null so it can be removed from the return type.
return (array) get_network_option( get_current_network_id(), $this->option_name, [] );
}

/**
@@ -142,7 +148,7 @@
public function delete( string $slug = '' ): bool {
$current_value = $this->get_all();
// Already doesn't exist, WordPress would normally return false.
if ( $current_value === null ) {
if ( ! $current_value ) {
return true;
}

@@ -171,6 +177,6 @@
* @return string
*/
protected function validate_slug( string $slug = '' ): string {
return $slug && Config::get_container()->get( Collection::class )->offsetExists( $slug ) ? $slug : '';
return $slug && $this->collection->offsetExists( $slug ) ? $slug : '';
}
}