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

UIBULKED-321:Permissions for editing Inventory records #358

Merged
merged 6 commits into from
Aug 4, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* [UIBULKED-282](https://issues.folio.org/browse/UIBULKED-282) Files generated more than 30 days ago can be downloaded from the "Logs".
* [UIBULKED-274](https://issues.folio.org/browse/UIBULKED-274) Create reusable permission-select component
* [UIBULKED-311](https://issues.folio.org/browse/UIBULKED-311) Bulk edit actions for notes - duplicate note.

* [UIBULKED-321](https://issues.folio.org/browse/UIBULKED-321) Permissions for editing Inventory records.

## [3.0.5](https://github.com/folio-org/ui-bulk-edit/tree/v3.0.5) (2023-03-22)

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"permissionName": "ui-bulk-edit.app-view",
"displayName": "Bulk Edit: In app - View inventory records",
"subPermissions": [
"ui-bulk-edit.view.base"
"ui-bulk-edit.view.base",
"ui-bulk-edit.edit.base"
],
"visible": true
},
Expand Down
7 changes: 5 additions & 2 deletions src/components/BulkEditActionMenu/BulkEditActionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ const BulkEditActionMenu = ({

const {
hasCsvEditPerms,
hasAnyInAppEditPermissions,
hasHoldingsInventoryEdit,
hasItemInventoryEdit,
} = perms;

const { id } = usePathParams('/bulk-edit/:id');
const { bulkDetails, isLoading } = useBulkOperationDetails({ id, additionalQueryKeys: [step] });

const [fileInfo, setFileInfo] = useState(null);

const hasEditPerm = hasHoldingsInventoryEdit || hasItemInventoryEdit;

useFileDownload({
id,
fileInfo,
Expand All @@ -62,7 +65,7 @@ const BulkEditActionMenu = ({
const isStartBulkCsvActive = hasCsvEditPerms && capability === CAPABILITIES.USER;
const isInitialStep = step === EDITING_STEPS.UPLOAD;
const isStartBulkInAppActive =
hasAnyInAppEditPermissions
hasEditPerm
&& isInitialStep
&& [JOB_STATUSES.DATA_MODIFICATION, JOB_STATUSES.REVIEW_CHANGES].includes(bulkDetails?.status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export const BulkEditListFilters = ({
hasCsvViewPerms,
hasInAppUsersEditPerms,
hasInAppViewPerms,
hasViewInAppPerms,
hasOnlyViewCsvPerms,
hasAnyInventoryWithInAppView,
} = permissions;
const showCallout = useShowCallout();
const history = useHistory();
Expand Down Expand Up @@ -235,7 +235,10 @@ export const BulkEditListFilters = ({
const renderListSelect = () => (
<ListSelect
value={recordIdentifier}
disabled={getIsDisabledByPerm(capabilities, isSelectIdentifiersDisabled, hasOnlyViewCsvPerms, hasViewInAppPerms)}
disabled={getIsDisabledByPerm(capabilities,
isSelectIdentifiersDisabled,
hasOnlyViewCsvPerms,
hasAnyInventoryWithInAppView)}
onChange={handleRecordIdentifierChange}
capabilities={capabilities}
/>
Expand All @@ -249,7 +252,7 @@ export const BulkEditListFilters = ({
handleDrop={handleDrop}
isDropZoneDisabled={isDropZoneDisabled
||
getIsDisabledByPerm(capabilities, isDropZoneDisabledPerm, hasOnlyViewCsvPerms, hasViewInAppPerms)}
getIsDisabledByPerm(capabilities, isDropZoneDisabledPerm, hasOnlyViewCsvPerms, hasAnyInventoryWithInAppView)}
recordIdentifier={recordIdentifier}
handleDragLeave={handleDragLeave}
handleDragEnter={handleDragEnter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ const Capabilities = ({
>
<RadioButtonGroup>
{capabilitiesFilterOptions?.map(option => (
<RadioButton
key={option.value}
label={option.label}
name="capabilities"
value={option.value}
disabled={option.disabled}
onChange={onCapabilityChange}
checked={option.value === capabilities}
/>
!option.hidden && (
<RadioButton
key={option.value}
label={option.label}
name="capabilities"
value={option.value}
disabled={option.disabled}
onChange={onCapabilityChange}
checked={option.value === capabilities}
/>
)
))}
</RadioButtonGroup>
</Accordion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getIsDisabledByPerm = (capabilities, defaultPerm, csvPerm, inAppVie
case CAPABILITIES.ITEM:
case CAPABILITIES.HOLDING:
if (inAppView) {
return true;
return false;
} else return defaultPerm;

default: return defaultPerm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('getIsDisabledByPerm', () => {
csvPerm = false;
inAppPerm = true;

expect(getIsDisabledByPerm(CAPABILITIES.ITEM, false, csvPerm, inAppPerm)).toBe(true);
expect(getIsDisabledByPerm(CAPABILITIES.ITEM, false, csvPerm, inAppPerm)).toBe(false);
});

it('should return correct boolean with default Perm', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import { CAPABILITIES, linkNamesMap } from '../../../constants';
import { useBulkPermissions } from '../../../hooks';

const BulkEditLogsActions = ({ item }) => {
const { hasUsersViewPerms } = useBulkPermissions();
const {
hasUsersViewPerms,
hasLogItemViewPerms,
hasLogHoldingsViewPerms,
hasInventoryInstanceViewPerms,
} = useBulkPermissions();
const [triggeredFile, setTriggeredFile] = useState(null);
const { refetch } = useFileDownload({
enabled: false,
Expand Down Expand Up @@ -80,6 +85,10 @@ const BulkEditLogsActions = ({ item }) => {
), [availableFiles]);

if (item.entityType === CAPABILITIES.USER && !hasUsersViewPerms) return null;
if (item.entityType === CAPABILITIES.HOLDING &&
(!hasLogHoldingsViewPerms || !hasInventoryInstanceViewPerms)) return null;
if (item.entityType === CAPABILITIES.ITEM &&
(!hasLogItemViewPerms && !hasInventoryInstanceViewPerms)) return null;

return (
item.expired ?
Expand Down
19 changes: 17 additions & 2 deletions src/hooks/useBulkPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ export const useBulkPermissions = () => {
const isActionMenuShown = hasCsvEditPerms || hasAnyInAppEditPermissions;
const isSelectIdentifiersDisabled = !hasAnyEditPermissions;
const isDropZoneDisabled = !hasAnyEditPermissions;
const isInventoryRadioDisabled = !hasInAppViewPerms;
const isUserRadioDisabled = !hasCsvViewPerms && !hasInAppUsersEditPerms;
const hasOnlyInAppViewPerms = hasInAppViewPerms && !hasCsvEditPerms && !hasInAppEditPerms && !hasInAppUsersEditPerms;
const hasItemInventoryView = hasInAppViewPerms && hasItemsPerms;
const hasHoldingsInventoryView = hasInAppViewPerms && hasHoldingsPerms;
const hasItemsAndHoldingsInventoryView = hasInAppViewPerms && hasInventoryInstanceViewPerms;
const hasItemInventoryEdit = hasInAppEditPerms && hasItemsPerms;
const hasHoldingsInventoryEdit = hasInAppEditPerms && hasHoldingsPerms;
const hasAnyInventoryWithInAppView = (hasItemInventoryView || hasHoldingsInventoryView
|| hasItemsAndHoldingsInventoryView) && hasInAppViewPerms;

// Logs perms
const hasLogViewPerms = stripes.hasPerm('ui-bulk-edit.logs.view');
const hasLogItemViewPerms = hasLogViewPerms && hasItemsPerms;
const hasLogHoldingsViewPerms = hasLogViewPerms && hasHoldingsPerms;

return {
// base
Expand All @@ -54,7 +62,6 @@ export const useBulkPermissions = () => {
isActionMenuShown,
isSelectIdentifiersDisabled,
isDropZoneDisabled,
isInventoryRadioDisabled,
isUserRadioDisabled,
hasOnlyInAppViewPerms,
hasAnyEditPermissions,
Expand All @@ -65,5 +72,13 @@ export const useBulkPermissions = () => {
hasUsersViewPerms,
hasOnlyViewCsvPerms,
hasViewInAppPerms,
hasItemInventoryEdit,
hasHoldingsInventoryEdit,
hasItemInventoryView,
hasHoldingsInventoryView,
hasItemsAndHoldingsInventoryView,
hasAnyInventoryWithInAppView,
hasLogItemViewPerms,
hasLogHoldingsViewPerms,
};
};
17 changes: 10 additions & 7 deletions src/utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@ export const isCapabilityDisabled = (capabilityValue, view, perms = {}) => {

const {
isUserRadioDisabled,
isInventoryRadioDisabled,
hasItemsPerms,
hasHoldingsPerms,
hasItemInventoryView,
hasHoldingsInventoryView,
hasItemsAndHoldingsInventoryView,
hasUsersPerms,
} = perms;

const capabilitiesMap = {
[CAPABILITIES.USER]: isQuery ? !hasUsersPerms : isUserRadioDisabled,
[CAPABILITIES.ITEM]: isQuery ? !hasItemsPerms : isInventoryRadioDisabled,
[CAPABILITIES.HOLDING]: isQuery ? !hasHoldingsPerms : isInventoryRadioDisabled,
[CAPABILITIES.ITEM]: hasItemInventoryView ?
!hasItemInventoryView : !hasItemsAndHoldingsInventoryView,
[CAPABILITIES.HOLDING]: hasHoldingsInventoryView ?
!hasHoldingsInventoryView :
!hasItemsAndHoldingsInventoryView,
};

return capabilitiesMap[capabilityValue];
};

export const getCapabilityOptions = (view, perms) => EDIT_CAPABILITIES_OPTIONS.map(capability => ({
...capability,
disabled: isCapabilityDisabled(capability.value, view, perms),
hidden: isCapabilityDisabled(capability.value, view, perms),
}));

export const getDefaultCapabilities = (view, perms) => {
const capabilityOptions = getCapabilityOptions(view, perms);

return capabilityOptions.find(option => !option.disabled)?.value;
return capabilityOptions.find(option => !option.hidden)?.value;
};

export const groupByCategory = (array) => {
Expand Down
Loading