diff --git a/CHANGELOG.md b/CHANGELOG.md index 55750b931..d6798acea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change history for ui-users -## [11.0.0] IN PROGRESS +## [10.1.0] IN PROGRESS + +* Don't display affiliations of users with types `patron` or `dcb`. Refs UIU-2967. ## [10.0.0](https://github.com/folio-org/ui-users/tree/v10.0.0) (2023-10-13) [Full Changelog](https://github.com/folio-org/ui-users/compare/v9.0.3...v10.0.0) diff --git a/package.json b/package.json index 50c168b23..ff6c1c89b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@folio/users", - "version": "10.0.0", + "version": "10.1.0", "description": "User management", "repository": "folio-org/ui-users", "publishConfig": { diff --git a/src/components/PermissionsAccordion/PermissionsAccordion.js b/src/components/PermissionsAccordion/PermissionsAccordion.js index ad957de3b..8c673cdc4 100644 --- a/src/components/PermissionsAccordion/PermissionsAccordion.js +++ b/src/components/PermissionsAccordion/PermissionsAccordion.js @@ -27,6 +27,7 @@ import EnableUnassignAll from './EnableUnassignAll'; import AffiliationsSelect from '../AffiliationsSelect'; import IfConsortium from '../IfConsortium'; import IfConsortiumPermission from '../IfConsortiumPermission'; +import { isAffiliationsEnabled } from '../util'; const PermissionsAccordion = (props) => { const { @@ -57,6 +58,7 @@ const PermissionsAccordion = (props) => { const isAllowedPermissions = !!getAssignedPermissions().length; const isActionsDisabled = disabled || isLoading; + const isAffiliationsVisible = isAffiliationsEnabled(props.initialValues) && affiliations?.length > 1; const [permissionModalOpen, setPermissionModalOpen] = useState(false); const [unassignModalOpen, setUnassignModalOpen] = useState(false); @@ -186,7 +188,7 @@ const PermissionsAccordion = (props) => { > - {affiliations?.length > 1 && ( + {isAffiliationsVisible && ( { userId, })}`; }; + +export const isPatronUser = (user) => user?.type === USER_TYPES.PATRON; +export const isDcbUser = (user) => user?.type === USER_TYPES.DCB; + +export const isAffiliationsEnabled = (user) => { + return !isPatronUser(user) && !isDcbUser(user); +}; diff --git a/src/components/util/util.test.js b/src/components/util/util.test.js index 8418dd7c5..cec1dd32b 100644 --- a/src/components/util/util.test.js +++ b/src/components/util/util.test.js @@ -1,5 +1,6 @@ import '__mock__'; import okapiUser from 'fixtures/okapiCurrentUser'; +import { USER_TYPES } from '../../constants'; import { accountsMatchStatus, checkUserActive, @@ -21,6 +22,7 @@ import { getCentralTenantId, isConsortiumEnabled, getRequestUrl, + isAffiliationsEnabled, } from './util'; const STRIPES = { @@ -417,3 +419,19 @@ describe('getRequestUrl', () => { expect(getRequestUrl(undefined, userId)).toBe(`/requests/?layer=create&userId=${userId}`); }); }); + +describe('isAffiliationsEnabled', () => { + it('should return \'false\' if a user type is \'patron\'', () => { + expect(isAffiliationsEnabled({ type: USER_TYPES.PATRON })).toBeFalsy(); + }); + + it('should return \'false\' if a user type is \'dcb\'', () => { + expect(isAffiliationsEnabled({ type: USER_TYPES.DCB })).toBeFalsy(); + }); + + it('should return \'true\' if a user type is other than \'patron\' and \'dcb\'', () => { + expect(isAffiliationsEnabled({ type: USER_TYPES.SHADOW })).toBeTruthy(); + expect(isAffiliationsEnabled({ type: USER_TYPES.STAFF })).toBeTruthy(); + expect(isAffiliationsEnabled({ type: USER_TYPES.SYSTEM })).toBeTruthy(); + }); +}); diff --git a/src/constants.js b/src/constants.js index 6b0ac1496..d3571eb59 100644 --- a/src/constants.js +++ b/src/constants.js @@ -346,4 +346,5 @@ export const USER_TYPES = { SHADOW: 'shadow', STAFF: 'staff', SYSTEM: 'system', + DCB: 'dcb', }; diff --git a/src/hooks/useUserAffiliations/useUserAffiliations.js b/src/hooks/useUserAffiliations/useUserAffiliations.js index b7ead459b..0865b45b5 100644 --- a/src/hooks/useUserAffiliations/useUserAffiliations.js +++ b/src/hooks/useUserAffiliations/useUserAffiliations.js @@ -32,7 +32,11 @@ const useUserAffiliations = ({ userId } = {}, options = {}) => { const consortium = stripes?.user?.user?.consortium; const currentUserTenants = stripes?.user?.user?.tenants; - const { assignedToCurrentUser, ...queryOptions } = options; + const { + assignedToCurrentUser, + enabled: enabledOption = true, + ...queryOptions + } = options; const searchParams = { userId, @@ -42,7 +46,8 @@ const useUserAffiliations = ({ userId } = {}, options = {}) => { const enabled = Boolean( consortium?.centralTenantId && consortium?.id - && userId, + && userId + && enabledOption, ); const { diff --git a/src/views/UserDetail/UserDetail.js b/src/views/UserDetail/UserDetail.js index f5b70d4fa..eebf7db25 100644 --- a/src/views/UserDetail/UserDetail.js +++ b/src/views/UserDetail/UserDetail.js @@ -54,7 +54,10 @@ import HelperApp from '../../components/HelperApp'; import IfConsortium from '../../components/IfConsortium'; import { PatronBlockMessage } from '../../components/PatronBlock'; import { getFormAddressList } from '../../components/data/converters/address'; -import { getFullName } from '../../components/util'; +import { + getFullName, + isAffiliationsEnabled, +} from '../../components/util'; import RequestFeeFineBlockButtons from '../../components/RequestFeeFineBlockButtons'; import { departmentsShape } from '../../shapes'; import ErrorPane from '../../components/ErrorPane'; @@ -618,7 +621,7 @@ class UserDetail extends React.Component { const userDepartments = (user?.departments || []) .map(departmentId => departments.find(({ id }) => id === departmentId)?.name); const accounts = resources?.accounts; - const isAffiliationEnabled = user?.type !== USER_TYPES.PATRON; + const isAffiliationsVisible = isAffiliationsEnabled(user); const isShadowUser = user?.type === USER_TYPES.SHADOW; const showPatronBlocksSection = hasPatronBlocksPermissions && !isShadowUser; @@ -704,7 +707,7 @@ class UserDetail extends React.Component { { - isAffiliationEnabled && ( + isAffiliationsVisible && (