Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ x-pack/packages/security-solution/side_nav @elastic/security-threat-hunting-expl
x-pack/packages/security-solution/storybook/config @elastic/security-threat-hunting-explore
x-pack/packages/security-solution/upselling @elastic/security-threat-hunting-explore
x-pack/test/security_functional/plugins/test_endpoints @elastic/kibana-security
x-pack/packages/security/ui_components @elastic/kibana-security
packages/kbn-securitysolution-autocomplete @elastic/security-detection-engine
x-pack/packages/security-solution/data_table @elastic/security-threat-hunting-investigations
packages/kbn-securitysolution-ecs @elastic/security-threat-hunting-explore
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@
"@kbn/security-solution-storybook-config": "link:x-pack/packages/security-solution/storybook/config",
"@kbn/security-solution-upselling": "link:x-pack/packages/security-solution/upselling",
"@kbn/security-test-endpoints-plugin": "link:x-pack/test/security_functional/plugins/test_endpoints",
"@kbn/security-ui-components": "link:x-pack/packages/security/ui_components",
"@kbn/securitysolution-autocomplete": "link:packages/kbn-securitysolution-autocomplete",
"@kbn/securitysolution-data-table": "link:x-pack/packages/security-solution/data_table",
"@kbn/securitysolution-ecs": "link:packages/kbn-securitysolution-ecs",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,8 @@
"@kbn/security-solution-upselling/*": ["x-pack/packages/security-solution/upselling/*"],
"@kbn/security-test-endpoints-plugin": ["x-pack/test/security_functional/plugins/test_endpoints"],
"@kbn/security-test-endpoints-plugin/*": ["x-pack/test/security_functional/plugins/test_endpoints/*"],
"@kbn/security-ui-components": ["x-pack/packages/security/ui_components"],
"@kbn/security-ui-components/*": ["x-pack/packages/security/ui_components/*"],
"@kbn/securitysolution-autocomplete": ["packages/kbn-securitysolution-autocomplete"],
"@kbn/securitysolution-autocomplete/*": ["packages/kbn-securitysolution-autocomplete/*"],
"@kbn/securitysolution-data-table": ["x-pack/packages/security-solution/data_table"],
Expand Down
3 changes: 3 additions & 0 deletions x-pack/packages/security/ui_components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/security-ui-components

Contains stateless components for RBAC administration within Kibana.
13 changes: 13 additions & 0 deletions x-pack/packages/security/ui_components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

export {
FeatureTable as KibanaPrivilegeTable,
FeatureTableCell,
} from './src/kibana_privilege_table';
export { PrivilegeFormCalculator } from './src/privilege_form_calculator';
export * as constants from './src/constants';
15 changes: 15 additions & 0 deletions x-pack/packages/security/ui_components/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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.
*/

module.exports = {
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/packages/security/ui_components',
coverageReporters: ['text', 'html'],
collectCoverageFrom: ['<rootDir>/x-pack/packages/security/ui_components/**/*.{ts,tsx}'],
preset: '@kbn/test',
rootDir: '../../../..',
roots: ['<rootDir>/x-pack/packages/security/ui_components'],
};
5 changes: 5 additions & 0 deletions x-pack/packages/security/ui_components/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/security-ui-components",
"owner": "@elastic/kibana-security"
}
6 changes: 6 additions & 0 deletions x-pack/packages/security/ui_components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/security-ui-components",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { findTestSubject, mountWithIntl } from '@kbn/test-jest-helpers';

import { getDisplayedFeaturePrivileges } from './__fixtures__';
import { FeatureTable } from './feature_table';
import type { Role } from '../../../../../../../common';
import type { Role } from '@kbn/security-plugin-types-common';
import { PrivilegeFormCalculator } from '../privilege_form_calculator';

const createRole = (kibana: Role['kibana'] = []): Role => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import type { KibanaPrivileges, SecuredFeature } from '@kbn/security-role-manage
import { ChangeAllPrivilegesControl } from './change_all_privileges';
import { FeatureTableExpandedRow } from './feature_table_expanded_row';
import { NO_PRIVILEGE_VALUE } from '../constants';
import { FeatureTableCell } from '../feature_table_cell';
import { FeatureTableCell } from './components/feature_table_cell';
import type { PrivilegeFormCalculator } from '../privilege_form_calculator';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { findTestSubject, mountWithIntl } from '@kbn/test-jest-helpers';

