diff --git a/assets/js/googlesitekit/datastore/site/connection.js b/assets/js/googlesitekit/datastore/site/connection.js index 95aa1503a6f..e8c9426a92f 100644 --- a/assets/js/googlesitekit/datastore/site/connection.js +++ b/assets/js/googlesitekit/datastore/site/connection.js @@ -84,20 +84,6 @@ const baseSelectors = { return connection; }, - /** - * Gets owner ID. - * - * @since 1.16.0 - * - * @param {Object} state Data store's state. - * @return {number|undefined} Owner ID if it exists, otherwise undefined. - */ - getOwnerID: createRegistrySelector( ( select ) => () => { - const { ownerID } = select( CORE_SITE ).getConnection() || {}; - - return ownerID; - } ), - /** * Gets information about connected admins. * diff --git a/assets/js/googlesitekit/datastore/site/connection.test.js b/assets/js/googlesitekit/datastore/site/connection.test.js index 120bc0772ad..d72ff82826e 100644 --- a/assets/js/googlesitekit/datastore/site/connection.test.js +++ b/assets/js/googlesitekit/datastore/site/connection.test.js @@ -34,7 +34,6 @@ describe( 'core/site connection', () => { resettable: true, setupCompleted: true, hasConnectedAdmins: true, - ownerID: 123, }; let registry; @@ -168,7 +167,6 @@ describe( 'core/site connection', () => { } ); describe.each( [ - [ 'getOwnerID', 'ownerID' ], [ 'hasConnectedAdmins', 'hasConnectedAdmins' ], [ 'isConnected', 'connected' ], [ 'isResettable', 'resettable' ], diff --git a/docs/context/php/asset-management.md b/docs/context/php/asset-management.md index e3bc7eb9f45..3fdd7fef83d 100644 --- a/docs/context/php/asset-management.md +++ b/docs/context/php/asset-management.md @@ -514,7 +514,6 @@ private function get_inline_base_data() { 'postTypes' => $this->get_post_types(), 'storagePrefix' => $this->get_storage_prefix(), 'userRoles' => $this->get_user_roles(), - 'isOwner' => current_user_can( Permissions::MANAGE_OPTIONS ), 'splashURL' => $this->context->admin_url( 'splash' ), ); } diff --git a/includes/Core/Authentication/Authentication.php b/includes/Core/Authentication/Authentication.php index 87b4cc5d44c..7d7acf0c622 100644 --- a/includes/Core/Authentication/Authentication.php +++ b/includes/Core/Authentication/Authentication.php @@ -155,14 +155,6 @@ final class Authentication implements Provides_Feature_Metrics { */ protected $token; - /** - * Owner_ID instance. - * - * @since 1.16.0 - * @var Owner_ID - */ - protected $owner_id; - /** * Has_Connected_Admins instance. * @@ -257,7 +249,6 @@ public function __construct( $this->verification_file = new Verification_File( $this->user_options ); $this->profile = new Profile( $this->user_options ); $this->token = new Token( $this->user_options ); - $this->owner_id = new Owner_ID( $this->options ); $this->has_connected_admins = new Has_Connected_Admins( $this->options, $this->user_options ); $this->has_multiple_admins = new Has_Multiple_Admins( $this->transients ); $this->connected_proxy_url = new Connected_Proxy_URL( $this->options ); @@ -278,7 +269,6 @@ public function register() { $this->verification_meta()->register(); $this->has_connected_admins->register(); $this->has_multiple_admins->register(); - $this->owner_id->register(); $this->connected_proxy_url->register(); $this->disconnected_reason->register(); $this->initial_version->register(); @@ -840,7 +830,6 @@ private function get_update_core_url() { * @return array Filtered $data. */ private function inline_js_base_data( $data ) { - $data['isOwner'] = $this->owner_id->get() === get_current_user_id(); $data['splashURL'] = esc_url_raw( $this->context->admin_url( 'splash' ) ); $data['proxySetupURL'] = ''; $data['proxyPermissionsURL'] = ''; @@ -1388,17 +1377,6 @@ public function get_has_multiple_admins_instance() { return $this->has_multiple_admins; } - /** - * Helper method to return owner_id property. - * - * @since 1.131.0 - * - * @return Owner_ID - */ - public function get_owner_id_instance() { - return $this->owner_id; - } - /** * Helper method to return disconnected_reason property. * diff --git a/includes/Core/Authentication/Clients/OAuth_Client.php b/includes/Core/Authentication/Clients/OAuth_Client.php index 5a064d75815..5494d2dbfda 100644 --- a/includes/Core/Authentication/Clients/OAuth_Client.php +++ b/includes/Core/Authentication/Clients/OAuth_Client.php @@ -15,7 +15,6 @@ use Google\Site_Kit\Core\Authentication\Credentials; use Google\Site_Kit\Core\Authentication\Exception\Google_Proxy_Code_Exception; use Google\Site_Kit\Core\Authentication\Google_Proxy; -use Google\Site_Kit\Core\Authentication\Owner_ID; use Google\Site_Kit\Core\Authentication\Profile; use Google\Site_Kit\Core\Authentication\Token; use Google\Site_Kit\Core\Dismissals\Dismissed_Items; @@ -43,14 +42,6 @@ final class OAuth_Client extends OAuth_Client_Base { const OPTION_ERROR_REDIRECT_URL = 'googlesitekit_error_redirect_url'; const CRON_REFRESH_PROFILE_DATA = 'googlesitekit_cron_refresh_profile_data'; - /** - * Owner_ID instance. - * - * @since 1.16.0 - * @var Owner_ID - */ - private $owner_id; - /** * Transients instance. * @@ -101,7 +92,6 @@ public function __construct( $token ); - $this->owner_id = new Owner_ID( $this->options ); $this->transients = $transients ?: new Transients( $this->context ); $this->dismissed_items = new Dismissed_Items( $this->user_options ); } @@ -510,13 +500,6 @@ function ( $scope ) { */ do_action( 'googlesitekit_authorize_user', $token_response, $scopes, $previous_scopes ); - // This must happen after googlesitekit_authorize_user as the permissions checks depend on - // values set which affect the meta capability mapping. - $current_user_id = get_current_user_id(); - if ( $this->should_update_owner_id( $current_user_id ) ) { - $this->owner_id->set( $current_user_id ); - } - $redirect_url = $this->get_authorize_user_redirect_url(); // Store the redirect URL in transients using the authorization code hash as the key. @@ -578,31 +561,6 @@ public function refresh_profile_data( $retry_after = 0 ) { } } - /** - * Determines whether the current owner ID must be changed or not. - * - * @since 1.16.0 - * - * @param int $user_id Current user ID. - * @return bool TRUE if owner needs to be changed, otherwise FALSE. - */ - private function should_update_owner_id( $user_id ) { - $current_owner_id = $this->owner_id->get(); - if ( $current_owner_id === $user_id ) { - return false; - } - - if ( ! empty( $current_owner_id ) && user_can( $current_owner_id, Permissions::MANAGE_OPTIONS ) ) { - return false; - } - - if ( ! user_can( $user_id, Permissions::MANAGE_OPTIONS ) ) { - return false; - } - - return true; - } - /** * Returns the permissions URL to the authentication proxy. * diff --git a/includes/Core/Authentication/Owner_ID.php b/includes/Core/Authentication/Owner_ID.php deleted file mode 100644 index fe22701ada9..00000000000 --- a/includes/Core/Authentication/Owner_ID.php +++ /dev/null @@ -1,75 +0,0 @@ -options->get( 'googlesitekit_first_admin' ); - } - - /** - * Gets the callback for sanitizing the setting's value before saving. - * - * @since 1.16.0 - * - * @return callable The callable sanitize callback. - */ - protected function get_sanitize_callback() { - return 'intval'; - } -} diff --git a/includes/Core/Authentication/REST_Authentication_Controller.php b/includes/Core/Authentication/REST_Authentication_Controller.php index e415d3be6b9..3363757198e 100644 --- a/includes/Core/Authentication/REST_Authentication_Controller.php +++ b/includes/Core/Authentication/REST_Authentication_Controller.php @@ -108,7 +108,6 @@ private function get_rest_routes() { 'setupCompleted' => $this->authentication->is_setup_completed(), 'hasConnectedAdmins' => $this->authentication->get_has_connected_admins_instance()->get(), 'hasMultipleAdmins' => $this->authentication->get_has_multiple_admins_instance()->get(), - 'ownerID' => $this->authentication->get_owner_id_instance()->get(), ); return new WP_REST_Response( $data ); diff --git a/storybook/utils/resetGlobals.js b/storybook/utils/resetGlobals.js index d1e20bb5821..e7285c7f41a 100644 --- a/storybook/utils/resetGlobals.js +++ b/storybook/utils/resetGlobals.js @@ -38,7 +38,6 @@ export function resetGlobals() { ampMode: false, isNetworkMode: false, activeModules: [], - isOwner: true, splashURL: 'http://example.com/wp-admin/admin.php?page=googlesitekit-splash', proxySetupURL: diff --git a/tests/phpunit/integration/Core/Authentication/Clients/OAuth_ClientTest.php b/tests/phpunit/integration/Core/Authentication/Clients/OAuth_ClientTest.php index 92cfce17158..82988a5ec0b 100644 --- a/tests/phpunit/integration/Core/Authentication/Clients/OAuth_ClientTest.php +++ b/tests/phpunit/integration/Core/Authentication/Clients/OAuth_ClientTest.php @@ -14,12 +14,9 @@ use Google\Site_Kit\Context; use Google\Site_Kit\Core\Authentication\Clients\OAuth_Client; -use Google\Site_Kit\Core\Authentication\Owner_ID; use Google\Site_Kit\Core\Authentication\Profile; use Google\Site_Kit\Core\Dismissals\Dismissed_Items; use Google\Site_Kit\Tests\Exception\RedirectException; -use Google\Site_Kit\Core\Permissions\Permissions; -use Google\Site_Kit\Core\Storage\Options; use Google\Site_Kit\Core\Storage\Transients; use Google\Site_Kit\Core\Storage\User_Options; use Google\Site_Kit\Tests\Fake_Site_Connection_Trait; @@ -663,51 +660,6 @@ function ( Request $request ) { } } - public function test_should_update_owner_id() { - $admin_id = $this->factory()->user->create( array( 'role' => 'administrator' ) ); - $owner_id = $this->factory()->user->create( array( 'role' => 'administrator' ) ); - wp_set_current_user( $admin_id ); - - $context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ); - $options = new Options( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) ); - $client = new OAuth_Client( $context, $options ); - - $class = new \ReflectionClass( OAuth_Client::class ); - $method = $class->getMethod( 'should_update_owner_id' ); - $method->setAccessible( true ); - - $should_update_owner_id = function ( ...$args ) use ( $method, $client ) { - return $method->invoke( $client, $args ); - }; - - $map_meta_cap = function ( $user_id ) { - return function ( $caps, $cap, $uid ) use ( $user_id ) { - if ( Permissions::MANAGE_OPTIONS === $cap && $uid === $user_id ) { - return array( 'manage_options' ); - } - return $caps; - }; - }; - - // Should return FALSE when user is already an owner. - $options->set( Owner_ID::OPTION, $owner_id ); - $this->assertFalse( $should_update_owner_id( $owner_id ) ); - - // Should return FALSE when the current owner is set and has MANAGE_OPTIONS permissions. - $map_owner_id_meta_cap = $map_meta_cap( $owner_id ); - add_filter( 'map_meta_cap', $map_owner_id_meta_cap, 99, 3 ); - $this->assertFalse( $should_update_owner_id( $admin_id ) ); - remove_filter( 'map_meta_cap', $map_owner_id_meta_cap, 99, 3 ); - - // Should return FALSE when passed user has no MANAGE_OPTIONS permssions. - $this->assertFalse( $should_update_owner_id( $admin_id ) ); - - // Should return TRUE when the current owner has appropriate permissions and not equals to provided user who has appropriate permissions too. - $map_admin_id_meta_cap = $map_meta_cap( $admin_id ); - add_filter( 'map_meta_cap', $map_admin_id_meta_cap, 99, 3 ); - $this->assertFalse( $should_update_owner_id( $admin_id ) ); - } - public function test_refresh_profile_data() { $context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ); $user_id_a = $this->factory()->user->create(); diff --git a/tests/phpunit/integration/Core/Authentication/Owner_IDTest.php b/tests/phpunit/integration/Core/Authentication/Owner_IDTest.php deleted file mode 100644 index 64ba431d4a8..00000000000 --- a/tests/phpunit/integration/Core/Authentication/Owner_IDTest.php +++ /dev/null @@ -1,97 +0,0 @@ -options = new Options( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) ); - $this->owner_id = new Owner_ID( $this->options ); - $this->owner_id->register(); - } - - public function test_get() { - $this->assertEquals( 0, $this->owner_id->get(), 'Owner ID should be 0 by default.' ); - $this->assertIsInt( $this->owner_id->get(), 'Owner ID should be an integer.' ); - - $this->options->set( Owner_ID::OPTION, 1 ); - $this->assertIsInt( $this->owner_id->get(), 'Owner ID should be an integer when set to 1.' ); - $this->assertEquals( 1, $this->owner_id->get(), 'Owner ID should return the set value of 1.' ); - - $this->options->set( Owner_ID::OPTION, 'xxx' ); - $this->assertIsInt( $this->owner_id->get(), 'Owner ID should be an integer even when set to invalid value.' ); - $this->assertEquals( 0, $this->owner_id->get(), 'Owner ID should return 0 for invalid values.' ); - - // When setting with a string, WP sanitizes it before caching. - // However, the value will be stored in the DB as a string and so loading - // from the DB with a cold cache will result in a string return value. - $this->options->set( Owner_ID::OPTION, '3' ); - wp_cache_flush(); // The option value is cached on set, so we have to flush after. - $this->assertIsInt( $this->owner_id->get(), 'Owner ID should be an integer when set to string "3".' ); - $this->assertEquals( 3, $this->owner_id->get(), 'Owner ID should return 3 when set to string "3".' ); - } - - public function test_set() { - $this->assertTrue( $this->owner_id->set( 1 ), 'Setting owner ID to 1 should return true.' ); - $this->assertSame( 1, $this->options->get( Owner_ID::OPTION ), 'Options should contain the set owner ID value.' ); - - // Setting with a string value is sanitized as an integer. - $this->assertTrue( $this->owner_id->set( '2' ), 'Setting owner ID to string "2" should return true.' ); - $this->assertSame( 2, $this->options->get( Owner_ID::OPTION ), 'Options should contain the sanitized integer value.' ); - - // An invalid value will result in a 0 as a result of sanitization. - $this->assertTrue( $this->owner_id->set( 'xxx' ), 'Setting owner ID to invalid value should return true.' ); - $this->assertSame( 0, $this->options->get( Owner_ID::OPTION ), 'Options should contain 0 for invalid values.' ); - } - - public function test_has() { - $this->assertFalse( $this->owner_id->has(), 'Owner ID should not exist initially.' ); - - $this->owner_id->set( 1 ); - $this->assertTrue( $this->owner_id->has(), 'Owner ID should exist after being set to 1.' ); - - $this->owner_id->set( 'xxx' ); - $this->assertTrue( $this->owner_id->has(), 'Owner ID should exist even when set to invalid value.' ); - } - - /** - * @inheritDoc - */ - protected function get_option_name() { - return Owner_ID::OPTION; - } -}