Skip to content

Commit

Permalink
UIU-3000 Can not edit shadow user account (#2589)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaSedyx authored and usavkov-epam committed Nov 21, 2023
1 parent 987b1b7 commit 15e220c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change history for ui-users

## [10.0.5] IN PROGRESS

* Disable validation for shadow user. Refs UIU-3000.

## [10.0.4](https://github.com/folio-org/ui-users/tree/v10.0.4) (2023-11-10)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v10.0.3...v10.0.4)

Expand Down
3 changes: 1 addition & 2 deletions src/components/EditSections/EditUserInfo/EditUserInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ class EditUserInfo extends React.Component {
dataOptions={patronGroupOptions}
defaultValue={initialValues.patronGroup}
aria-required="true"
required
disabled={disabled}
required={!disabled}
/>
<OnChange name="patronGroup">
{(selectedPatronGroup) => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/UserEdit/UserEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class UserEdit extends React.Component {
}

user.personal.addresses = toUserAddresses(user.personal.addresses); // eslint-disable-line no-param-reassign
user.personal.email = user.personal.email.trim();
user.personal.email = user.personal.email?.trim();
user.departments = compact(user.departments);

const { proxies, sponsors, permissions, servicePoints, preferredServicePoint } = user;
Expand Down
8 changes: 5 additions & 3 deletions src/views/UserEdit/UserForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { EditCustomFieldsRecord } from '@folio/stripes/smart-components';
import stripesFinalForm from '@folio/stripes/final-form';

import { USER_TYPES } from '../../constants';
import {
EditUserInfo,
EditExtendedInfo,
Expand All @@ -40,10 +41,11 @@ import getProxySponsorWarning from '../../components/util/getProxySponsorWarning
import TenantsPermissionsAccordion from './TenantsPermissionsAccordion';

import css from './UserForm.css';
import { USER_TYPES } from '../../constants';

export function validate(values) {
const isShadowUser = values?.type === USER_TYPES.SHADOW;
const errors = {};

errors.personal = {};

if (!values.personal || !values.personal.lastName) {
Expand All @@ -54,11 +56,11 @@ export function validate(values) {
errors.username = <FormattedMessage id="ui-users.errors.missingRequiredUsername" />;
}

if (!values.patronGroup) {
if (!isShadowUser && !values.patronGroup) {
errors.patronGroup = <FormattedMessage id="ui-users.errors.missingRequiredPatronGroup" />;
}

if (!values.personal || !values.personal.preferredContactTypeId) {
if (!isShadowUser && (!values.personal || !values.personal.preferredContactTypeId)) {
if (errors.personal) errors.personal.preferredContactTypeId = <FormattedMessage id="ui-users.errors.missingRequiredContactType" />;
else errors.personal = { preferredContactTypeId: <FormattedMessage id="ui-users.errors.missingRequiredContactType" /> };
}
Expand Down
12 changes: 12 additions & 0 deletions src/views/UserEdit/UserForm.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { FormattedMessage } from 'react-intl';

import { USER_TYPES } from '../../constants';

import { validate } from './UserForm';

describe('UserForm', () => {
Expand Down Expand Up @@ -43,6 +45,11 @@ describe('UserForm', () => {
expect(result.personal.preferredContactTypeId).toMatchObject(<FormattedMessage id="ui-users.errors.missingRequiredContactType" />);
});

it('not requires personal.preferredContactTypeId for shadow user', () => {
const result = validate({ personal: {}, type: USER_TYPES.SHADOW });
expect(result.personal.preferredContactTypeId).not.toBeDefined();
});

it('requires username when password is present', () => {
const result = validate({ creds: { password: 'thunder-chicken' } });
expect(result.username).toMatchObject(<FormattedMessage id="ui-users.errors.missingRequiredUsername" />);
Expand All @@ -53,6 +60,11 @@ describe('UserForm', () => {
expect(result.patronGroup).toMatchObject(<FormattedMessage id="ui-users.errors.missingRequiredPatronGroup" />);
});

it('not requires patronGroup for shadow user', () => {
const result = validate({ type: USER_TYPES.SHADOW });
expect(result.patronGroup).not.toBeDefined();
});

it('requires personal.addresses to have an addressType', () => {
const result = validate({ personal: { addresses: [{ 'monkey': 'bagel' }] } });
expect(result.personal.addresses[0].addressType).toMatchObject(<FormattedMessage id="ui-users.errors.missingRequiredAddressType" />);
Expand Down

0 comments on commit 15e220c

Please sign in to comment.