Feature Controls: addressing bugs for enterprise search (#70538)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
e298317586
commit
0673dbde1f
6 changed files with 59 additions and 4 deletions
|
@ -846,4 +846,43 @@ describe('FeatureTable', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not render features which lack privileges', () => {
|
||||||
|
const role = createRole([
|
||||||
|
{
|
||||||
|
spaces: ['foo'],
|
||||||
|
base: [],
|
||||||
|
feature: {},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const featureWithoutPrivileges = createFeature({
|
||||||
|
id: 'no_privs',
|
||||||
|
name: 'No Privileges Feature',
|
||||||
|
privileges: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { displayedPrivileges } = setup({
|
||||||
|
role,
|
||||||
|
features: [...kibanaFeatures, featureWithoutPrivileges],
|
||||||
|
privilegeIndex: 0,
|
||||||
|
calculateDisplayedPrivileges: true,
|
||||||
|
canCustomizeSubFeaturePrivileges: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(displayedPrivileges).toEqual({
|
||||||
|
excluded_from_base: {
|
||||||
|
primaryFeaturePrivilege: 'none',
|
||||||
|
},
|
||||||
|
no_sub_features: {
|
||||||
|
primaryFeaturePrivilege: 'none',
|
||||||
|
},
|
||||||
|
with_excluded_sub_features: {
|
||||||
|
primaryFeaturePrivilege: 'none',
|
||||||
|
},
|
||||||
|
with_sub_features: {
|
||||||
|
primaryFeaturePrivilege: 'none',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -63,7 +63,9 @@ export class FeatureTable extends Component<Props, State> {
|
||||||
public render() {
|
public render() {
|
||||||
const { role, kibanaPrivileges } = this.props;
|
const { role, kibanaPrivileges } = this.props;
|
||||||
|
|
||||||
const featurePrivileges = kibanaPrivileges.getSecuredFeatures();
|
const featurePrivileges = kibanaPrivileges
|
||||||
|
.getSecuredFeatures()
|
||||||
|
.filter((feature) => feature.privileges != null || feature.reserved != null);
|
||||||
|
|
||||||
const items: TableRow[] = featurePrivileges
|
const items: TableRow[] = featurePrivileges
|
||||||
.sort((feature1, feature2) => {
|
.sort((feature1, feature2) => {
|
||||||
|
|
|
@ -50,7 +50,7 @@ describe('usingPrivileges', () => {
|
||||||
new Feature({
|
new Feature({
|
||||||
id: 'fooFeature',
|
id: 'fooFeature',
|
||||||
name: 'Foo Feature',
|
name: 'Foo Feature',
|
||||||
app: [],
|
app: ['fooApp'],
|
||||||
navLinkId: 'foo',
|
navLinkId: 'foo',
|
||||||
privileges: null,
|
privileges: null,
|
||||||
}),
|
}),
|
||||||
|
@ -63,6 +63,7 @@ describe('usingPrivileges', () => {
|
||||||
Object.freeze({
|
Object.freeze({
|
||||||
navLinks: {
|
navLinks: {
|
||||||
foo: true,
|
foo: true,
|
||||||
|
fooApp: true,
|
||||||
bar: true,
|
bar: true,
|
||||||
},
|
},
|
||||||
management: {
|
management: {
|
||||||
|
@ -85,6 +86,7 @@ describe('usingPrivileges', () => {
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
navLinks: {
|
navLinks: {
|
||||||
foo: false,
|
foo: false,
|
||||||
|
fooApp: false,
|
||||||
bar: true,
|
bar: true,
|
||||||
},
|
},
|
||||||
management: {
|
management: {
|
||||||
|
|
|
@ -18,8 +18,12 @@ export function disableUICapabilitiesFactory(
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
authz: AuthorizationServiceSetup
|
authz: AuthorizationServiceSetup
|
||||||
) {
|
) {
|
||||||
|
// nav links are sourced from two places:
|
||||||
|
// 1) The `navLinkId` property. This is deprecated and will be removed (https://github.com/elastic/kibana/issues/66217)
|
||||||
|
// 2) The apps property. The Kibana Platform associates nav links to the app which registers it, in a 1:1 relationship.
|
||||||
|
// This behavior is replacing the `navLinkId` property above.
|
||||||
const featureNavLinkIds = features
|
const featureNavLinkIds = features
|
||||||
.map((feature) => feature.navLinkId)
|
.flatMap((feature) => [feature.navLinkId, ...feature.app])
|
||||||
.filter((navLinkId) => navLinkId != null);
|
.filter((navLinkId) => navLinkId != null);
|
||||||
|
|
||||||
const shouldDisableFeatureUICapability = (
|
const shouldDisableFeatureUICapability = (
|
||||||
|
|
|
@ -43,7 +43,7 @@ const features = ([
|
||||||
id: 'feature_3',
|
id: 'feature_3',
|
||||||
name: 'Feature 3',
|
name: 'Feature 3',
|
||||||
navLinkId: 'feature3',
|
navLinkId: 'feature3',
|
||||||
app: [],
|
app: ['feature3_app'],
|
||||||
catalogue: ['feature3Entry'],
|
catalogue: ['feature3Entry'],
|
||||||
management: {
|
management: {
|
||||||
kibana: ['indices'],
|
kibana: ['indices'],
|
||||||
|
@ -67,6 +67,7 @@ const buildCapabilities = () =>
|
||||||
feature1: true,
|
feature1: true,
|
||||||
feature2: true,
|
feature2: true,
|
||||||
feature3: true,
|
feature3: true,
|
||||||
|
feature3_app: true,
|
||||||
unknownFeature: true,
|
unknownFeature: true,
|
||||||
},
|
},
|
||||||
catalogue: {
|
catalogue: {
|
||||||
|
@ -241,6 +242,7 @@ describe('capabilitiesSwitcher', () => {
|
||||||
expectedCapabilities.feature_2.foo = false;
|
expectedCapabilities.feature_2.foo = false;
|
||||||
|
|
||||||
expectedCapabilities.navLinks.feature3 = false;
|
expectedCapabilities.navLinks.feature3 = false;
|
||||||
|
expectedCapabilities.navLinks.feature3_app = false;
|
||||||
expectedCapabilities.catalogue.feature3Entry = false;
|
expectedCapabilities.catalogue.feature3Entry = false;
|
||||||
expectedCapabilities.management.kibana.indices = false;
|
expectedCapabilities.management.kibana.indices = false;
|
||||||
expectedCapabilities.feature_3.bar = false;
|
expectedCapabilities.feature_3.bar = false;
|
||||||
|
|
|
@ -68,6 +68,12 @@ function toggleDisabledFeatures(
|
||||||
navLinks[feature.navLinkId] = false;
|
navLinks[feature.navLinkId] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
feature.app.forEach((app) => {
|
||||||
|
if (navLinks.hasOwnProperty(app)) {
|
||||||
|
navLinks[app] = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Disable associated catalogue entries
|
// Disable associated catalogue entries
|
||||||
const privilegeCatalogueEntries = feature.catalogue || [];
|
const privilegeCatalogueEntries = feature.catalogue || [];
|
||||||
privilegeCatalogueEntries.forEach((catalogueEntryId) => {
|
privilegeCatalogueEntries.forEach((catalogueEntryId) => {
|
||||||
|
|
Loading…
Reference in a new issue