Skip to content

Commit

Permalink
Fix to remove rendering of reserved fields in custom field edit form (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ArtiomCiumac authored and zxan1285 committed May 28, 2019
1 parent 1591f4a commit c18f086
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion client/components/Users/UserActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions client/components/Users/UserFieldsChangeForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -48,7 +48,7 @@ class UserFieldsChangeForm extends Component {
{languageDictionary.cancelButtonText || 'Cancel'}
</Button>
<Button bsSize="large" bsStyle="primary" disabled={loading} onClick={this.props.handleSubmit}>
{loading ? languageDictionary.savingText || 'Saving....' : languageDictionary.updateButtonText || 'Update'}
{loading ? languageDictionary.savingText || 'Saving....' : languageDictionary.updateButtonText || 'Update'}
</Button>
</Modal.Footer>
</div>
Expand Down
3 changes: 3 additions & 0 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];
1 change: 0 additions & 1 deletion tests/client/components/Users/UserActions.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
7 changes: 6 additions & 1 deletion tests/client/components/Users/UserFieldsChangeForm.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit c18f086

Please sign in to comment.