Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Settings: Remove problematic "blacklist"/"whitelist" language #4…
- Loading branch information
1 parent
f65f304
commit 8e1de1d
Showing
9 changed files
with
125 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} ); | ||
} ); |
Oops, something went wrong.