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

Feature Controls - Infrastructure and Logging #31843

Merged
merged 43 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a500ded
hide infra/logs apps if disabled via UICapabilities
legrego Feb 11, 2019
2df2771
adds tests
legrego Feb 11, 2019
b1b7c41
adds UICapability tests for infra and log apps
legrego Feb 11, 2019
fe63b39
update expected privilege/action mapping
legrego Feb 11, 2019
bbfc833
adds feature controls security tests for infraHome
legrego Feb 12, 2019
e44b0eb
adds infra spaces feature control tests
legrego Feb 12, 2019
f5db5c8
remove debug code
legrego Feb 12, 2019
4794cbf
Merge branch 'granular-app-privileges' into fc/enable-infra
legrego Feb 14, 2019
a1c3345
a sample readonly implementation, ignoring 'logs' privileges
legrego Feb 15, 2019
0382915
Merge branch 'granular-app-privileges' into fc/enable-infra
legrego Feb 15, 2019
0cb1bf0
ts fixes
legrego Feb 15, 2019
dc61811
fix capability expectations
legrego Feb 15, 2019
7981ad4
Removing RequiresUICapability component, since there are no usages
kobelb Feb 21, 2019
d3bd237
Driving the source configuration seperately for logs/infrastructure
kobelb Feb 21, 2019
19bfb58
Adding infrastructure feature controls security functional tests
kobelb Feb 22, 2019
8eab19a
Adding spaces infrastructure tests
kobelb Feb 22, 2019
b20b6b6
Adding logs functional tests
kobelb Feb 22, 2019
d9dcccf
Reworking the ui capability tests to be more consistent
kobelb Feb 22, 2019
daea6a3
Fixing privileges API
kobelb Feb 22, 2019
f53271c
Forcing logout
kobelb Feb 22, 2019
7b5be17
Merge remote-tracking branch 'upstream/granular-app-privileges' into …
kobelb Feb 25, 2019
1b3b418
Fixing comma issue introduced by merge
kobelb Feb 25, 2019
a51083d
Fix merge conflicts and loading/unloading esarchives more consistently
kobelb Feb 25, 2019
fc1ea1a
Removing unnecessary !!
kobelb Feb 27, 2019
11e0082
Merge remote-tracking branch 'upstream/granular-app-privileges' into …
kobelb Feb 28, 2019
c213bc3
Fixing saved object management tests
kobelb Mar 1, 2019
6202363
Fixing more tests
kobelb Mar 1, 2019
4776f1f
Using the new context APIs
kobelb Mar 1, 2019
ab1e930
Revert "Using the new context APIs"
kobelb Mar 1, 2019
28612d0
Adding future version of ui capabilities react provider
kobelb Mar 1, 2019
d4d8538
Merge remote-tracking branch 'upstream/granular-app-privileges' into …
kobelb Mar 1, 2019
7bdc00d
Merge remote-tracking branch 'upstream/granular-app-privileges' into …
kobelb Mar 4, 2019
a8d9c41
Switching the order of the HOC's for infra and making the future the
kobelb Mar 4, 2019
35829c1
Applying Felix's PR feedback
kobelb Mar 4, 2019
2cd4a50
Protecting Infra's GraphQL APIs
kobelb Mar 5, 2019
8e49558
Updating privileges list
kobelb Mar 5, 2019
20cd128
Using the introspection query
kobelb Mar 7, 2019
c41d5b3
No longer using apollo context library, rephrasing test descriptions
kobelb Mar 7, 2019
14510b2
Merge remote-tracking branch 'upstream/granular-app-privileges' into …
kobelb Mar 7, 2019
9206566
Fixing issue introduced by merge conflict, I forgot a }
kobelb Mar 7, 2019
b4b987f
Merge remote-tracking branch 'upstream/granular-app-privileges' into …
kobelb Mar 7, 2019
6371bb6
Putting back missplaced data test subj
kobelb Mar 7, 2019
a071707
Merge remote-tracking branch 'upstream/granular-app-privileges' into …
kobelb Mar 9, 2019
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
22 changes: 22 additions & 0 deletions src/legacy/ui/public/capabilities/react/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { UICapabilitiesProvider } from './ui_capabilities_provider';
export { injectUICapabilities } from './inject_ui_capabilities';
export { UICapabilities } from '../ui_capabilities';
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

jest.mock('ui/chrome', () => ({
getInjected(key: string) {
if (key === 'uiCapabilities') {
return {
uiCapability1: true,
uiCapability2: {
nestedProp: 'nestedValue',
},
};
}
},
}));

import { mount } from 'enzyme';
import React from 'react';
import { UICapabilities } from '..';
import { injectUICapabilities } from './inject_ui_capabilities';
import { UICapabilitiesProvider } from './ui_capabilities_provider';

