[App Search] Role mappings migration part 1 (#94346)

* Fix test suite name

https://github.com/elastic/kibana/pull/94038/files#r590545670

* Move types out of AttributeSelector component to shared types

* Fix random typo

* Add routes and path generator util

* Move constants to shared

* Fix types in mock

* Fix routes

* Fix failing tests
This commit is contained in:
Scotty Bollinger 2021-03-10 16:16:46 -06:00 committed by GitHub
parent 5c352cace7
commit 26603620a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 84 additions and 48 deletions

View file

@ -54,7 +54,7 @@ export const EnginesTable: React.FC<EnginesTableProps> = ({
const { navigateToUrl } = useValues(KibanaLogic);
const { hasPlatinumLicense } = useValues(LicensingLogic);
const generteEncodedEnginePath = (engineName: string) =>
const generateEncodedEnginePath = (engineName: string) =>
generateEncodedPath(ENGINE_PATH, { engineName });
const sendEngineTableLinkClickTelemetry = () =>
sendAppSearchTelemetry({
@ -71,7 +71,7 @@ export const EnginesTable: React.FC<EnginesTableProps> = ({
render: (name: string) => (
<EuiLinkTo
data-test-subj="EngineNameLink"
to={generteEncodedEnginePath(name)}
to={generateEncodedEnginePath(name)}
onClick={sendEngineTableLinkClickTelemetry}
>
{name}
@ -159,7 +159,7 @@ export const EnginesTable: React.FC<EnginesTableProps> = ({
icon: 'eye',
onClick: (engineDetails) => {
sendEngineTableLinkClickTelemetry();
navigateToUrl(generteEncodedEnginePath(engineDetails.name));
navigateToUrl(generateEncodedEnginePath(engineDetails.name));
},
},
{

View file

@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { generateRoleMappingPath } from './utils';
describe('generateRoleMappingPath', () => {
it('generates paths with roleId filled', () => {
const roleId = 'role123';
expect(generateRoleMappingPath(roleId)).toEqual(`/role_mappings/${roleId}`);
});
});

View file

@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ROLE_MAPPING_PATH } from '../../routes';
import { generateEncodedPath } from '../../utils/encode_path_params';
export const generateRoleMappingPath = (roleId: string) =>
generateEncodedPath(ROLE_MAPPING_PATH, { roleId });

View file

@ -156,7 +156,7 @@ describe('AppSearchNav', () => {
const wrapper = shallow(<AppSearchNav />);
expect(wrapper.find(SideNavLink).last().prop('to')).toEqual(
'http://localhost:3002/as#/role-mappings'
'http://localhost:3002/as/role_mappings'
);
});
});

View file

@ -14,7 +14,10 @@ export const SETUP_GUIDE_PATH = '/setup_guide';
export const LIBRARY_PATH = '/library';
export const SETTINGS_PATH = '/settings/account';
export const CREDENTIALS_PATH = '/credentials';
export const ROLE_MAPPINGS_PATH = '#/role-mappings'; // This page seems to 404 if the # isn't included
export const ROLE_MAPPINGS_PATH = '/role_mappings';
export const ROLE_MAPPING_PATH = `${ROLE_MAPPINGS_PATH}/:roleId`;
export const ROLE_MAPPING_NEW_PATH = `${ROLE_MAPPINGS_PATH}/new`;
export const ENGINES_PATH = '/engines';
export const ENGINE_CREATION_PATH = '/engine_creation';

View file

@ -7,7 +7,7 @@
import { roleHasScopedEngines } from './';
describe('roleHasScopedEngines()', () => {
describe('roleHasScopedEngines', () => {
it('returns false for owner and admin roles', () => {
expect(roleHasScopedEngines('owner')).toEqual(false);
expect(roleHasScopedEngines('admin')).toEqual(false);

View file

@ -5,9 +5,11 @@
* 2.0.
*/
import { AttributeName } from '../../types';
export const asRoleMapping = {
id: null,
attributeName: 'role',
attributeName: 'role' as AttributeName,
attributeValue: ['superuser'],
authProvider: ['*'],
roleType: 'owner',
@ -23,7 +25,7 @@ export const asRoleMapping = {
export const wsRoleMapping = {
id: '602d4ba85foobarbaz123',
attributeName: 'username',
attributeName: 'username' as AttributeName,
attributeValue: 'user',
authProvider: ['*', 'other_auth'],
roleType: 'admin',

View file

@ -11,7 +11,9 @@ import { shallow, ShallowWrapper } from 'enzyme';
import { EuiComboBox, EuiFieldText } from '@elastic/eui';
import { AttributeSelector, AttributeName } from './attribute_selector';
import { AttributeName } from '../types';
import { AttributeSelector } from './attribute_selector';
import { ANY_AUTH_PROVIDER, ANY_AUTH_PROVIDER_OPTION_LABEL } from './constants';
const handleAttributeSelectorChange = jest.fn();

View file

@ -20,6 +20,8 @@ import {
EuiTitle,
} from '@elastic/eui';
import { AttributeName, AttributeExamples } from '../types';
import {
ANY_AUTH_PROVIDER,
ANY_AUTH_PROVIDER_OPTION_LABEL,
@ -31,8 +33,6 @@ import {
ATTRIBUTE_VALUE_LABEL,
} from './constants';
export type AttributeName = keyof AttributeExamples | 'role';
interface Props {
attributeName: AttributeName;
attributeValue?: string;
@ -47,12 +47,6 @@ interface Props {
handleAuthProviderChange?(value: string[]): void;
}
interface AttributeExamples {
username: string;
email: string;
metadata: string;
}
interface ParentOption extends EuiComboBoxOptionOption<string> {
label: string;
options: ChildOption[];

View file

@ -107,3 +107,25 @@ export const MANAGE_ROLE_MAPPING_BUTTON = i18n.translate(
defaultMessage: 'Manage',
}
);
export const ROLE_MAPPINGS_TITLE = i18n.translate(
'xpack.enterpriseSearch.roleMapping.roleMappingsTitle',
{
defaultMessage: 'Users & roles',
}
);
export const EMPTY_ROLE_MAPPINGS_TITLE = i18n.translate(
'xpack.enterpriseSearch.roleMapping.emptyRoleMappingsTitle',
{
defaultMessage: 'No role mappings yet',
}
);
export const ROLE_MAPPINGS_DESCRIPTION = i18n.translate(
'xpack.enterpriseSearch.roleMapping.roleMappingsDescription',
{
defaultMessage:
'Define role mappings for elasticsearch-native and elasticsearch-saml authentication.',
}
);

View file

@ -51,9 +51,17 @@ export interface RoleRules {
metadata?: string;
}
export interface AttributeExamples {
username: string;
email: string;
metadata: string;
}
export type AttributeName = keyof AttributeExamples | 'role';
export interface RoleMapping {
id: string;
attributeName: string;
attributeName: AttributeName;
attributeValue: string;
authProvider: string[];
roleType: string;

View file

@ -59,13 +59,6 @@ export const GROUP_ASSIGNMENT_ALL_GROUPS_LABEL = i18n.translate(
}
);
export const EMPTY_ROLE_MAPPINGS_TITLE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.roleMapping.emptyRoleMappingsTitle',
{
defaultMessage: 'No role mappings yet',
}
);
export const EMPTY_ROLE_MAPPINGS_BODY = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.roleMapping.emptyRoleMappingsBody',
{
@ -80,18 +73,3 @@ export const ROLE_MAPPINGS_TABLE_HEADER = i18n.translate(
defaultMessage: 'Group Access',
}
);
export const ROLE_MAPPINGS_TITLE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.roleMapping.roleMappingsTitle',
{
defaultMessage: 'Users & roles',
}
);
export const ROLE_MAPPINGS_DESCRIPTION = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.roleMapping.roleMappingsDescription',
{
defaultMessage:
'Define role mappings for elasticsearch-native and elasticsearch-saml authentication.',
}
);

View file

@ -14,16 +14,15 @@ import { EuiEmptyPrompt } from '@elastic/eui';
import { FlashMessages } from '../../../shared/flash_messages';
import { Loading } from '../../../shared/loading';
import { AddRoleMappingButton, RoleMappingsTable } from '../../../shared/role_mapping';
import {
EMPTY_ROLE_MAPPINGS_TITLE,
ROLE_MAPPINGS_TITLE,
ROLE_MAPPINGS_DESCRIPTION,
} from '../../../shared/role_mapping/constants';
import { ViewContentHeader } from '../../components/shared/view_content_header';
import { getRoleMappingPath, ROLE_MAPPING_NEW_PATH } from '../../routes';
import {
EMPTY_ROLE_MAPPINGS_TITLE,
EMPTY_ROLE_MAPPINGS_BODY,
ROLE_MAPPINGS_TABLE_HEADER,
ROLE_MAPPINGS_TITLE,
ROLE_MAPPINGS_DESCRIPTION,
} from './constants';
import { EMPTY_ROLE_MAPPINGS_BODY, ROLE_MAPPINGS_TABLE_HEADER } from './constants';
import { RoleMappingsLogic } from './role_mappings_logic';

View file

@ -10,8 +10,8 @@ import { kea, MakeLogicType } from 'kea';
import { clearFlashMessages, flashAPIErrors } from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
import { KibanaLogic } from '../../../shared/kibana';
import { AttributeName } from '../../../shared/role_mapping/attribute_selector';
import { ANY_AUTH_PROVIDER } from '../../../shared/role_mapping/constants';
import { AttributeName } from '../../../shared/types';
import { ROLE_MAPPINGS_PATH } from '../../routes';
import { RoleGroup, WSRoleMapping, Role } from '../../types';