Skip to content

Commit

Permalink
Site Settings: Remove problematic "blacklist"/"whitelist" language #4…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Jun 25, 2020
1 parent f65f304 commit 8e1de1d
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 122 deletions.
36 changes: 19 additions & 17 deletions client/my-sites/comments/comment/comment-author-more-info.jsx
Expand Up @@ -20,7 +20,7 @@ import { urlToDomainAndPath } from 'lib/url';
import canCurrentUser from 'state/selectors/can-current-user';
import { getSiteComment } from 'state/comments/selectors';
import getSiteSetting from 'state/selectors/get-site-setting';
import isEmailBlacklisted from 'state/selectors/is-email-blacklisted';
import isAuthorsEmailBlocked from 'state/selectors/is-authors-email-blocked';
import {
bumpStat,
composeAnalytics,
Expand Down Expand Up @@ -52,12 +52,12 @@ export class CommentAuthorMoreInfo extends Component {
authorEmail,
authorId,
commentId,
isAuthorBlacklisted,
isAuthorBlocked,
showNotice,
siteBlacklist,
blockedCommentAuthorKeys,
siteId,
translate,
updateBlacklist,
updateBlockedCommentAuthors,
} = this.props;

const noticeOptions = {
Expand All @@ -67,27 +67,29 @@ export class CommentAuthorMoreInfo extends Component {
};

const analytics = {
action: isAuthorBlacklisted ? 'unblock_user' : 'block_user',
action: isAuthorBlocked ? 'unblock_user' : 'block_user',
user_type: authorId ? 'wpcom' : 'email_only',
};

if ( isAuthorBlacklisted ) {
const newBlacklist = siteBlacklist
if ( isAuthorBlocked ) {
const nextBlockedCommentAuthorKeys = blockedCommentAuthorKeys
.split( '\n' )
.filter( ( item ) => item !== authorEmail )
.join( '\n' );

updateBlacklist( siteId, newBlacklist, analytics );
updateBlockedCommentAuthors( siteId, nextBlockedCommentAuthorKeys, analytics );

return showNotice(
translate( 'User %(email)s unblocked.', { args: { email: authorEmail } } ),
noticeOptions
);
}

const newBlacklist = siteBlacklist ? siteBlacklist + '\n' + authorEmail : authorEmail;
const nextBlockedCommentAuthorKeys = blockedCommentAuthorKeys
? blockedCommentAuthorKeys + '\n' + authorEmail
: authorEmail;

updateBlacklist( siteId, newBlacklist, analytics );
updateBlockedCommentAuthors( siteId, nextBlockedCommentAuthorKeys, analytics );

showNotice(
translate( 'User %(email)s is blocked and can no longer comment on your site.', {
Expand All @@ -104,7 +106,7 @@ export class CommentAuthorMoreInfo extends Component {
authorIp,
authorUrl,
authorUsername,
isAuthorBlacklisted,
isAuthorBlocked,
showBlockUser,
siteSlug,
trackAnonymousModeration,
Expand Down Expand Up @@ -166,8 +168,8 @@ export class CommentAuthorMoreInfo extends Component {

{ showBlockUser && (
<div className="comment__author-more-info-element">
<Button onClick={ this.toggleBlockUser } scary={ ! isAuthorBlacklisted }>
{ isAuthorBlacklisted ? translate( 'Unblock user' ) : translate( 'Block user' ) }
<Button onClick={ this.toggleBlockUser } scary={ ! isAuthorBlocked }>
{ isAuthorBlocked ? translate( 'Unblock user' ) : translate( 'Block user' ) }
</Button>
</div>
) }
Expand Down Expand Up @@ -216,17 +218,17 @@ const mapStateToProps = ( state, { commentId } ) => {
authorIp: get( comment, 'author.ip_address' ),
authorUsername: get( comment, 'author.nice_name' ),
authorUrl: get( comment, 'author.URL', '' ),
isAuthorBlacklisted: isEmailBlacklisted( state, siteId, authorEmail ),
isAuthorBlocked: isAuthorsEmailBlocked( state, siteId, authorEmail ),
showBlockUser,
siteBlacklist: getSiteSetting( state, siteId, 'blacklist_keys' ),
blockedCommentAuthorKeys: getSiteSetting( state, siteId, 'blacklist_keys' ),
siteId,
siteSlug: getSelectedSiteSlug( state ),
};
};

const mapDispatchToProps = ( dispatch ) => ( {
showNotice: ( text, options ) => dispatch( successNotice( text, options ) ),
updateBlacklist: ( siteId, blacklist_keys, analytics ) =>
updateBlockedCommentAuthors: ( siteId, blockedCommentAuthorKeys, analytics ) =>
dispatch(
withAnalytics(
composeAnalytics(
Expand All @@ -238,7 +240,7 @@ const mapDispatchToProps = ( dispatch ) => ( {
: 'comment_author_unblocked'
)
),
saveSiteSettings( siteId, { blacklist_keys } )
saveSiteSettings( siteId, { blacklist_keys: blockedCommentAuthorKeys } )
)
),
trackAnonymousModeration: () =>
Expand Down
4 changes: 2 additions & 2 deletions client/my-sites/site-settings/disconnect-site/confirm.jsx
Expand Up @@ -33,7 +33,7 @@ class ConfirmDisconnection extends PureComponent {
translate: PropTypes.func,
};

static reasonWhitelist = [
static allowedReasons = [
'troubleshooting',
'cannot-work',
'slow',
Expand All @@ -48,7 +48,7 @@ class ConfirmDisconnection extends PureComponent {

const surveyData = {
'why-cancel': {
response: find( this.constructor.reasonWhitelist, ( r ) => r === reason ),
response: find( this.constructor.allowedReasons, ( r ) => r === reason ),
text: isArray( text ) ? text.join() : text,
},
source: {
Expand Down
16 changes: 8 additions & 8 deletions client/my-sites/site-settings/form-discussion.jsx
Expand Up @@ -513,7 +513,7 @@ class SiteSettingsFormDiscussion extends Component {
);
}

commentBlacklistSettings() {
disallowedCommentsSettings() {
const {
eventTracker,
fields,
Expand All @@ -525,22 +525,22 @@ class SiteSettingsFormDiscussion extends Component {
} = this.props;
return (
<FormFieldset>
<FormLegend>{ translate( 'Comment blacklist' ) }</FormLegend>
<FormLabel htmlFor="blacklist_keys">
<FormLegend>{ translate( 'Disallowed comments' ) }</FormLegend>
<FormLabel htmlFor="disallowed_comment_keys">
{ translate(
'When a comment contains any of these words in its content, name, URL, e-mail, or IP, it will be put in the trash. ' +
'One word or IP per line. It will match inside words, so "press" will match "WordPress".'
) }
</FormLabel>
<FormTextarea
name="blacklist_keys"
id="blacklist_keys"
name="disallowed_comment_keys"
id="disallowed_comment_keys"
value={ fields.blacklist_keys }
onChange={ onChangeField( 'blacklist_keys' ) }
disabled={ isRequestingSettings || isSavingSettings }
autoCapitalize="none"
onClick={ eventTracker( 'Clicked Blacklist Field' ) }
onKeyPress={ uniqueEventTracker( 'Typed in Blacklist Field' ) }
onClick={ eventTracker( 'Clicked Disallowed Comments Field' ) }
onKeyPress={ uniqueEventTracker( 'Typed in Disallowed Comments Field' ) }
/>
</FormFieldset>
);
Expand Down Expand Up @@ -608,7 +608,7 @@ class SiteSettingsFormDiscussion extends Component {
<hr />
{ this.commentModerationSettings() }
<hr />
{ this.commentBlacklistSettings() }
{ this.disallowedCommentsSettings() }
</Card>

{ isJetpack && (
Expand Down
40 changes: 20 additions & 20 deletions client/my-sites/site-settings/protect.jsx
Expand Up @@ -40,15 +40,15 @@ class Protect extends Component {
fields: {},
};

handleAddToWhitelist = () => {
handleAddToAllowedList = () => {
const { setFieldValue } = this.props;
let whitelist = trimEnd( this.getProtectWhitelist() );
let allowedIps = trimEnd( this.getProtectAllowedIps() );

if ( whitelist.length ) {
whitelist += '\n';
if ( allowedIps.length ) {
allowedIps += '\n';
}

setFieldValue( 'jetpack_protect_global_whitelist', whitelist + this.getIpAddress() );
setFieldValue( 'jetpack_protect_global_whitelist', allowedIps + this.getIpAddress() );
};

getIpAddress() {
Expand All @@ -59,22 +59,22 @@ class Protect extends Component {
return null;
}

getProtectWhitelist() {
getProtectAllowedIps() {
const { jetpack_protect_global_whitelist } = this.props.fields;
return jetpack_protect_global_whitelist || '';
}

isIpAddressWhitelisted() {
isIpAddressAllowed() {
const ipAddress = this.getIpAddress();
if ( ! ipAddress ) {
return false;
}

const whitelist = this.getProtectWhitelist().split( '\n' );
const allowedIps = this.getProtectAllowedIps().split( '\n' );

return (
includes( whitelist, ipAddress ) ||
some( whitelist, ( entry ) => {
includes( allowedIps, ipAddress ) ||
some( allowedIps, ( entry ) => {
if ( entry.indexOf( '-' ) < 0 ) {
return false;
}
Expand All @@ -97,7 +97,7 @@ class Protect extends Component {
} = this.props;

const ipAddress = this.getIpAddress();
const isIpWhitelisted = this.isIpAddressWhitelisted();
const isIpAllowed = this.isIpAddressAllowed();
const disabled =
isRequestingSettings || isSavingSettings || protectModuleUnavailable || ! protectModuleActive;
const protectToggle = (
Expand Down Expand Up @@ -137,31 +137,31 @@ class Protect extends Component {

{ ipAddress && (
<Button
className="protect__add-to-whitelist site-settings__add-to-whitelist"
onClick={ this.handleAddToWhitelist }
disabled={ disabled || isIpWhitelisted }
className="site-settings__add-to-explicitly-allowed-list"
onClick={ this.handleAddToAllowedList }
disabled={ disabled || isIpAllowed }
compact
>
{ isIpWhitelisted
? translate( 'Already in whitelist' )
: translate( 'Add to whitelist' ) }
{ isIpAllowed
? translate( 'Already in list of allowed IPs' )
: translate( 'Add to list of allowed IPs' ) }
</Button>
) }
</p>

<FormLabel htmlFor="jetpack_protect_global_whitelist">
{ translate( 'Whitelisted IP addresses' ) }
{ translate( 'Allowed IP addresses' ) }
</FormLabel>
<FormTextarea
id="jetpack_protect_global_whitelist"
value={ this.getProtectWhitelist() }
value={ this.getProtectAllowedIps() }
onChange={ onChangeField( 'jetpack_protect_global_whitelist' ) }
disabled={ disabled }
placeholder={ translate( 'Example: 12.12.12.1-12.12.12.100' ) }
/>
<FormSettingExplanation>
{ translate(
'You may whitelist an IP address or series of addresses preventing them from ' +
'You may explicitly allow an IP address or series of addresses preventing them from ' +
'ever being blocked by Jetpack. IPv4 and IPv6 are acceptable. ' +
'To specify a range, enter the low value and high value separated by a dash. ' +
'Example: 12.12.12.1-12.12.12.100'
Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/site-settings/style.scss
Expand Up @@ -461,7 +461,7 @@
margin-top: -21px;
}

.site-settings__add-to-whitelist {
.site-settings__add-to-explicitly-allowed-list {
margin-top: 3px;
}

Expand Down
25 changes: 25 additions & 0 deletions client/state/selectors/is-authors-email-blocked.js
@@ -0,0 +1,25 @@
/**
* External dependencies
*/
import { includes } from 'lodash';

/**
* Internal dependencies
*/
import getSiteSetting from 'state/selectors/get-site-setting';

/**
* Check if an email address is disallowed according to
* the list of blocked addresses for the site.
*
* @param {object} state Global state tree
* @param {number} siteId Site ID
* @param {string} email An email address.
* @returns {boolean} If the email address is disallowed.
*/
export const isAuthorsEmailBlocked = ( state, siteId, email = '' ) => {
const blocklist = getSiteSetting( state, siteId, 'blacklist_keys' ) || '';
return includes( blocklist.split( '\n' ), email );
};

export default isAuthorsEmailBlocked;
24 changes: 0 additions & 24 deletions client/state/selectors/is-email-blacklisted.js

This file was deleted.

50 changes: 50 additions & 0 deletions client/state/selectors/test/is-authors-email-blocked.js
@@ -0,0 +1,50 @@
/**
* External dependencies
*/
import { expect } from 'chai';

/**
* Internal dependencies
*/
import isAuthorsEmailBlocked from 'state/selectors/is-authors-email-blocked';

const email = 'foo@bar.baz';

const state = {
siteSettings: {
items: {
123: {
blacklist_keys: 'mail@mail.com\ntest@example.com\nfoo@bar.baz\nyadda@yadda.yadda',
},
456: {
blacklist_keys: 'mail@mail.com\ntest@example.com\nyadda@yadda.yadda',
},
789: {
blacklist_keys: '',
},
},
},
};

const noSiteSettingsState = { siteSettings: {} };

describe( 'isAuthorsEmailBlocked()', () => {
test( 'should return true if email is blocked', () => {
expect( isAuthorsEmailBlocked( state, 123, email ) ).to.be.true;
} );
test( 'should return false if email is not blocked', () => {
expect( isAuthorsEmailBlocked( state, 456, email ) ).to.be.false;
} );
test( 'should return false if blocklist is empty', () => {
expect( isAuthorsEmailBlocked( state, 789, email ) ).to.be.false;
} );
test( 'should return false if there are no site settings in state', () => {
expect( isAuthorsEmailBlocked( noSiteSettingsState, 123, email ) ).to.be.false;
} );
test( 'should return false if no email is provided', () => {
expect( isAuthorsEmailBlocked( state, 123 ) ).to.be.false;
} );
test( 'should return false if email is empty', () => {
expect( isAuthorsEmailBlocked( state, 123, '' ) ).to.be.false;
} );
} );

0 comments on commit 8e1de1d

Please sign in to comment.