Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIU-3000 Can not edit shadow user account #2589

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [10.1.0] IN PROGRESS

* Also support `feesfines` interface version `19.0`. Refs UIU-2960.
* Can not edit shadow user account. Refs UIU-3000.
NikitaSedyx marked this conversation as resolved.
Show resolved Hide resolved

## [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
Loading