mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 07:17:40 -02:30
Add new tests for rbac on some of the org pages
This commit is contained in:
@@ -176,4 +176,38 @@ describe('<OrganizationAccessList />', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('add role button visible for user that can edit org', () => {
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<OrganizationAccessList
|
||||||
|
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
||||||
|
removeRole={() => {}}
|
||||||
|
api={api}
|
||||||
|
organization={organization}
|
||||||
|
/>
|
||||||
|
).find('OrganizationAccessList');
|
||||||
|
|
||||||
|
setImmediate(() => {
|
||||||
|
const addRole = wrapper.update().find('DataListToolbar').find('PlusIcon');
|
||||||
|
expect(addRole.length).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('add role button hidden for user that cannot edit org', () => {
|
||||||
|
const readOnlyOrg = { ...organization };
|
||||||
|
readOnlyOrg.summary_fields.user_capabilities.edit = false;
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<OrganizationAccessList
|
||||||
|
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
||||||
|
removeRole={() => {}}
|
||||||
|
api={api}
|
||||||
|
organization={readOnlyOrg}
|
||||||
|
/>
|
||||||
|
).find('OrganizationAccessList');
|
||||||
|
|
||||||
|
setImmediate(() => {
|
||||||
|
const addRole = wrapper.update().find('DataListToolbar').find('PlusIcon');
|
||||||
|
expect(addRole.length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,4 +10,14 @@ describe('<OrganizationView />', () => {
|
|||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
mountWithContexts(<Organization me={me} />);
|
mountWithContexts(<Organization me={me} />);
|
||||||
});
|
});
|
||||||
|
test('notifications tab shown/hidden based on permissions', () => {
|
||||||
|
const wrapper = mountWithContexts(<Organization me={me} />);
|
||||||
|
expect(wrapper.find('.pf-c-tabs__item').length).toBe(3);
|
||||||
|
expect(wrapper.find('.pf-c-tabs__button[children="Notifications"]').length).toBe(0);
|
||||||
|
wrapper.find('Organization').setState({
|
||||||
|
isNotifAdmin: true
|
||||||
|
});
|
||||||
|
expect(wrapper.find('.pf-c-tabs__item').length).toBe(4);
|
||||||
|
expect(wrapper.find('.pf-c-tabs__button[children="Notifications"]').length).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -88,4 +88,28 @@ describe('<OrganizationDetail />', () => {
|
|||||||
expect(modifiedDetail.find('h6').text()).toBe('Last Modified');
|
expect(modifiedDetail.find('h6').text()).toBe('Last Modified');
|
||||||
expect(modifiedDetail.find('p').text()).toBe('Boo');
|
expect(modifiedDetail.find('p').text()).toBe('Boo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should show edit button for users with edit permission', () => {
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<OrganizationDetail
|
||||||
|
organization={mockDetails}
|
||||||
|
/>
|
||||||
|
).find('OrganizationDetail');
|
||||||
|
|
||||||
|
const editLink = wrapper.findWhere(node => node.props().to === '/organizations/undefined/edit');
|
||||||
|
expect(editLink.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should hide edit button for users without edit permission', () => {
|
||||||
|
const readOnlyOrg = { ...mockDetails };
|
||||||
|
readOnlyOrg.summary_fields.user_capabilities.edit = false;
|
||||||
|
const wrapper = mountWithContexts(
|
||||||
|
<OrganizationDetail
|
||||||
|
organization={readOnlyOrg}
|
||||||
|
/>
|
||||||
|
).find('OrganizationDetail');
|
||||||
|
|
||||||
|
const editLink = wrapper.findWhere(node => node.props().to === '/organizations/undefined/edit');
|
||||||
|
expect(editLink.length).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -135,14 +135,18 @@ class Organization extends Component {
|
|||||||
|| isAdminOfThisOrg
|
|| isAdminOfThisOrg
|
||||||
);
|
);
|
||||||
|
|
||||||
const tabElements = [
|
const tabsArray = [
|
||||||
{ name: i18nMark('Details'), link: `${match.url}/details` },
|
{ name: i18nMark('Details'), link: `${match.url}/details`, id: 0 },
|
||||||
{ name: i18nMark('Access'), link: `${match.url}/access` },
|
{ name: i18nMark('Access'), link: `${match.url}/access`, id: 1 },
|
||||||
{ name: i18nMark('Teams'), link: `${match.url}/teams` }
|
{ name: i18nMark('Teams'), link: `${match.url}/teams`, id: 2 }
|
||||||
];
|
];
|
||||||
|
|
||||||
if (canSeeNotificationsTab) {
|
if (canSeeNotificationsTab) {
|
||||||
tabElements.push({ name: i18nMark('Notifications'), link: `${match.url}/notifications` });
|
tabsArray.push({
|
||||||
|
name: i18nMark('Notifications'),
|
||||||
|
link: `${match.url}/notifications`,
|
||||||
|
id: 3
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let cardHeader = (
|
let cardHeader = (
|
||||||
@@ -158,12 +162,7 @@ class Organization extends Component {
|
|||||||
match={match}
|
match={match}
|
||||||
history={history}
|
history={history}
|
||||||
labeltext={i18n._(t`Organization detail tabs`)}
|
labeltext={i18n._(t`Organization detail tabs`)}
|
||||||
tabsArray={[
|
tabsArray={tabsArray}
|
||||||
{ name: i18nMark('Details'), link: `${match.url}/details`, id: 0 },
|
|
||||||
{ name: i18nMark('Access'), link: `${match.url}/access`, id: 1 },
|
|
||||||
{ name: i18nMark('Teams'), link: `${match.url}/teams`, id: 2 },
|
|
||||||
{ name: i18nMark('Notifications'), link: `${match.url}/notifications`, id: 3 },
|
|
||||||
]}
|
|
||||||
/>
|
/>
|
||||||
<Link
|
<Link
|
||||||
aria-label="Close"
|
aria-label="Close"
|
||||||
|
|||||||
Reference in New Issue
Block a user