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-2967 Don't display affiliations of users with types patron or dcb #2570

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@folio/users",
"version": "10.0.0",
"version": "10.1.0",
"description": "User management",
"repository": "folio-org/ui-users",
"publishConfig": {
Expand Down
4 changes: 3 additions & 1 deletion src/components/PermissionsAccordion/PermissionsAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -186,7 +188,7 @@ const PermissionsAccordion = (props) => {
>
<IfConsortium>
<IfConsortiumPermission perm="consortia.user-tenants.collection.get">
{affiliations?.length > 1 && (
{isAffiliationsVisible && (
<AffiliationsSelect
affiliations={affiliations}
onChange={onChangeAffiliation}
Expand Down
8 changes: 8 additions & 0 deletions src/components/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import queryString from 'query-string';
import { NoValue } from '@folio/stripes/components';

import {
USER_TYPES,
requestStatuses,
sortTypes,
} from '../../constants';
Expand Down Expand Up @@ -199,3 +200,10 @@ export const getRequestUrl = (barcode, userId) => {
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);
};
Comment on lines +204 to +209
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests. I know these functions are dead-simple. At least the tests will be dead-simple too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've added.

18 changes: 18 additions & 0 deletions src/components/util/util.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '__mock__';
import okapiUser from 'fixtures/okapiCurrentUser';
import { USER_TYPES } from '../../constants';
import {
accountsMatchStatus,
checkUserActive,
Expand All @@ -21,6 +22,7 @@ import {
getCentralTenantId,
isConsortiumEnabled,
getRequestUrl,
isAffiliationsEnabled,
} from './util';

const STRIPES = {
Expand Down Expand Up @@ -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();
});
});
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,5 @@ export const USER_TYPES = {
SHADOW: 'shadow',
STAFF: 'staff',
SYSTEM: 'system',
DCB: 'dcb',
};
9 changes: 7 additions & 2 deletions src/hooks/useUserAffiliations/useUserAffiliations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,7 +46,8 @@ const useUserAffiliations = ({ userId } = {}, options = {}) => {
const enabled = Boolean(
consortium?.centralTenantId
&& consortium?.id
&& userId,
&& userId
&& enabledOption,
);

const {
Expand Down
9 changes: 6 additions & 3 deletions src/views/UserDetail/UserDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -704,7 +707,7 @@ class UserDetail extends React.Component {
<IfConsortium>
<IfConsortiumPermission perm="consortia.user-tenants.collection.get">
{
isAffiliationEnabled && (
isAffiliationsVisible && (
<UserAffiliations
accordionId="affiliationsSection"
expanded={sections.affiliationsSection}
Expand Down
2 changes: 2 additions & 0 deletions src/views/UserEdit/TenantsPermissionsAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
statusFilterConfig,
permissionTypeFilterConfig,
} from '../../components/PermissionsAccordion/helpers/filtersConfig';
import { isAffiliationsEnabled } from '../../components/util';
import {
useUserAffiliations,
useUserTenantPermissions,
Expand Down Expand Up @@ -93,6 +94,7 @@ const TenantsPermissionsAccordion = ({
} = useUserAffiliations(
{ userId },
{
enabled: isAffiliationsEnabled(initialValues),
onError: handleLoadAffiliationsError
},
);
Expand Down
Loading