import { FeatureTableExpandedRow } from './feature_table_expanded_row';
import type { Role } from '../../../../../../../common';
import type { Role } from '@kbn/security-plugin-types-common';
import { PrivilegeFormCalculator } from '../privilege_form_calculator';

const createRole = (kibana: Role['kibana'] = []): Role => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export { FeatureTable } from './feature_table';
export { FeatureTableCell } from './components';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@kbn/security-role-management-model/src/__fixtures__';

import { PrivilegeFormCalculator } from './privilege_form_calculator';
import type { Role } from '../../../../../../../common';
import type { Role } from '@kbn/security-plugin-types-common';

const createRole = (kibana: Role['kibana'] = []): Role => {
return {
Expand Down
18 changes: 18 additions & 0 deletions x-pack/packages/security/ui_components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": ["jest", "node", "react"]
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["target/**/*"],
"kbn_references": [
"@kbn/core",
"@kbn/i18n",
"@kbn/i18n-react",
"@kbn/security-plugin-types-common",
"@kbn/test-jest-helpers",
"@kbn/security-role-management-model",
"@kbn/features-plugin",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ export const EditRolePage: FunctionComponent<Props> = ({
<EuiFlexGroup justifyContent="flexEnd" gutterSize="s">
<EuiFlexItem grow={false}>
<EuiButton size="s" href={cloudOrgUrl}>
Manage Members
{i18n.translate('xpack.security.management.roles.manageRoleUsers', {
defaultMessage: 'Manage Members',
})}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import { EuiTableRow } from '@elastic/eui';
import type { ReactWrapper } from 'enzyme';

import { FeatureTableCell } from '@kbn/security-ui-components';
import { findTestSubject } from '@kbn/test-jest-helpers';

import type { Role, RoleKibanaPrivilege } from '../../../../../../../../common';
import { FeatureTableCell } from '../../feature_table_cell';
import { PrivilegeSummaryExpandedRow } from '../privilege_summary_expanded_row';

interface DisplayedFeaturePrivileges {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import {
type PrimaryFeaturePrivilege,
type SecuredFeature,
} from '@kbn/security-role-management-model';
import { FeatureTableCell } from '@kbn/security-ui-components';
import type { Space, SpacesApiUi } from '@kbn/spaces-plugin/public';

import type { EffectiveFeaturePrivileges } from './privilege_summary_calculator';
import { PrivilegeSummaryCalculator } from './privilege_summary_calculator';
import { PrivilegeSummaryExpandedRow } from './privilege_summary_expanded_row';
import { SpaceColumnHeader } from './space_column_header';
import { ALL_SPACES_ID } from '../../../../../../../common/constants';
import { FeatureTableCell } from '../feature_table_cell';

export interface PrivilegeSummaryTableProps {
role: Role;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiSelect } from '@elastic/eui';
import type { ChangeEvent } from 'react';
import React, { Component } from 'react';

import { NO_PRIVILEGE_VALUE } from '../constants';
import { constants } from '@kbn/security-ui-components';

interface Props {
['data-test-subj']: string;
Expand All @@ -27,10 +27,10 @@ export class PrivilegeSelector extends Component<Props, {}> {
public render() {
const { availablePrivileges, value, disabled, allowNone, compressed } = this.props;

const options = [];
const options: Array<{ value: string; text: string }> = [];

if (allowNone) {
options.push({ value: NO_PRIVILEGE_VALUE, text: 'none' });
options.push({ value: constants.NO_PRIVILEGE_VALUE, text: 'none' });
}

options.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ import {
import React, { Component, Fragment } from 'react';

import { FormattedMessage } from '@kbn/i18n-react';
import type { Role, RoleKibanaPrivilege } from '@kbn/security-plugin-types-common';
import {
isGlobalPrivilegeDefinition,
type KibanaPrivileges,
} from '@kbn/security-role-management-model';
import {
constants,
KibanaPrivilegeTable,
PrivilegeFormCalculator,
} from '@kbn/security-ui-components';

import { UnsupportedSpacePrivilegesWarning } from './unsupported_space_privileges_warning';
import type { Role, RoleKibanaPrivilege } from '../../../../../../../common';
import { copyRole } from '../../../../../../../common/model';
import { CUSTOM_PRIVILEGE_VALUE, NO_PRIVILEGE_VALUE } from '../constants';
import { FeatureTable } from '../feature_table';
import { PrivilegeFormCalculator } from '../privilege_form_calculator';

interface Props {
role: Role;
Expand Down Expand Up @@ -98,7 +100,7 @@ export class SimplePrivilegeSection extends Component<Props, State> {
onChange={this.onKibanaPrivilegeChange}
options={[
{
value: NO_PRIVILEGE_VALUE,
value: constants.NO_PRIVILEGE_VALUE,
inputDisplay: (
<FormattedMessage
id="xpack.security.management.editRole.simplePrivilegeForm.noPrivilegeInput"
Expand Down Expand Up @@ -179,7 +181,7 @@ export class SimplePrivilegeSection extends Component<Props, State> {
),
},
{
value: CUSTOM_PRIVILEGE_VALUE,
value: constants.CUSTOM_PRIVILEGE_VALUE,
inputDisplay: (
<FormattedMessage
id="xpack.security.management.editRole.simplePrivilegeForm.customPrivilegeInput"
Expand Down Expand Up @@ -213,7 +215,7 @@ export class SimplePrivilegeSection extends Component<Props, State> {
</EuiFormRow>
{this.state.isCustomizingGlobalPrivilege && (
<EuiFormRow fullWidth>
<FeatureTable
<KibanaPrivilegeTable
role={this.props.role}
kibanaPrivileges={this.props.kibanaPrivileges}
privilegeCalculator={
Expand All @@ -239,25 +241,25 @@ export class SimplePrivilegeSection extends Component<Props, State> {

public getDisplayedBasePrivilege = () => {
if (this.state.isCustomizingGlobalPrivilege) {
return CUSTOM_PRIVILEGE_VALUE;
return constants.CUSTOM_PRIVILEGE_VALUE;
}

const { role } = this.props;

const form = this.locateGlobalPrivilege(role);

return form && form.base.length > 0 ? form.base[0] : NO_PRIVILEGE_VALUE;
return form && form.base.length > 0 ? form.base[0] : constants.NO_PRIVILEGE_VALUE;
};

public onKibanaPrivilegeChange = (privilege: string) => {
const role = copyRole(this.props.role);

const form = this.locateGlobalPrivilege(role) || this.createGlobalPrivilegeEntry(role);

if (privilege === NO_PRIVILEGE_VALUE) {
if (privilege === constants.NO_PRIVILEGE_VALUE) {
// Remove global entry if no privilege value
role.kibana = role.kibana.filter((entry) => !isGlobalPrivilegeDefinition(entry));
} else if (privilege === CUSTOM_PRIVILEGE_VALUE) {
} else if (privilege === constants.CUSTOM_PRIVILEGE_VALUE) {
// Remove base privilege if customizing feature privileges
form.base = [];
} else {
Expand All @@ -267,7 +269,7 @@ export class SimplePrivilegeSection extends Component<Props, State> {

this.props.onChange(role);
this.setState({
isCustomizingGlobalPrivilege: privilege === CUSTOM_PRIVILEGE_VALUE,
isCustomizingGlobalPrivilege: privilege === constants.CUSTOM_PRIVILEGE_VALUE,
globalPrivsIndex: role.kibana.indexOf(form),
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import _ from 'lodash';
import type { FC, ReactNode } from 'react';
import React from 'react';

import { NO_PRIVILEGE_VALUE } from '../constants';
import { constants } from '@kbn/security-ui-components';

interface Props extends PropsOf<typeof EuiText> {
privilege: string | string[] | undefined;
Expand Down Expand Up @@ -40,7 +40,8 @@ function getDisplayValue(privilege: string | string[] | undefined) {
let displayValue: string | ReactNode;

const isPrivilegeMissing =
privileges.length === 0 || (privileges.length === 1 && privileges.includes(NO_PRIVILEGE_VALUE));
privileges.length === 0 ||
(privileges.length === 1 && privileges.includes(constants.NO_PRIVILEGE_VALUE));

if (isPrivilegeMissing) {
displayValue = <EuiIcon color="subdued" type={'minusInCircle'} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
createKibanaPrivileges,
kibanaFeatures,
} from '@kbn/security-role-management-model/src/__fixtures__';
import { KibanaPrivilegeTable as FeatureTable } from '@kbn/security-ui-components';
import { getDisplayedFeaturePrivileges } from '@kbn/security-ui-components/src/kibana_privilege_table/__fixtures__';
import type { Space } from '@kbn/spaces-plugin/public';
import { findTestSubject, mountWithIntl } from '@kbn/test-jest-helpers';

import { PrivilegeSpaceForm } from './privilege_space_form';
import { SpaceSelector } from './space_selector';
import type { Role } from '../../../../../../../common';
import { FeatureTable } from '../feature_table';
import { getDisplayedFeaturePrivileges } from '../feature_table/__fixtures__';

const createRole = (kibana: Role['kibana'] = []): Role => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ import React, { Component, Fragment } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import type { KibanaPrivileges } from '@kbn/security-role-management-model';
import {
KibanaPrivilegeTable,
PrivilegeFormCalculator,
constants as UI_CONSTANTS,
} from '@kbn/security-ui-components';
import type { Space } from '@kbn/spaces-plugin/public';

import { SpaceSelector } from './space_selector';
import type { FeaturesPrivileges, Role } from '../../../../../../../common';
import { ALL_SPACES_ID } from '../../../../../../../common/constants';
import { copyRole } from '../../../../../../../common/model';
import { CUSTOM_PRIVILEGE_VALUE } from '../constants';
import { FeatureTable } from '../feature_table';
import { PrivilegeFormCalculator } from '../privilege_form_calculator';

interface Props {
role: Role;
Expand Down Expand Up @@ -254,7 +256,7 @@ export class PrivilegeSpaceForm extends Component<Props, State> {

<EuiSpacer size="l" />

<FeatureTable
<KibanaPrivilegeTable
role={this.state.role}
privilegeCalculator={this.state.privilegeCalculator}
onChange={this.onFeaturePrivilegesChange}
Expand Down Expand Up @@ -447,7 +449,7 @@ export class PrivilegeSpaceForm extends Component<Props, State> {

let isCustomizingFeaturePrivileges = false;

if (privilegeName === CUSTOM_PRIVILEGE_VALUE) {
if (privilegeName === UI_CONSTANTS.CUSTOM_PRIVILEGE_VALUE) {
form.base = [];
isCustomizingFeaturePrivileges = true;
} else {
Expand All @@ -456,7 +458,8 @@ export class PrivilegeSpaceForm extends Component<Props, State> {
}

this.setState({
selectedBasePrivilege: privilegeName === CUSTOM_PRIVILEGE_VALUE ? [] : [privilegeName],
selectedBasePrivilege:
privilegeName === UI_CONSTANTS.CUSTOM_PRIVILEGE_VALUE ? [] : [privilegeName],
role,
isCustomizingFeaturePrivileges,
privilegeCalculator: new PrivilegeFormCalculator(this.props.kibanaPrivileges, role),
Expand Down Expand Up @@ -507,7 +510,7 @@ export class PrivilegeSpaceForm extends Component<Props, State> {
return `basePrivilege_${basePrivilege.id}`;
}

return `basePrivilege_${CUSTOM_PRIVILEGE_VALUE}`;
return `basePrivilege_${UI_CONSTANTS.CUSTOM_PRIVILEGE_VALUE}`;
};

private onFeaturePrivilegesChange = (featureId: string, privileges: string[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import React from 'react';
import { KibanaFeature } from '@kbn/features-plugin/public';
import type { Role, RoleKibanaPrivilege } from '@kbn/security-plugin-types-common';
import { createKibanaPrivileges } from '@kbn/security-role-management-model/src/__fixtures__';
import { PrivilegeFormCalculator } from '@kbn/security-ui-components';
import { findTestSubject, mountWithIntl } from '@kbn/test-jest-helpers';

import { PrivilegeDisplay } from './privilege_display';
import { PrivilegeSpaceTable } from './privilege_space_table';
import { PrivilegeFormCalculator } from '../privilege_form_calculator';

interface TableRow {
spaces: string[];
Expand Down
Loading