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

Account Protection: Remove strict mode #41316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
3f56ee7
Add Account Protection toggle to Jetpack security settings
dkmyta Jan 9, 2025
719f950
Import package and run activation/deactivation on module toggle
dkmyta Jan 9, 2025
c83c604
changelog
dkmyta Jan 9, 2025
ab4f99a
Add Protect Settings page and hook up Account Protection toggle
dkmyta Jan 9, 2025
c2e8f1e
changelog
dkmyta Jan 9, 2025
b64fdaf
Update changelog
dkmyta Jan 9, 2025
13949a6
Merge branch 'add/jetpack/account-protection-security-settings' into …
dkmyta Jan 9, 2025
3f68536
Register modules on plugin activation
dkmyta Jan 9, 2025
3628b02
Ensure package is initialized on plugin activation
dkmyta Jan 9, 2025
3f90fe4
Make account protection class init static
dkmyta Jan 9, 2025
911e1db
Merge branch 'add/jetpack/account-protection-security-settings' into …
dkmyta Jan 9, 2025
3bfbcb3
Add auth hooks, redirect and a custom login action template
dkmyta Jan 13, 2025
289dbdb
Reorg, add Password_Detection class
dkmyta Jan 14, 2025
7eabdd3
Remove user cxn req and banner
dkmyta Jan 14, 2025
5a1af0b
Do not enabled module by default
dkmyta Jan 14, 2025
3b35efe
Add strict mode option and settings toggle
dkmyta Jan 15, 2025
4ddb644
changelog
dkmyta Jan 15, 2025
2a0e811
Merge branch 'add/jetpack/account-protection-security-settings' into …
dkmyta Jan 15, 2025
b62811b
Add strict mode toggle
dkmyta Jan 15, 2025
28f5820
Add strict mode toggle and endpoints
dkmyta Jan 15, 2025
da260ea
Rebase
dkmyta Jan 15, 2025
b72e93a
Reorg and add kill switch and is supported check
dkmyta Jan 15, 2025
7fad7f9
Add testing infrastructure
dkmyta Jan 15, 2025
39a28d5
Add email handlings, resend AJAX action, and attempt limitations
dkmyta Jan 16, 2025
da85a18
Add nonces, checks and template error handling
dkmyta Jan 17, 2025
6a43ec0
Use method over template to avoid lint errors
dkmyta Jan 17, 2025
7557056
Improve render_password_detection_template, update SVG file ext
dkmyta Jan 17, 2025
16845a7
Remove template file and include
dkmyta Jan 17, 2025
5f959f1
Prep for validation endpoints
dkmyta Jan 17, 2025
a4ba959
Update classes to be dynamic
dkmyta Jan 17, 2025
992f288
Add constructors
dkmyta Jan 17, 2025
43d4cd0
Reorg user meta methods
dkmyta Jan 17, 2025
3cec891
Add type declarations and hinting
dkmyta Jan 17, 2025
c61877b
Simplify method naming
dkmyta Jan 17, 2025
92d0ea6
Rebase, fix conflicts
dkmyta Jan 20, 2025
7634ed2
Use dynamic classes
dkmyta Jan 20, 2025
692db33
Update class dependencies
dkmyta Jan 20, 2025
22d2678
Fix copy
dkmyta Jan 20, 2025
0fd3e41
Revert unrelated changes
dkmyta Jan 20, 2025
805b367
Rebase, fix conflicts
dkmyta Jan 20, 2025
4383b5e
Revert unrelated changes
dkmyta Jan 20, 2025
9a70647
Fix method calls
dkmyta Jan 20, 2025
969102f
Do not activate by default
dkmyta Jan 20, 2025
8356bd4
Fix phan errors
dkmyta Jan 20, 2025
dad19c7
Merge branch 'add/jetpack/account-protection-security-settings' into …
dkmyta Jan 20, 2025
a5f1467
Rebase, fix conflicts
dkmyta Jan 20, 2025
32f3ef6
Changelog
dkmyta Jan 20, 2025
b02d511
Update composer deps
dkmyta Jan 20, 2025
7c255ac
Update lock files, add constructor method
dkmyta Jan 20, 2025
cdb0ac8
Fix php warning
dkmyta Jan 20, 2025
19efaea
Merge branch 'add/jetpack/account-protection-security-settings' into …
dkmyta Jan 20, 2025
1ce68b9
Update lock file
dkmyta Jan 20, 2025
7a06508
Changelog
dkmyta Jan 20, 2025
ddfa535
Rebase
dkmyta Jan 20, 2025
c128cf5
Fix Password_Detection constructor
dkmyta Jan 20, 2025
7a56b48
Changelog
dkmyta Jan 20, 2025
bc7aa77
More changelogs
dkmyta Jan 20, 2025
b28c8cf
Remove comments
dkmyta Jan 20, 2025
4bb5401
Fix static analysis errors
dkmyta Jan 20, 2025
20dec01
Remove top level phpunit.xml.dist
dkmyta Jan 20, 2025
2bdbf8e
Remove never return type
dkmyta Jan 20, 2025
a80c024
Revert tests dir changes in favour of a dedicated task
dkmyta Jan 20, 2025
f07e52e
Add tests dir
dkmyta Jan 20, 2025
80d0e92
Reapply default test infrastructure
dkmyta Jan 20, 2025
c03d626
Reorg and rename
dkmyta Jan 20, 2025
ae3b6b6
Update @package
dkmyta Jan 20, 2025
30f2329
Use never phpdoc return type as per static analysis error
dkmyta Jan 21, 2025
55ccadb
Merge branch 'add/account-protection' into add/jetpack/account-protec…
dkmyta Jan 21, 2025
3fed240
Merge branch 'add/jetpack/account-protection-security-settings' into …
dkmyta Jan 21, 2025
2beaca5
Merge branch 'add/protect/account-protection-settings' into add/packa…
dkmyta Jan 21, 2025
aad7ff6
Enable module by default
dkmyta Jan 21, 2025
de4fc75
Merge branch 'add/jetpack/account-protection-security-settings' into …
dkmyta Jan 21, 2025
448079b
Enable module by default
dkmyta Jan 21, 2025
bc263e0
Merge branch 'add/protect/account-protection-settings' into add/packa…
dkmyta Jan 21, 2025
4b18375
Remove all reference to and functionality of strict mode
dkmyta Jan 24, 2025
bbec51a
Rebase, fix conflicts
dkmyta Jan 24, 2025
7d72fd9
Remove unneeded strict mode code, update Protect settings UI
dkmyta Jan 24, 2025
36f0945
Updates/fixes
dkmyta Jan 24, 2025
37e0aa2
Fix import
dkmyta Jan 24, 2025
d51016d
Update placeholder content
dkmyta Jan 24, 2025
30b86d5
Revert unrelated changes
dkmyta Jan 24, 2025
6b34d25
Remove missed code
dkmyta Jan 24, 2025
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
10 changes: 0 additions & 10 deletions projects/js-packages/api/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' ) );
}

