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

UIIN-3187: ECS: Disable opening item details if a user is not affiliated with item's member tenant #2707

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Add "linked-data 1.0" interface to "optionalOkapiInterfaces". Refs UIIN-3166.
* Fix infinite loading animation after cancel edit/duplicate or 'Save & Close' consortial holdings/items. Fixes UIIN-3167.
* Remove hover-over text next to "Effective call number" on the Item record detail view. Refs UIIN-3131.
* ECS: Disable opening item details if a user is not affiliated with item's member tenant. Fixes UIIN-3187.

## [12.0.8](https://github.com/folio-org/ui-inventory/tree/v12.0.8) (2024-12-24)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v12.0.7...v12.0.8)
Expand Down
28 changes: 28 additions & 0 deletions src/components/InstancesList/InstancesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
withNamespace,
checkIfUserInCentralTenant,
TitleManager,
getUserTenantsPermissions,
} from '@folio/stripes/core';
import {
SearchAndSort,
Expand Down Expand Up @@ -83,6 +84,7 @@ import {
replaceFilter,
batchQueryIntoSmaller,
getSortOptions,
hasMemberTenantPermission,
} from '../../utils';
import {
INSTANCES_ID_REPORT_TIMEOUT,
Expand Down Expand Up @@ -213,6 +215,7 @@ class InstancesList extends React.Component {
searchAndSortKey: 0,
segmentsSortBy: this.getInitialSegmentsSortBy(),
searchInProgress: false,
userTenantPermissions: [],
};
}

Expand All @@ -222,6 +225,7 @@ class InstancesList extends React.Component {
location: _location,
getParams,
data,
stripes,
} = this.props;

const params = getParams();
Expand Down Expand Up @@ -260,6 +264,10 @@ class InstancesList extends React.Component {
if (isSortingUpdated || isStaffSuppressFilterChanged) {
this.redirectToSearchParams(searchParams);
}

if (isUserInConsortiumMode(stripes)) {
this.getCurrentTenantPermissions();
}
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -1190,6 +1198,15 @@ class InstancesList extends React.Component {
};
}

getCurrentTenantPermissions = () => {
const {
stripes,
stripes: { user: { user: { tenants } } },
} = this.props;

getUserTenantsPermissions(stripes, tenants).then(userTenantPermissions => this.setState({ userTenantPermissions }));
}

findAndOpenItem = async (instance) => {
const {
parentResources,
Expand All @@ -1213,6 +1230,17 @@ class InstancesList extends React.Component {

const tenantItemBelongsTo = instance?.items?.[0]?.tenantId || stripes.okapi.tenant;

// if a user is not affiliated with the item's member tenant then item details cannot be open
if (isUserInConsortiumMode(stripes)) {
const tenants = stripes.user.user.tenants || [];
const isUserAffiliatedWithMemberTenant = tenants.find(tenant => tenant?.id === tenantItemBelongsTo);
const canMemberTenantViewItems = hasMemberTenantPermission('ui-inventory.instance.view', tenantItemBelongsTo, this.state.userTenantPermissions);

if (isEmpty(isUserAffiliatedWithMemberTenant) || !canMemberTenantViewItems) {
return instance;
}
}

itemsByQuery.reset();
const items = await itemsByQuery.GET({
params: { query: itemQuery },
Expand Down
Loading