Skip to content

Commit

Permalink
UIU-3105: hide permissionSets from settings/users navigation pane if …
Browse files Browse the repository at this point in the history
…roles interface is present (#2689)

Refs UIU-3105.
  • Loading branch information
aidynoJ authored Jun 7, 2024
1 parent 16835fb commit 9e4f9a8
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* Show Roles assigned to users. Refs UIU-3110.
* Add edit user roles accordion on edit role modal view. Refs UIU-3021.
* Wire up with API ability to assign/unassign user roles in UserForm. Refs UIU-3124.
* Fix filter issues in user roles modal. Refs UIU-3124.
* Fix filter issues in user roles modal. Refs UIU-3124.
* Suppress Settings > Users > Permission sets when `roles` interface is present. Refs UIU-3105.

## [10.1.0](https://github.com/folio-org/ui-users/tree/v10.1.0) (2024-03-20)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v10.0.4...v10.1.0)
Expand Down
10 changes: 8 additions & 2 deletions src/settings/components/SectionPageItem.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import { IfInterface, IfPermission } from '@folio/stripes/core';
import { IfInterface, IfPermission, useStripes } from '@folio/stripes/core';
import {
NavListItem,
} from '@folio/stripes/components';

const SectionPageItem = ({ setting, path }) => {
const stripes = useStripes();
let sectionItem = (
<NavListItem to={`${path}/${setting.route}`} data-test-sectionpageitem>
{setting.label}
Expand All @@ -28,6 +29,10 @@ const SectionPageItem = ({ setting, path }) => {
);
}

if (stripes.hasInterface(setting?.unlessInterface)) {
sectionItem = null;
}

return sectionItem;
};

Expand All @@ -38,7 +43,8 @@ SectionPageItem.propTypes = {
label: PropTypes.element,
perm: PropTypes.string,
route: PropTypes.string,
})
unlessInterface: PropTypes.string
}),
};

export default SectionPageItem;
61 changes: 59 additions & 2 deletions src/settings/components/SectionPageItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@folio/jest-config-stripes/testing-library/react';
import { createMemoryHistory } from 'history';
import { FormattedMessage } from 'react-intl';
import { useStripes } from '@folio/stripes/core';

import '__mock__';
import SectionPageItem from './SectionPageItem';
Expand All @@ -24,6 +25,14 @@ const renderSectionPageItem = ({ setting, path }) => {

describe('Settings SectionPageItem', () => {
let sectionPageItem;
beforeAll(() => {
useStripes.mockClear().mockReturnValue({ hasInterface: () => false });
});

afterAll(() => {
jest.clearAllMocks();
cleanup();
});

describe('vanilla', () => {
beforeEach(() => {
Expand All @@ -47,8 +56,6 @@ describe('Settings SectionPageItem', () => {
});
});



describe('with interface present', () => {
beforeEach(() => {
sectionPageItem = renderSectionPageItem({
Expand Down Expand Up @@ -140,4 +147,54 @@ describe('Settings SectionPageItem', () => {
expect(sectionContent).toBeNull();
});
});

describe('with unlessInterface', () => {
beforeEach(() => {
useStripes.mockClear().mockReturnValue({ hasInterface: () => true });
sectionPageItem = renderSectionPageItem({
setting: {
route: 'some-route',
label: <FormattedMessage id="foo" />,
component: <div />,
perm: 'permission',
unlessInterface: 'goats'
},
path: 'funky-chicken',
});
});

afterEach(cleanup);

it('should not be rendered', () => {
const { container } = sectionPageItem;
const sectionContent = container.querySelector('[data-test-sectionpageitem]');
expect(container).toBeVisible();
expect(sectionContent).toBeNull();
});
});

describe('with no interface of unlessInterface', () => {
beforeEach(() => {
useStripes.mockClear().mockReturnValue({ hasInterface: () => false });
sectionPageItem = renderSectionPageItem({
setting: {
route: 'some-route',
label: <FormattedMessage id="foo" />,
component: <div />,
perm: 'permission',
unlessInterface: 'goats'
},
path: 'funky-chicken',
});
});

afterEach(cleanup);

it('should be rendered', () => {
const { container } = sectionPageItem;
const sectionContent = container.querySelector('[data-test-sectionpageitem]');
expect(container).toBeVisible();
expect(sectionContent).not.toBeNull();
});
});
});
1 change: 1 addition & 0 deletions src/settings/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const settingsGeneral = [
label: <FormattedMessage id="ui-users.settings.permissionSet" />,
component: PermissionSets,
perm: 'ui-users.settings.permsets.view',
unlessInterface: 'roles'
},
{
route: 'groups',
Expand Down

0 comments on commit 9e4f9a8

Please sign in to comment.