/**
Expand Down Expand Up @@ -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;
}
}
104 changes: 0 additions & 104 deletions projects/packages/account-protection/src/class-rest-controller.php

This file was deleted.

144 changes: 2 additions & 142 deletions projects/plugins/jetpack/_inc/client/security/account-protection.jsx
Original file line number Diff line number Diff line change
@@ -1,108 +1,22 @@
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 (
<SettingsCard
{ ...this.props }
module="account-protection"
header={ _x( 'Account protection', 'Settings header', 'jetpack' ) }
hideButton={ true }
feature={ FEATURE_JETPACK_ACCOUNT_PROTECTION }
>
{ isAccountProtectionActive && <QueryAccountProtectionSettings /> }
<SettingsGroup
hasChild
disableInOfflineMode
Expand All @@ -128,64 +42,10 @@ const AccountProtection = class extends Component {
) }
</span>
</ModuleToggle>
{ isAccountProtectionActive && (
<FormFieldset className="account-protection__settings">
<div className="account-protection__settings__toggle-setting">
<ToggleControl
checked={ this.props.settings?.strictMode }
disabled={ baseInputDisabledCase }
toggling={
this.props.isUpdatingAccountProtectionSettings &&
this.state.strictMode !== this.props.settings?.strictMode
}
onChange={ this.toggleStrictMode }
label={
<div className="account-protection__settings__toggle-setting__label">
<span className="jp-form-toggle-explanation">
{ __( 'Require strong passwords', 'jetpack' ) }
</span>
<InfoPopover
position="right"
screenReaderText={ __( 'Learn more', 'jetpack' ) }
className="account-protection__settings__strict-mode-popover"
>
{ createInterpolateElement(
__(
'Allow Jetpack to enforce strict password rules. <ExternalLink>Learn more</ExternalLink> <hr /> <ExternalLink>Privacy Information</ExternalLink>',
'jetpack'
),
{
ExternalLink: <ExternalLink href="#" />, // TODO: Update this redirect URL
hr: <hr />,
}
) }
</InfoPopover>
</div>
}
/>
</div>
</FormFieldset>
) }
</SettingsGroup>
</SettingsCard>
);
}
};

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 );
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/_inc/client/security/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
20 changes: 0 additions & 20 deletions projects/plugins/jetpack/_inc/client/security/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Loading
Loading