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 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [11.0.0] IN PROGRESS

* Don't display affiliations of users with types `patron` or `dbc`. Refs UIU-2967.

Copy link
Contributor

Choose a reason for hiding this comment

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

This one seems to be a target for Poppy bugfix. Please update the version in progress accordingly

Copy link
Member

Choose a reason for hiding this comment

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

Generally, our practice is to target all changes to the master branch and then to cherry-pick fixed onto patch branches. If somebody else's PR hits master before yours lands, you'll have to do this anyway, so I just plan for things to work out this way. I would do it like this:

  1. Bump the version on master in package.json to 10.1.0. You'll save a PR later if you do it in a separate PR now, but it's up to you.
  2. Merge this PR.
  3. Split a release branch named b10.0 from the commit where master was tagged and push it up so others can also pick bug fixes onto : (get checkout master; git checkout -b b10.0 v10.0.0; git push -u origin head).
  4. If you bumped the version in step 1 in a separate PR, you can just pick the commit from this PR onto your release branch: git cherry-pick -x SOME_HASH; git push, you're done! If you bumped the version in step 1 in this PR, you'll need to split a branch from b10.0, pick this fix onto it, fix the version in package.json, push the branch and open a PR with a target of b10.0.

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

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