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

[Enterprise Search] Add User management feature #103173

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d62ea2b
Rename method to close both flyouts
scottybollinger Jun 22, 2021
1a6cf9d
Add logic for elasticsearch users and single user role mappings
scottybollinger Jun 22, 2021
1881ef5
Add logic for various form states
scottybollinger Jun 22, 2021
c154afc
Add User server routes
scottybollinger Jun 22, 2021
859f9d1
Add logic for saving a user
scottybollinger Jun 22, 2021
ccf902c
Add User components
scottybollinger Jun 23, 2021
cf8aad3
Add User list and User flyout to RoleMappings view
scottybollinger Jun 23, 2021
c668bef
Fix path
scottybollinger Jun 23, 2021
0f6977e
Rename things
scottybollinger Jun 23, 2021
ebfea97
Set default group when modal closed
scottybollinger Jun 23, 2021
cb7307e
Adds tooltip for external attribute
scottybollinger Jun 23, 2021
2fcccc3
Fix invitations link
scottybollinger Jun 23, 2021
80c4f0e
Fix incorrect role type
scottybollinger Jun 23, 2021
9d1fb67
Add EuiPortal to Flyout
scottybollinger Jun 23, 2021
cac8cd5
Auth provider deprecation warning in mapping UI
scottybollinger Jun 23, 2021
08e954d
Email is no longer required
scottybollinger Jun 23, 2021
76c0c4c
Existing users’ usernames should not be editable
scottybollinger Jun 23, 2021
9d85270
Use EuiLink instead of anchor
scottybollinger Jun 23, 2021
bb6c539
Merge branch 'master' into scottybollinger/es-user-management
kibanamachine Jun 23, 2021
ae4c9bf
Add validation tests
scottybollinger Jun 23, 2021
92e493e
Change URL for users_and_roles
scottybollinger Jun 23, 2021
ea7776a
Remove unused import
scottybollinger Jun 23, 2021
e0924c2
Merge branch 'master' into scottybollinger/es-user-management
kibanamachine Jun 23, 2021
c14ebf5
Merge branch 'master' into scottybollinger/es-user-management
kibanamachine Jun 24, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ describe('useAppSearchNav', () => {
},
{
id: 'usersRoles',
name: 'Users & roles',
href: '/role_mappings',
name: 'Users and roles',
href: '/users_and_roles',
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { generateNavLink } from '../../../shared/layout';
import { ROLE_MAPPINGS_TITLE } from '../../../shared/role_mapping/constants';

import { AppLogic } from '../../app_logic';
import { ENGINES_PATH, SETTINGS_PATH, CREDENTIALS_PATH, ROLE_MAPPINGS_PATH } from '../../routes';
import { ENGINES_PATH, SETTINGS_PATH, CREDENTIALS_PATH, USERS_AND_ROLES_PATH } from '../../routes';
import { CREDENTIALS_TITLE } from '../credentials';
import { useEngineNav } from '../engine/engine_nav';
import { ENGINES_TITLE } from '../engines';
Expand Down Expand Up @@ -57,7 +57,7 @@ export const useAppSearchNav = () => {
navItems.push({
id: 'usersRoles',
name: ROLE_MAPPINGS_TITLE,
...generateNavLink({ to: ROLE_MAPPINGS_PATH }),
...generateNavLink({ to: USERS_AND_ROLES_PATH }),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const RoleMapping: React.FC = () => {
handleAuthProviderChange,
handleRoleChange,
handleSaveMapping,
closeRoleMappingFlyout,
closeUsersAndRolesFlyout,
} = useActions(RoleMappingsLogic);

const {
Expand Down Expand Up @@ -68,7 +68,7 @@ export const RoleMapping: React.FC = () => {
<RoleMappingFlyout
disabled={attributeValueInvalid || !hasEngineAssignment}
isNew={isNew}
closeRoleMappingFlyout={closeRoleMappingFlyout}
closeUsersAndRolesFlyout={closeUsersAndRolesFlyout}
handleSaveMapping={handleSaveMapping}
>
<EuiForm isInvalid={roleMappingErrors.length > 0} error={roleMappingErrors}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,39 @@ import React from 'react';

import { shallow } from 'enzyme';

import { RoleMappingsTable, RoleMappingsHeading } from '../../../shared/role_mapping';
import { wsRoleMapping } from '../../../shared/role_mapping/__mocks__/roles';
import {
RoleMappingsTable,
RoleMappingsHeading,
UsersHeading,
UsersEmptyPrompt,
} from '../../../shared/role_mapping';
import {
asRoleMapping,
asSingleUserRoleMapping,
} from '../../../shared/role_mapping/__mocks__/roles';

import { RoleMapping } from './role_mapping';
import { RoleMappings } from './role_mappings';
import { User } from './user';

describe('RoleMappings', () => {
const initializeRoleMappings = jest.fn();
const initializeRoleMapping = jest.fn();
const initializeSingleUserRoleMapping = jest.fn();
const handleDeleteMapping = jest.fn();
const mockValues = {
roleMappings: [wsRoleMapping],
roleMappings: [asRoleMapping],
dataLoading: false,
multipleAuthProvidersConfig: false,
singleUserRoleMappings: [asSingleUserRoleMapping],
singleUserRoleMappingFlyoutOpen: false,
};

beforeEach(() => {
setMockActions({
initializeRoleMappings,
initializeRoleMapping,
initializeSingleUserRoleMapping,
handleDeleteMapping,
});
setMockValues(mockValues);
Expand All @@ -50,10 +63,31 @@ describe('RoleMappings', () => {
expect(wrapper.find(RoleMapping)).toHaveLength(1);
});

it('handles onClick', () => {
it('renders User flyout', () => {
setMockValues({ ...mockValues, singleUserRoleMappingFlyoutOpen: true });
const wrapper = shallow(<RoleMappings />);

expect(wrapper.find(User)).toHaveLength(1);
});

it('handles RoleMappingsHeading onClick', () => {
const wrapper = shallow(<RoleMappings />);
wrapper.find(RoleMappingsHeading).prop('onClick')();

expect(initializeRoleMapping).toHaveBeenCalled();
});

it('handles UsersHeading onClick', () => {
const wrapper = shallow(<RoleMappings />);
wrapper.find(UsersHeading).prop('onClick')();

expect(initializeSingleUserRoleMapping).toHaveBeenCalled();
});

it('handles empty users state', () => {
setMockValues({ ...mockValues, singleUserRoleMappings: [] });
const wrapper = shallow(<RoleMappings />);

expect(wrapper.find(UsersEmptyPrompt)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import React, { useEffect } from 'react';

import { useActions, useValues } from 'kea';

import { EuiSpacer } from '@elastic/eui';

import { APP_SEARCH_PLUGIN } from '../../../../../common/constants';
import {
RoleMappingsTable,
RoleMappingsHeading,
RolesEmptyPrompt,
UsersTable,
UsersHeading,
UsersEmptyPrompt,
} from '../../../shared/role_mapping';
import { ROLE_MAPPINGS_TITLE } from '../../../shared/role_mapping/constants';

Expand All @@ -23,6 +28,7 @@ import { AppSearchPageTemplate } from '../layout';
import { ROLE_MAPPINGS_ENGINE_ACCESS_HEADING } from './constants';
import { RoleMapping } from './role_mapping';
import { RoleMappingsLogic } from './role_mappings_logic';
import { User } from './user';

const ROLES_DOCS_LINK = `${DOCS_PREFIX}/security-and-users.html`;

Expand All @@ -31,21 +37,26 @@ export const RoleMappings: React.FC = () => {
enableRoleBasedAccess,
initializeRoleMappings,
initializeRoleMapping,
initializeSingleUserRoleMapping,
handleDeleteMapping,
resetState,
} = useActions(RoleMappingsLogic);
const {
roleMappings,
singleUserRoleMappings,
multipleAuthProvidersConfig,
dataLoading,
roleMappingFlyoutOpen,
singleUserRoleMappingFlyoutOpen,
} = useValues(RoleMappingsLogic);

useEffect(() => {
initializeRoleMappings();
return resetState;
}, []);

const hasUsers = singleUserRoleMappings.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

[optional techdebt for the future] I've recently been refactoring flags like these to Kea selectors, it just generally feels nicer to have them in Kea


const rolesEmptyState = (
<RolesEmptyPrompt
productName={APP_SEARCH_PLUGIN.NAME}
Expand All @@ -72,6 +83,23 @@ export const RoleMappings: React.FC = () => {
</section>
);

const usersTable = (
<UsersTable
accessItemKey="engines"
singleUserRoleMappings={singleUserRoleMappings}
initializeSingleUserRoleMapping={initializeSingleUserRoleMapping}
handleDeleteMapping={handleDeleteMapping}
/>
);

const usersSection = (
<>
<UsersHeading onClick={() => initializeSingleUserRoleMapping()} />
<EuiSpacer />
{hasUsers ? usersTable : <UsersEmptyPrompt />}
</>
);

return (
<AppSearchPageTemplate
pageChrome={[ROLE_MAPPINGS_TITLE]}
Expand All @@ -81,7 +109,10 @@ export const RoleMappings: React.FC = () => {
emptyState={rolesEmptyState}
>
{roleMappingFlyoutOpen && <RoleMapping />}
{singleUserRoleMappingFlyoutOpen && <User />}
{roleMappingsSection}
<EuiSpacer size="xxl" />
{usersSection}
</AppSearchPageTemplate>
);
};
Loading