Skip to content

Commit

Permalink
[App Search] Role mappings migration part 1 (#94346)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
scottybollinger authored Mar 10, 2021
1 parent 5c352ca commit 2660362
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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}
Expand Down Expand Up @@ -159,7 +159,7 @@ export const EnginesTable: React.FC<EnginesTableProps> = ({
icon: 'eye',
onClick: (engineDetails) => {
sendEngineTableLinkClickTelemetry();
navigateToUrl(generteEncodedEnginePath(engineDetails.name));
navigateToUrl(generateEncodedEnginePath(engineDetails.name));
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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}`);
});
});
Original file line number Diff line number Diff line change
@@ -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 });
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
EuiTitle,
} from '@elastic/eui';

import { AttributeName, AttributeExamples } from '../types';

import {
ANY_AUTH_PROVIDER,
ANY_AUTH_PROVIDER_OPTION_LABEL,
Expand All @@ -31,8 +33,6 @@ import {
ATTRIBUTE_VALUE_LABEL,
} from './constants';

export type AttributeName = keyof AttributeExamples | 'role';

interface Props {
attributeName: AttributeName;
attributeValue?: string;
Expand All @@ -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[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand All @@ -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.',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -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 { 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';
} 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_BODY, ROLE_MAPPINGS_TABLE_HEADER } from './constants';

import { RoleMappingsLogic } from './role_mappings_logic';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit 2660362

Please sign in to comment.