From c18f08683bc5a59c19278229b58c0f022444ae68 Mon Sep 17 00:00:00 2001 From: Artiom Ciumac Date: Tue, 28 May 2019 12:18:33 +0300 Subject: [PATCH] Fix to remove rendering of reserved fields in custom field edit form (#181) * Fix to remove rendering of reserved fields in custom field edit form * Fixed failing unit tests as custom fields form must not be rendered when only reserved custom fields are used * Removed test skipping clause --- client/components/Users/UserActions.jsx | 3 ++- client/components/Users/UserFieldsChangeForm.jsx | 10 +++++----- client/constants.js | 3 +++ tests/client/components/Users/UserActions.tests.js | 1 - .../components/Users/UserFieldsChangeForm.tests.js | 7 ++++++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/client/components/Users/UserActions.jsx b/client/components/Users/UserActions.jsx index 4e8c7ad31..d0ef53c8a 100644 --- a/client/components/Users/UserActions.jsx +++ b/client/components/Users/UserActions.jsx @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import { MenuItem, DropdownButton } from 'react-bootstrap'; import _ from 'lodash'; import { removeBlockedIPs } from "../../reducers/removeBlockedIPs"; +import { RESERVED_USER_FIELDS } from '../../constants'; export default class UserActions extends Component { static propTypes = { @@ -85,7 +86,7 @@ export default class UserActions extends Component { } /* Only display this if there are editable fields */ - const fieldsWithEdit = _.filter(this.props.userFields, field => field.edit); + const fieldsWithEdit = _.filter(this.props.userFields, field => !_.includes(RESERVED_USER_FIELDS, field.property) && field.edit); if (fieldsWithEdit.length <= 0) return null; return ( diff --git a/client/components/Users/UserFieldsChangeForm.jsx b/client/components/Users/UserFieldsChangeForm.jsx index 33aced9c6..315794e9e 100644 --- a/client/components/Users/UserFieldsChangeForm.jsx +++ b/client/components/Users/UserFieldsChangeForm.jsx @@ -6,6 +6,8 @@ import { reduxForm } from 'redux-form'; import UserCustomFormFields from './UserCustomFormFields'; +import { RESERVED_USER_FIELDS } from '../../constants'; + class UserFieldsChangeForm extends Component { static propTypes = { initialValues: PropTypes.object, @@ -15,19 +17,17 @@ class UserFieldsChangeForm extends Component { submitting: PropTypes.bool, customFields: PropTypes.array, languageDictionary: PropTypes.object, - loading: PropTypes.bool, + loading: PropTypes.bool }; render() { - const fields = this.props.customFields || []; if (fields.length === 0) return null; const languageDictionary = this.props.languageDictionary || {}; - const ignoreFields = [ 'username', 'memberships', 'connection', 'password', 'email', 'repeatPassword' ]; - const filteredCustomFields = _.filter(fields, field => !_.includes(ignoreFields, field.property) && field.edit); + const filteredCustomFields = _.filter(fields, field => !_.includes(RESERVED_USER_FIELDS, field.property) && field.edit); if (filteredCustomFields.length === 0) return null; @@ -48,7 +48,7 @@ class UserFieldsChangeForm extends Component { {languageDictionary.cancelButtonText || 'Cancel'} diff --git a/client/constants.js b/client/constants.js index f4da175b3..dfdc92925 100644 --- a/client/constants.js +++ b/client/constants.js @@ -250,3 +250,6 @@ export const FETCH_LANGUAGE_DICTIONARY_FULFILLED = 'FETCH_LANGUAGE_DICTIONARY_FU // Access level constants export const SUPER_ADMIN = 2; + +// The list of reserved user fields that must not be rendered in the custom fields edit form +export const RESERVED_USER_FIELDS = [ 'username', 'memberships', 'connection', 'password', 'email', 'repeatPassword', 'resetPassword' ]; diff --git a/tests/client/components/Users/UserActions.tests.js b/tests/client/components/Users/UserActions.tests.js index a42d31605..4cd5a44cc 100644 --- a/tests/client/components/Users/UserActions.tests.js +++ b/tests/client/components/Users/UserActions.tests.js @@ -153,7 +153,6 @@ describe('#Client-Components-UserActions', () => { "Change Email": changeEmail(), "Change Username": changeUsername(), "Reset Password": resetPassword(), - "Change Profile": changeFields(), "Delete User": deleteUser(), "Resend Verification Email": resendVerificationEmail() }; diff --git a/tests/client/components/Users/UserFieldsChangeForm.tests.js b/tests/client/components/Users/UserFieldsChangeForm.tests.js index acc74e76e..2045ff4ab 100644 --- a/tests/client/components/Users/UserFieldsChangeForm.tests.js +++ b/tests/client/components/Users/UserFieldsChangeForm.tests.js @@ -73,7 +73,12 @@ describe('#Client-Components-UserFieldsChangeForm', () => { }); it('should not render if the custom fields dont edit', () => { - const provider = renderComponent({}, [{ property: 'do.not.edit.me', edit: false }, { property: 'do.not.edit.me.either' }]); + const provider = renderComponent({}, [ { property: 'do.not.edit.me', edit: false }, { property: 'do.not.edit.me.either' } ]); + checkForm(provider, false); + }); + + it('should not render reserved fields', () => { + const provider = renderComponent({}, [ { property: 'password' } ]); checkForm(provider, false); });