describe('injectUICapabilities', () => {
it('provides UICapabilities to SFCs', () => {
interface SFCProps {
uiCapabilities: UICapabilities;
}

const MySFC = injectUICapabilities(({ uiCapabilities }: SFCProps) => {
return <span>{uiCapabilities.uiCapability2.nestedProp}</span>;
});

const wrapper = mount(
<UICapabilitiesProvider>
<MySFC />
</UICapabilitiesProvider>
);

expect(wrapper).toMatchInlineSnapshot(`
<UICapabilitiesProvider>
<InjectUICapabilities(Component)>
<Component
uiCapabilities={
Object {
"uiCapability1": true,
"uiCapability2": Object {
"nestedProp": "nestedValue",
},
}
}
>
<span>
nestedValue
</span>
</Component>
</InjectUICapabilities(Component)>
</UICapabilitiesProvider>
`);
});

it('provides UICapabilities to class components', () => {
interface ClassProps {
uiCapabilities: UICapabilities;
}

class MyClassComponent extends React.Component<ClassProps, {}> {
public render() {
return <span>{this.props.uiCapabilities.uiCapability2.nestedProp}</span>;
}
}

const WrappedComponent = injectUICapabilities(MyClassComponent);

const wrapper = mount(
<UICapabilitiesProvider>
<WrappedComponent />
</UICapabilitiesProvider>
);

expect(wrapper).toMatchInlineSnapshot(`
<UICapabilitiesProvider>
<InjectUICapabilities(MyClassComponent)>
<MyClassComponent
uiCapabilities={
Object {
"uiCapability1": true,
"uiCapability2": Object {
"nestedProp": "nestedValue",
},
}
}
>
<span>
nestedValue
</span>
</MyClassComponent>
</InjectUICapabilities(MyClassComponent)>
</UICapabilitiesProvider>
`);
});
});
53 changes: 53 additions & 0 deletions src/legacy/ui/public/capabilities/react/inject_ui_capabilities.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { Component, ComponentClass, ComponentType } from 'react';
import { UICapabilities } from '../ui_capabilities';
import { UICapabilitiesContext } from './ui_capabilities_context';

function getDisplayName(component: ComponentType<any>) {
return component.displayName || component.name || 'Component';
}

interface InjectedProps {
uiCapabilities: UICapabilities;
}

export function injectUICapabilities<P>(
WrappedComponent: ComponentType<P & InjectedProps>
): ComponentClass<Pick<P, Exclude<keyof P, keyof InjectedProps>>> & {
WrappedComponent: ComponentType<P & InjectedProps>;
} {
class InjectUICapabilities extends Component<P, any> {
public static displayName = `InjectUICapabilities(${getDisplayName(WrappedComponent)})`;

public static WrappedComponent: ComponentType<P & InjectedProps> = WrappedComponent;

public static contextType = UICapabilitiesContext;

constructor(props: any, context: any) {
super(props, context);
}

public render() {
return <WrappedComponent {...this.props} {...{ uiCapabilities: this.context }} />;
}
}
return InjectUICapabilities;
}
22 changes: 22 additions & 0 deletions src/legacy/ui/public/capabilities/react/legacy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { UICapabilitiesProvider } from './ui_capabilities_provider';
export { injectUICapabilities } from './inject_ui_capabilities';
export { UICapabilities } from '../../ui_capabilities';
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

jest.mock('ui/chrome', () => ({
getInjected(key: string) {
if (key === 'uiCapabilities') {
return {
uiCapability1: true,
uiCapability2: {
nestedProp: 'nestedValue',
},
};
}
},
}));

import { mount } from 'enzyme';
import React from 'react';
import { UICapabilities } from '..';
import { injectUICapabilities } from './inject_ui_capabilities';
import { UICapabilitiesProvider } from './ui_capabilities_provider';

describe('injectUICapabilities', () => {
it('provides UICapabilities to SFCs', () => {
interface SFCProps {
uiCapabilities: UICapabilities;
}

const MySFC = injectUICapabilities(({ uiCapabilities }: SFCProps) => {
return <span>{uiCapabilities.uiCapability2.nestedProp}</span>;
});

const wrapper = mount(
<UICapabilitiesProvider>
<MySFC />
</UICapabilitiesProvider>
);

expect(wrapper).toMatchInlineSnapshot(`
<UICapabilitiesProvider>
<InjectUICapabilities(Component)>
<Component
uiCapabilities={
Object {
"uiCapability1": true,
"uiCapability2": Object {
"nestedProp": "nestedValue",
},
}
}
>
<span>
nestedValue
</span>
</Component>
</InjectUICapabilities(Component)>
</UICapabilitiesProvider>
`);
});

it('provides UICapabilities to class components', () => {
interface ClassProps {
uiCapabilities: UICapabilities;
}

class MyClassComponent extends React.Component<ClassProps, {}> {
public render() {
return <span>{this.props.uiCapabilities.uiCapability2.nestedProp}</span>;
}
}

const WrappedComponent = injectUICapabilities(MyClassComponent);

const wrapper = mount(
<UICapabilitiesProvider>
<WrappedComponent />
</UICapabilitiesProvider>
);

expect(wrapper).toMatchInlineSnapshot(`
<UICapabilitiesProvider>
<InjectUICapabilities(MyClassComponent)>
<MyClassComponent
uiCapabilities={
Object {
"uiCapability1": true,
"uiCapability2": Object {
"nestedProp": "nestedValue",
},
}
}
>
<span>
nestedValue
</span>
</MyClassComponent>
</InjectUICapabilities(MyClassComponent)>
</UICapabilitiesProvider>
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import PropTypes from 'prop-types';
import React, { Component, ComponentClass, ComponentType } from 'react';
import { UICapabilities } from '../../ui_capabilities';

function getDisplayName(component: ComponentType<any>) {
return component.displayName || component.name || 'Component';
}

interface InjectedProps {
uiCapabilities: UICapabilities;
}

export function injectUICapabilities<P>(
WrappedComponent: ComponentType<P & InjectedProps>
): ComponentClass<Pick<P, Exclude<keyof P, keyof InjectedProps>>> & {
WrappedComponent: ComponentType<P & InjectedProps>;
} {
class InjectUICapabilities extends Component<P, any> {
public static displayName = `InjectUICapabilities(${getDisplayName(WrappedComponent)})`;

public static WrappedComponent: ComponentType<P & InjectedProps> = WrappedComponent;

public static contextTypes = {
uiCapabilities: PropTypes.object.isRequired,
};

constructor(props: any, context: any) {
super(props, context);
}

public render() {
return (
<WrappedComponent {...this.props} {...{ uiCapabilities: this.context.uiCapabilities }} />
);
}
}
return InjectUICapabilities;
}
Loading