diff --git a/projects/js-packages/api/index.jsx b/projects/js-packages/api/index.jsx
index 6f6cdffe0b325..8233d0ba8a616 100644
--- a/projects/js-packages/api/index.jsx
+++ b/projects/js-packages/api/index.jsx
@@ -510,16 +510,6 @@ function JetpackRestApiClient( root, nonce ) {
getRequest( `${ wpcomOriginApiUrl }jetpack/v4/search/stats`, getParams )
.then( checkStatus )
.then( parseJsonResponse ),
- fetchAccountProtectionSettings: () =>
- getRequest( `${ apiRoot }jetpack/v4/account-protection`, getParams )
- .then( checkStatus )
- .then( parseJsonResponse ),
- updateAccountProtectionSettings: newSettings =>
- postRequest( `${ apiRoot }jetpack/v4/account-protection`, postParams, {
- body: JSON.stringify( newSettings ),
- } )
- .then( checkStatus )
- .then( parseJsonResponse ),
fetchWafSettings: () =>
getRequest( `${ apiRoot }jetpack/v4/waf`, getParams )
.then( checkStatus )
diff --git a/projects/packages/account-protection/src/class-account-protection.php b/projects/packages/account-protection/src/class-account-protection.php
index a63d54545889f..2db8aaf73582d 100644
--- a/projects/packages/account-protection/src/class-account-protection.php
+++ b/projects/packages/account-protection/src/class-account-protection.php
@@ -15,7 +15,6 @@
class Account_Protection {
const PACKAGE_VERSION = '0.1.0-alpha';
const ACCOUNT_PROTECTION_MODULE_NAME = 'account-protection';
- const STRICT_MODE_OPTION_NAME = 'jetpack_account_protection_strict_mode';
/**
* Modules instance.
@@ -64,9 +63,6 @@ private function register_hooks(): void {
// Do not run in unsupported environments
add_action( 'jetpack_get_available_modules', array( $this, 'remove_module_on_unsupported_environments' ) );
add_action( 'jetpack_get_available_standalone_modules', array( $this, 'remove_standalone_module_on_unsupported_environments' ) );
-
- // Register REST routes
- add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) );
}
/**
@@ -189,17 +185,4 @@ function ( $module ) {
return $modules;
}
-
- /**
- * Get the account protection settings.
- *
- * @return array
- */
- public function get_settings(): array {
- $settings = array(
- self::STRICT_MODE_OPTION_NAME => get_option( self::STRICT_MODE_OPTION_NAME, false ),
- );
-
- return $settings;
- }
}
diff --git a/projects/packages/account-protection/src/class-rest-controller.php b/projects/packages/account-protection/src/class-rest-controller.php
deleted file mode 100644
index a49c1b1fe7c65..0000000000000
--- a/projects/packages/account-protection/src/class-rest-controller.php
+++ /dev/null
@@ -1,104 +0,0 @@
-routes_registered ) {
- return;
- }
-
- register_rest_route(
- 'jetpack/v4',
- '/account-protection',
- array(
- 'methods' => WP_REST_Server::READABLE,
- 'callback' => array( $this, 'get_settings' ),
- 'permission_callback' => array( $this, 'permissions_callback' ),
- )
- );
-
- register_rest_route(
- 'jetpack/v4',
- '/account-protection',
- array(
- 'methods' => WP_REST_Server::EDITABLE,
- 'callback' => array( $this, 'update_settings' ),
- 'permission_callback' => array( $this, 'permissions_callback' ),
- )
- );
-
- $this->routes_registered = true;
- }
-
- /**
- * Account Protection Settings Endpoint
- *
- * @return WP_REST_Response
- */
- public function get_settings() {
- $settings = ( new Account_Protection() )->get_settings();
-
- return rest_ensure_response( $settings );
- }
-
- /**
- * Update Account Protection Settings Endpoint
- *
- * @param WP_REST_Request $request The API request.
- *
- * @return WP_REST_Response|WP_Error
- */
- public function update_settings( $request ) {
- // Strict Mode
- if ( isset( $request[ Account_Protection::STRICT_MODE_OPTION_NAME ] ) ) {
- update_option( Account_Protection::STRICT_MODE_OPTION_NAME, $request[ Account_Protection::STRICT_MODE_OPTION_NAME ] ? '1' : '' );
- }
-
- return $this->get_settings();
- }
-
- /**
- * Account Protection Endpoint Permissions Callback
- *
- * @return bool|WP_Error True if user can view the Jetpack admin page.
- */
- public function permissions_callback() {
- if ( current_user_can( 'manage_options' ) ) {
- return true;
- }
-
- return new WP_Error(
- 'invalid_user_permission_manage_options',
- REST_Connector::get_user_permissions_error_msg(),
- array( 'status' => rest_authorization_required_code() )
- );
- }
-}
diff --git a/projects/plugins/jetpack/_inc/client/security/account-protection.jsx b/projects/plugins/jetpack/_inc/client/security/account-protection.jsx
index 7334eb9e3ca7d..4f8f51b250f10 100644
--- a/projects/plugins/jetpack/_inc/client/security/account-protection.jsx
+++ b/projects/plugins/jetpack/_inc/client/security/account-protection.jsx
@@ -1,98 +1,14 @@
-import { ToggleControl } from '@automattic/jetpack-components';
-import { ExternalLink } from '@wordpress/components';
-import { createInterpolateElement } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';
import React, { Component } from 'react';
-import { connect } from 'react-redux';
-import { FormFieldset } from 'components/forms';
-import { createNotice, removeNotice } from 'components/global-notices/state/notices/actions';
import { withModuleSettingsFormHelpers } from 'components/module-settings/with-module-settings-form-helpers';
import { ModuleToggle } from 'components/module-toggle';
import SettingsCard from 'components/settings-card';
import SettingsGroup from 'components/settings-group';
-import QueryAccountProtectionSettings from '../components/data/query-account-protection-settings';
-import InfoPopover from '../components/info-popover';
-import { FEATURE_JETPACK_ACCOUNT_PROTECTION } from '../lib/plans/constants';
-import { updateAccountProtectionSettings } from '../state/account-protection/actions';
-import {
- getAccountProtectionSettings,
- isFetchingAccountProtectionSettings,
- isUpdatingAccountProtectionSettings,
-} from '../state/account-protection/reducer';
-
-const AccountProtection = class extends Component {
- /**
- * Get options for initial state.
- *
- * @return {object}
- */
- state = {
- strictMode: this.props.settings?.strictMode,
- };
-
- /**
- * Keep the form values in sync with updates to the settings prop.
- *
- * @param {object} prevProps - Next render props.
- */
- componentDidUpdate = prevProps => {
- // Sync the form values with the settings prop.
- if ( this.props.settings !== prevProps.settings ) {
- this.setState( {
- ...this.state,
- strictMode: this.props.settings?.strictMode,
- } );
- }
- };
-
- /**
- * Handle settings updates.
- *
- * @return {void}
- */
- onSubmit = () => {
- this.props.removeNotice( 'module-setting-update' );
- this.props.removeNotice( 'module-setting-update-success' );
-
- this.props.createNotice( 'is-info', __( 'Updating settingsā¦', 'jetpack' ), {
- id: 'module-setting-update',
- } );
- this.props
- .updateAccountProtectionSettings( this.state )
- .then( () => {
- this.props.removeNotice( 'module-setting-update' );
- this.props.createNotice( 'is-success', __( 'Updated Settings.', 'jetpack' ), {
- id: 'module-setting-update-success',
- } );
- } )
- .catch( () => {
- this.props.removeNotice( 'module-setting-update' );
- this.props.createNotice( 'is-error', __( 'Error updating settings.', 'jetpack' ), {
- id: 'module-setting-update',
- } );
- } );
- };
-
- /**
- * Toggle strict mode.
- */
- toggleStrictMode = () => {
- const state = {
- ...this.state,
- strictMode: ! this.state.strictMode,
- };
-
- this.setState( state, this.onSubmit );
- };
+const AccountProtectionComponent = class extends Component {
render() {
const isAccountProtectionActive = this.props.getOptionValue( 'account-protection' ),
unavailableInOfflineMode = this.props.isUnavailableInOfflineMode( 'account-protection' );
- const baseInputDisabledCase =
- ! isAccountProtectionActive ||
- unavailableInOfflineMode ||
- this.props.isFetchingAccountProtectionSettings ||
- this.props.isSavingAnyOption( [ 'account-protection' ] );
return (
- { isAccountProtectionActive && }
- { isAccountProtectionActive && (
-
-
-
-
- { __( 'Require strong passwords', 'jetpack' ) }
-
-
- { createInterpolateElement(
- __(
- 'Allow Jetpack to enforce strict password rules. Learn more
Privacy Information',
- 'jetpack'
- ),
- {
- ExternalLink: , // TODO: Update this redirect URL
- hr:
,
- }
- ) }
-
-
- }
- />
-
-
- ) }
);
}
};
-export default connect(
- state => {
- return {
- isFetchingSettings: isFetchingAccountProtectionSettings( state ),
- isUpdatingAccountProtectionSettings: isUpdatingAccountProtectionSettings( state ),
- settings: getAccountProtectionSettings( state ),
- };
- },
- dispatch => {
- return {
- updateAccountProtectionSettings: newSettings =>
- dispatch( updateAccountProtectionSettings( newSettings ) ),
- createNotice: ( type, message, props ) => dispatch( createNotice( type, message, props ) ),
- removeNotice: notice => dispatch( removeNotice( notice ) ),
- };
- }
-)( withModuleSettingsFormHelpers( AccountProtection ) );
+export const AccountProtection = withModuleSettingsFormHelpers( AccountProtectionComponent );
diff --git a/projects/plugins/jetpack/_inc/client/security/index.jsx b/projects/plugins/jetpack/_inc/client/security/index.jsx
index d4677461de9ea..ff1ec0efad4f2 100644
--- a/projects/plugins/jetpack/_inc/client/security/index.jsx
+++ b/projects/plugins/jetpack/_inc/client/security/index.jsx
@@ -12,7 +12,7 @@ import { isModuleFound } from 'state/search';
import { getSettings } from 'state/settings';
import { siteHasFeature } from 'state/site';
import { isPluginActive, isPluginInstalled } from 'state/site/plugins';
-import AccountProtection from './account-protection';
+import { AccountProtection } from './account-protection';
import AllowList from './allowList';
import Antispam from './antispam';
import BackupsScan from './backups-scan';
diff --git a/projects/plugins/jetpack/_inc/client/security/style.scss b/projects/plugins/jetpack/_inc/client/security/style.scss
index 385e7feaa710f..60855aa333edb 100644
--- a/projects/plugins/jetpack/_inc/client/security/style.scss
+++ b/projects/plugins/jetpack/_inc/client/security/style.scss
@@ -192,23 +192,3 @@
.jp-form-settings-group p {
margin-bottom: 0.5rem;
}
-
-.account-protection__settings {
- &__toggle-setting {
- flex-wrap: wrap;
- display: flex;
- margin-bottom: 24px;
-
- &__label {
- display: flex;
- align-items: center;
- }
- }
-
- &__strict-mode-popover {
- display: flex;
- align-items: center;
- margin-left: 4px;
- }
-
-}
\ No newline at end of file
diff --git a/projects/plugins/jetpack/_inc/client/state/account-protection/actions.js b/projects/plugins/jetpack/_inc/client/state/account-protection/actions.js
deleted file mode 100644
index feee531d78a38..0000000000000
--- a/projects/plugins/jetpack/_inc/client/state/account-protection/actions.js
+++ /dev/null
@@ -1,66 +0,0 @@
-import restApi from '@automattic/jetpack-api';
-import {
- ACCOUNT_PROTECTION_SETTINGS_FETCH,
- ACCOUNT_PROTECTION_SETTINGS_FETCH_RECEIVE,
- ACCOUNT_PROTECTION_SETTINGS_FETCH_FAIL,
- ACCOUNT_PROTECTION_SETTINGS_UPDATE,
- ACCOUNT_PROTECTION_SETTINGS_UPDATE_SUCCESS,
- ACCOUNT_PROTECTION_SETTINGS_UPDATE_FAIL,
-} from 'state/action-types';
-
-export const fetchAccountProtectionSettings = () => {
- return dispatch => {
- dispatch( {
- type: ACCOUNT_PROTECTION_SETTINGS_FETCH,
- } );
- return restApi
- .fetchAccountProtectionSettings()
- .then( settings => {
- dispatch( {
- type: ACCOUNT_PROTECTION_SETTINGS_FETCH_RECEIVE,
- settings,
- } );
- return settings;
- } )
- .catch( error => {
- dispatch( {
- type: ACCOUNT_PROTECTION_SETTINGS_FETCH_FAIL,
- error: error,
- } );
- } );
- };
-};
-
-/**
- * Update Account Protection Settings
- *
- * @param {object} newSettings - The new settings to be saved.
- * @param {boolean} newSettings.strictMode - Whether strict mode is enabled.
- * @return {Function} - The action.
- */
-export const updateAccountProtectionSettings = newSettings => {
- return dispatch => {
- dispatch( {
- type: ACCOUNT_PROTECTION_SETTINGS_UPDATE,
- } );
- return restApi
- .updateAccountProtectionSettings( {
- jetpack_account_protection_strict_mode: newSettings.strictMode,
- } )
- .then( settings => {
- dispatch( {
- type: ACCOUNT_PROTECTION_SETTINGS_UPDATE_SUCCESS,
- settings,
- } );
- return settings;
- } )
- .catch( error => {
- dispatch( {
- type: ACCOUNT_PROTECTION_SETTINGS_UPDATE_FAIL,
- error: error,
- } );
-
- throw error;
- } );
- };
-};
diff --git a/projects/plugins/jetpack/_inc/client/state/account-protection/index.js b/projects/plugins/jetpack/_inc/client/state/account-protection/index.js
deleted file mode 100644
index 5e3164b4c9f72..0000000000000
--- a/projects/plugins/jetpack/_inc/client/state/account-protection/index.js
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from './reducer';
-export * from './actions';
diff --git a/projects/plugins/jetpack/_inc/client/state/account-protection/reducer.js b/projects/plugins/jetpack/_inc/client/state/account-protection/reducer.js
deleted file mode 100644
index cb42d7bccc486..0000000000000
--- a/projects/plugins/jetpack/_inc/client/state/account-protection/reducer.js
+++ /dev/null
@@ -1,87 +0,0 @@
-import { assign, get } from 'lodash';
-import { combineReducers } from 'redux';
-import {
- ACCOUNT_PROTECTION_SETTINGS_FETCH,
- ACCOUNT_PROTECTION_SETTINGS_FETCH_RECEIVE,
- ACCOUNT_PROTECTION_SETTINGS_FETCH_FAIL,
- ACCOUNT_PROTECTION_SETTINGS_UPDATE,
- ACCOUNT_PROTECTION_SETTINGS_UPDATE_SUCCESS,
- ACCOUNT_PROTECTION_SETTINGS_UPDATE_FAIL,
-} from 'state/action-types';
-
-export const data = ( state = {}, action ) => {
- switch ( action.type ) {
- case ACCOUNT_PROTECTION_SETTINGS_FETCH_RECEIVE:
- case ACCOUNT_PROTECTION_SETTINGS_UPDATE_SUCCESS:
- return assign( {}, state, {
- strictMode: Boolean( action.settings?.jetpack_account_protection_strict_mode ),
- } );
- default:
- return state;
- }
-};
-
-export const initialRequestsState = {
- isFetchingAccountProtectionSettings: false,
- isUpdatingAccountProtectionSettings: false,
-};
-
-export const requests = ( state = initialRequestsState, action ) => {
- switch ( action.type ) {
- case ACCOUNT_PROTECTION_SETTINGS_FETCH:
- return assign( {}, state, {
- isFetchingAccountProtectionSettings: true,
- } );
- case ACCOUNT_PROTECTION_SETTINGS_FETCH_RECEIVE:
- case ACCOUNT_PROTECTION_SETTINGS_FETCH_FAIL:
- return assign( {}, state, {
- isFetchingAccountProtectionSettings: false,
- } );
- case ACCOUNT_PROTECTION_SETTINGS_UPDATE:
- return assign( {}, state, {
- isUpdatingAccountProtectionSettings: true,
- } );
- case ACCOUNT_PROTECTION_SETTINGS_UPDATE_SUCCESS:
- case ACCOUNT_PROTECTION_SETTINGS_UPDATE_FAIL:
- return assign( {}, state, {
- isUpdatingAccountProtectionSettings: false,
- } );
- default:
- return state;
- }
-};
-
-export const reducer = combineReducers( {
- data,
- requests,
-} );
-
-/**
- * Returns true if currently requesting the account protection settings. Otherwise false.
- *
- * @param {object} state - Global state tree
- * @return {boolean} Whether the account protection settings are being requested
- */
-export function isFetchingAccountProtectionSettings( state ) {
- return !! state.jetpack.accountProtection.requests.isFetchingAccountProtectionSettings;
-}
-
-/**
- * Returns true if currently updating the account protection settings. Otherwise false.
- *
- * @param {object} state - Global state tree
- * @return {boolean} Whether the account protection settings are being requested
- */
-export function isUpdatingAccountProtectionSettings( state ) {
- return !! state.jetpack.accountProtection.requests.isUpdatingAccountProtectionSettings;
-}
-
-/**
- * Returns the account protection's settings.
- *
- * @param {object} state - Global state tree
- * @return {string} File path to bootstrap.php
- */
-export function getAccountProtectionSettings( state ) {
- return get( state.jetpack.accountProtection, [ 'data' ], {} );
-}
diff --git a/projects/plugins/jetpack/_inc/client/state/action-types.js b/projects/plugins/jetpack/_inc/client/state/action-types.js
index 7da1fbb07cf1d..c4785d4a2ced5 100644
--- a/projects/plugins/jetpack/_inc/client/state/action-types.js
+++ b/projects/plugins/jetpack/_inc/client/state/action-types.js
@@ -245,15 +245,6 @@ export const JETPACK_LICENSING_GET_USER_LICENSES_FAILURE =
export const JETPACK_CONNECTION_HAS_SEEN_WC_CONNECTION_MODAL =
'JETPACK_CONNECTION_HAS_SEEN_WC_CONNECTION_MODAL';
-export const ACCOUNT_PROTECTION_SETTINGS_FETCH = 'ACCOUNT_PROTECTION_SETTINGS_FETCH';
-export const ACCOUNT_PROTECTION_SETTINGS_FETCH_RECEIVE =
- 'ACCOUNT_PROTECTION_SETTINGS_FETCH_RECEIVE';
-export const ACCOUNT_PROTECTION_SETTINGS_FETCH_FAIL = 'ACCOUNT_PROTECTION_SETTINGS_FETCH_FAIL';
-export const ACCOUNT_PROTECTION_SETTINGS_UPDATE = 'ACCOUNT_PROTECTION_SETTINGS_UPDATE';
-export const ACCOUNT_PROTECTION_SETTINGS_UPDATE_SUCCESS =
- 'ACCOUNT_PROTECTION_SETTINGS_UPDATE_SUCCESS';
-export const ACCOUNT_PROTECTION_SETTINGS_UPDATE_FAIL = 'ACCOUNT_PROTECTION_SETTINGS_UPDATE_FAIL';
-
export const WAF_SETTINGS_FETCH = 'WAF_SETTINGS_FETCH';
export const WAF_SETTINGS_FETCH_RECEIVE = 'WAF_SETTINGS_FETCH_RECEIVE';
export const WAF_SETTINGS_FETCH_FAIL = 'WAF_SETTINGS_FETCH_FAIL';
diff --git a/projects/plugins/jetpack/_inc/client/state/reducer.js b/projects/plugins/jetpack/_inc/client/state/reducer.js
index 14e85f0fb5289..5ff156b807a49 100644
--- a/projects/plugins/jetpack/_inc/client/state/reducer.js
+++ b/projects/plugins/jetpack/_inc/client/state/reducer.js
@@ -1,6 +1,5 @@
import { combineReducers } from 'redux';
import { globalNotices } from 'components/global-notices/state/notices/reducer';
-import { reducer as accountProtection } from 'state/account-protection/reducer';
import { dashboard } from 'state/at-a-glance/reducer';
import { reducer as connection } from 'state/connection/reducer';
import { reducer as devCard } from 'state/dev-version/reducer';
@@ -47,7 +46,6 @@ const jetpackReducer = combineReducers( {
disconnectSurvey,
trackingSettings,
licensing,
- accountProtection,
waf,
introOffers,
} );
diff --git a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php
index 06cf25d1268f7..86c23729166e2 100644
--- a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php
+++ b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php
@@ -2358,14 +2358,6 @@ public static function get_updateable_data_list( $selector = '' ) {
'validate_callback' => __CLASS__ . '::validate_posint',
'jp_group' => 'custom-content-types',
),
- // Account Protection.
- 'jetpack_account_protection_strict_mode' => array(
- 'description' => esc_html__( 'Strict mode - Require strong passwords.', 'jetpack' ),
- 'type' => 'boolean',
- 'default' => 0,
- 'validate_callback' => __CLASS__ . '::validate_boolean',
- 'jp_group' => 'account-protection',
- ),
// WAF.
'jetpack_waf_automatic_rules' => array(
'description' => esc_html__( 'Enable automatic rules - Protect your site against untrusted traffic sources with automatic security rules.', 'jetpack' ),
diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php
index 4b931dadb330f..9852478a7c53d 100644
--- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php
+++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php
@@ -127,7 +127,6 @@
'jetpack_subscriptions_login_navigation_enabled' => '(bool) Whether the Subscriber Login block navigation placement is enabled',
'jetpack_subscriptions_subscribe_navigation_enabled' => '(Bool) Whether the Subscribe block navigation placement is enabled',
'wpcom_ai_site_prompt' => '(string) User input in the AI site prompt',
- 'jetpack_account_protection_strict_mode' => '(bool) Whether to enforce strict password requirements',
'jetpack_waf_automatic_rules' => '(bool) Whether the WAF should enforce automatic firewall rules',
'jetpack_waf_ip_allow_list' => '(string) List of IP addresses to always allow',
'jetpack_waf_ip_allow_list_enabled' => '(bool) Whether the IP allow list is enabled',
@@ -491,7 +490,6 @@ function ( $newsletter_category ) {
'jetpack_comment_form_color_scheme' => (string) get_option( 'jetpack_comment_form_color_scheme' ),
'in_site_migration_flow' => (string) get_option( 'in_site_migration_flow', '' ),
'migration_source_site_domain' => (string) get_option( 'migration_source_site_domain' ),
- 'jetpack_account_protection_strict_mode' => (bool) get_option( 'jetpack_account_protection_strict_mode' ),
'jetpack_waf_automatic_rules' => (bool) get_option( 'jetpack_waf_automatic_rules' ),
'jetpack_waf_ip_allow_list' => (string) get_option( 'jetpack_waf_ip_allow_list' ),
'jetpack_waf_ip_allow_list_enabled' => (bool) get_option( 'jetpack_waf_ip_allow_list_enabled' ),
diff --git a/projects/plugins/protect/src/class-jetpack-protect.php b/projects/plugins/protect/src/class-jetpack-protect.php
index ea02244a44e5a..e67b6eddb26f5 100644
--- a/projects/plugins/protect/src/class-jetpack-protect.php
+++ b/projects/plugins/protect/src/class-jetpack-protect.php
@@ -214,7 +214,6 @@ public function initial_state() {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
$refresh_status_from_wpcom = isset( $_GET['checkPlan'] );
$status = Status::get_status( $refresh_status_from_wpcom );
- $account_protection = new Account_Protection();
$initial_state = array(
'apiRoot' => esc_url_raw( rest_url() ),
@@ -233,10 +232,7 @@ public function initial_state() {
'jetpackScan' => My_Jetpack_Products::get_product( 'scan' ),
'hasPlan' => Plan::has_required_plan(),
'onboardingProgress' => Onboarding::get_current_user_progress(),
- 'accountProtection' => array(
- 'isEnabled' => $account_protection->is_enabled(),
- 'settings' => $account_protection->get_settings(),
- ),
+ 'accountProtection' => ( new Account_Protection() )->is_enabled(),
'waf' => array(
'wafSupported' => Waf_Runner::is_supported_environment(),
'currentIp' => IP_Utils::get_ip(),
diff --git a/projects/plugins/protect/src/class-rest-controller.php b/projects/plugins/protect/src/class-rest-controller.php
index b6ddb432afa23..fb6dd1dba9fd4 100644
--- a/projects/plugins/protect/src/class-rest-controller.php
+++ b/projects/plugins/protect/src/class-rest-controller.php
@@ -403,7 +403,7 @@ public static function api_toggle_account_protection() {
* @return WP_Rest_Response
*/
public static function api_get_account_protection() {
- return new WP_REST_Response( ( new Account_Protection() )->get_settings() );
+ return new WP_REST_Response( ( new Account_Protection() )->is_enabled() );
}
/**
diff --git a/projects/plugins/protect/src/js/api.ts b/projects/plugins/protect/src/js/api.ts
index 186ac89c2c513..b87875b8b188a 100644
--- a/projects/plugins/protect/src/js/api.ts
+++ b/projects/plugins/protect/src/js/api.ts
@@ -1,11 +1,10 @@
import { type FixersStatus, type ScanStatus } from '@automattic/jetpack-scan';
import apiFetch from '@wordpress/api-fetch';
import camelize from 'camelize';
-import { AccountProtectionStatus } from './types/account-protection';
import { WafStatus } from './types/waf';
const API = {
- getAccountProtection: (): Promise< AccountProtectionStatus > =>
+ getAccountProtection: () =>
apiFetch( {
path: 'jetpack-protect/v1/account-protection',
method: 'GET',
@@ -17,13 +16,6 @@ const API = {
path: 'jetpack-protect/v1/toggle-account-protection',
} ),
- updateAccountProtection: data =>
- apiFetch( {
- method: 'POST',
- path: 'jetpack/v4/account-protection',
- data,
- } ).then( camelize ),
-
getWaf: (): Promise< WafStatus > =>
apiFetch( {
path: 'jetpack-protect/v1/waf',
diff --git a/projects/plugins/protect/src/js/data/account-protection/use-account-protection-mutation.ts b/projects/plugins/protect/src/js/data/account-protection/use-account-protection-mutation.ts
deleted file mode 100644
index 592c5b983c37a..0000000000000
--- a/projects/plugins/protect/src/js/data/account-protection/use-account-protection-mutation.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import { useMutation, UseMutationResult, useQueryClient } from '@tanstack/react-query';
-import { __ } from '@wordpress/i18n';
-import camelize from 'camelize';
-import API from '../../api';
-import { QUERY_ACCOUNT_PROTECTION_KEY } from '../../constants';
-import useNotices from '../../hooks/use-notices';
-import { AccountProtectionStatus } from '../../types/account-protection';
-
-/**
- * Account Protection Mutatation Hook
- *
- * @return {UseMutationResult} useMutation result.
- */
-export default function useAccountProtectionMutation(): UseMutationResult<
- unknown,
- { [ key: string ]: unknown },
- unknown,
- { initialValue: AccountProtectionStatus }
-> {
- const queryClient = useQueryClient();
- const { showSuccessNotice, showSavingNotice, showErrorNotice } = useNotices();
-
- return useMutation( {
- mutationFn: API.updateAccountProtection,
- onMutate: settings => {
- showSavingNotice();
-
- // Get the current Account Protection settings.
- const initialValue = queryClient.getQueryData( [
- QUERY_ACCOUNT_PROTECTION_KEY,
- ] ) as AccountProtectionStatus;
-
- // Optimistically update the Account Protection settings.
- queryClient.setQueryData(
- [ QUERY_ACCOUNT_PROTECTION_KEY ],
- ( accountProtectionStatus: AccountProtectionStatus ) => ( {
- ...accountProtectionStatus,
- settings: {
- ...accountProtectionStatus.settings,
- ...camelize( settings ),
- },
- } )
- );
-
- return { initialValue };
- },
- onSuccess: () => {
- showSuccessNotice( __( 'Changes saved.', 'jetpack-protect' ) );
- },
- onError: ( error, variables, context ) => {
- // Reset the account protection config to its previous state.
- queryClient.setQueryData( [ QUERY_ACCOUNT_PROTECTION_KEY ], context.initialValue );
-
- showErrorNotice( __( 'Error saving changes.', 'jetpack-protect' ) );
- },
- } );
-}
diff --git a/projects/plugins/protect/src/js/data/account-protection/use-account-protection-query.ts b/projects/plugins/protect/src/js/data/account-protection/use-account-protection-query.ts
index 01dd3354432a9..8bd32f8ddf951 100644
--- a/projects/plugins/protect/src/js/data/account-protection/use-account-protection-query.ts
+++ b/projects/plugins/protect/src/js/data/account-protection/use-account-protection-query.ts
@@ -2,14 +2,13 @@ import { useQuery, UseQueryResult } from '@tanstack/react-query';
import camelize from 'camelize';
import API from '../../api';
import { QUERY_ACCOUNT_PROTECTION_KEY } from '../../constants';
-import { AccountProtectionStatus } from '../../types/account-protection';
/**
* Account Protection Query Hook
*
* @return {UseQueryResult} useQuery result.
*/
-export default function useAccountProtectionQuery(): UseQueryResult< AccountProtectionStatus > {
+export default function useAccountProtectionQuery(): UseQueryResult {
return useQuery( {
queryKey: [ QUERY_ACCOUNT_PROTECTION_KEY ],
queryFn: API.getAccountProtection,
diff --git a/projects/plugins/protect/src/js/data/account-protection/use-toggle-account-protection-module-mutation.ts b/projects/plugins/protect/src/js/data/account-protection/use-toggle-account-protection-module-mutation.ts
index 2f8ca342902ea..68c5b53ee0d40 100644
--- a/projects/plugins/protect/src/js/data/account-protection/use-toggle-account-protection-module-mutation.ts
+++ b/projects/plugins/protect/src/js/data/account-protection/use-toggle-account-protection-module-mutation.ts
@@ -3,7 +3,6 @@ import { __ } from '@wordpress/i18n';
import API from '../../api';
import { QUERY_ACCOUNT_PROTECTION_KEY } from '../../constants';
import useNotices from '../../hooks/use-notices';
-import { AccountProtectionStatus } from '../../types/account-protection';
/**
* Toggle Account Protection Mutatation
@@ -19,19 +18,9 @@ export default function useToggleAccountProtectionMutation(): UseMutationResult
onMutate: () => {
showSavingNotice();
- // Get the current Account Protection settings.
- const initialValue = queryClient.getQueryData( [
- QUERY_ACCOUNT_PROTECTION_KEY,
- ] ) as AccountProtectionStatus;
+ const initialValue = queryClient.getQueryData( [ QUERY_ACCOUNT_PROTECTION_KEY ] );
- // Optimistically update the Account Protection settings.
- queryClient.setQueryData(
- [ QUERY_ACCOUNT_PROTECTION_KEY ],
- ( accountProtectionStatus: AccountProtectionStatus ) => ( {
- ...accountProtectionStatus,
- isEnabled: ! initialValue.isEnabled,
- } )
- );
+ queryClient.setQueryData( [ QUERY_ACCOUNT_PROTECTION_KEY ], ! initialValue );
return { initialValue };
},
@@ -39,7 +28,10 @@ export default function useToggleAccountProtectionMutation(): UseMutationResult
showSuccessNotice( __( 'Changes saved.', 'jetpack-protect' ) );
},
onError: () => {
- showErrorNotice( __( 'Error savings changes.', 'jetpack-protect' ) );
+ showErrorNotice( __( 'An error occurred.', 'jetpack-protect' ) );
+ },
+ onSettled: () => {
+ queryClient.invalidateQueries( { queryKey: [ QUERY_ACCOUNT_PROTECTION_KEY ] } );
},
} );
}
diff --git a/projects/plugins/protect/src/js/hooks/use-account-protection-data/index.jsx b/projects/plugins/protect/src/js/hooks/use-account-protection-data/index.jsx
deleted file mode 100644
index 90e473c270bc6..0000000000000
--- a/projects/plugins/protect/src/js/hooks/use-account-protection-data/index.jsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import { useCallback } from 'react';
-import useAccountProtectionMutation from '../../data/account-protection/use-account-protection-mutation';
-import useAccountProtectionQuery from '../../data/account-protection/use-account-protection-query';
-import useToggleAccountProtectionMutation from '../../data/account-protection/use-toggle-account-protection-module-mutation';
-import useAnalyticsTracks from '../use-analytics-tracks';
-
-/**
- * Use Account Protection Data Hook
- *
- * @return {object} Account Protection data and methods for interacting with it.
- */
-const useAccountProtectionData = () => {
- const { recordEvent } = useAnalyticsTracks();
- const { data: accountProtection } = useAccountProtectionQuery();
- const accountProtectionMutation = useAccountProtectionMutation();
- const toggleAccountProtectionMutation = useToggleAccountProtectionMutation();
-
- /**
- * Toggle Account Protection Module
- *
- * Flips the switch on the Account Protection module, and then refreshes the data.
- */
- const toggleAccountProtection = useCallback( async () => {
- toggleAccountProtectionMutation.mutate();
- }, [ toggleAccountProtectionMutation ] );
-
- /**
- * Toggle Strict Mode
- *
- * Flips the switch on the strict mode option, and then refreshes the data.
- */
- const toggleStrictMode = useCallback( async () => {
- const value = ! accountProtection.settings.jetpackAccountProtectionStrictMode;
- const mutationObj = { jetpack_account_protection_strict_mode: value };
- if ( ! value ) {
- mutationObj.jetpack_account_protection_strict_mode = false;
- }
- await accountProtectionMutation.mutateAsync( mutationObj );
- recordEvent(
- mutationObj
- ? 'jetpack_account_protection_strict_mode_enabled'
- : 'jetpack_account_protection_strict_mode_disabled'
- );
- }, [
- recordEvent,
- accountProtection.settings.jetpackAccountProtectionStrictMode,
- accountProtectionMutation,
- ] );
-
- return {
- ...accountProtection,
- isUpdating: accountProtectionMutation.isPending,
- isToggling: toggleAccountProtectionMutation.isPending,
- toggleAccountProtection,
- toggleStrictMode,
- };
-};
-
-export default useAccountProtectionData;
diff --git a/projects/plugins/protect/src/js/routes/settings/index.jsx b/projects/plugins/protect/src/js/routes/settings/index.jsx
index 3fe6b735f7d3e..459bc542586b1 100644
--- a/projects/plugins/protect/src/js/routes/settings/index.jsx
+++ b/projects/plugins/protect/src/js/routes/settings/index.jsx
@@ -8,22 +8,27 @@ import {
import { createInterpolateElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Icon, warning } from '@wordpress/icons';
+import React, { useCallback } from 'react';
import AdminPage from '../../components/admin-page';
-import useAccountProtectionData from '../../hooks/use-account-protection-data';
+import useAccountProtectionQuery from '../../data/account-protection/use-account-protection-query';
+import useToggleAccountProtectionMutation from '../../data/account-protection/use-toggle-account-protection-module-mutation';
import useAnalyticsTracks from '../../hooks/use-analytics-tracks';
import usePlan from '../../hooks/use-plan';
import styles from './styles.module.scss';
const SettingsPage = () => {
const { hasPlan } = usePlan();
- const {
- settings: { jetpackAccountProtectionStrictMode: strictMode },
- isEnabled: isAccountProtectionEnabled,
- toggleAccountProtection,
- toggleStrictMode,
- isToggling,
- isUpdating,
- } = useAccountProtectionData();
+ const { data: accountProtectionIsEnabled } = useAccountProtectionQuery();
+ const toggleAccountProtectionMutation = useToggleAccountProtectionMutation();
+
+ /**
+ * Toggle Account Protect Module
+ *
+ * Flips the switch on the Account Protection module, and then refreshes the data.
+ */
+ const toggleAccountProtection = useCallback( async () => {
+ toggleAccountProtectionMutation.mutate();
+ }, [ toggleAccountProtectionMutation ] );
// Track view for Protect Account Protection page.
useAnalyticsTracks( {
@@ -37,9 +42,9 @@ const SettingsPage = () => {
@@ -49,47 +54,7 @@ const SettingsPage = () => {
{ createInterpolateElement(
__(
- 'When enabled, users can only set passwords that meet strong security standards, helping protect their accounts and your site.',
- 'jetpack-protect'
- ),
- {
- link: , // TODO: Update this redirect URL
- }
- ) }
-
-
-
- );
-
- const strictModeSettings = (
-
-
-
-
-
-
- { __( 'Require strongs passwords', 'jetpack-protect' ) }
-
-
- { createInterpolateElement(
- __(
- 'When enabled, users can only set passwords that meet strong security standards, helping protect their accounts and your site.',
- 'jetpack-protect'
- ),
- {
- link: , // TODO: Update this redirect URL
- }
- ) }
-
-
-
- { createInterpolateElement(
- __(
- 'Jetpack recommends activating this setting. Please be mindful of the risks.',
+ 'Protect your site with enhanced password detection and profile management security.',
'jetpack-protect'
),
{
@@ -97,6 +62,20 @@ const SettingsPage = () => {
}
) }
+ { ! accountProtectionIsEnabled && (
+
+
+ { createInterpolateElement(
+ __(
+ 'Jetpack recommends activating this setting. Please be mindful of the risks.',
+ 'jetpack-protect'
+ ),
+ {
+ link: , // TODO: Update this redirect URL
+ }
+ ) }
+
+ ) }
);
@@ -109,10 +88,7 @@ const SettingsPage = () => {
-
- { accountProtectionSettings }
- { isAccountProtectionEnabled && strictModeSettings }
-
+ { accountProtectionSettings }
diff --git a/projects/plugins/protect/src/js/types/account-protection.ts b/projects/plugins/protect/src/js/types/account-protection.ts
deleted file mode 100644
index 37d557638982b..0000000000000
--- a/projects/plugins/protect/src/js/types/account-protection.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-export type AccountProtectionStatus = {
- /** Whether the "account-protection" module is enabled. */
- isEnabled: boolean;
-
- /** The current Account Protetion settings. */
- settings: AccountProtectionSettings;
-};
-
-export type AccountProtectionSettings = {
- /** Whether the user has enabled strict mode. */
- jetpackAccountProtectionStrictMode: boolean;
-};