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: addressing bugs for enterprise search #70538

Merged
merged 8 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class FeatureTable extends Component<Props, State> {
public render() {
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
.sort((feature1, feature2) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('usingPrivileges', () => {
new Feature({
id: 'fooFeature',
name: 'Foo Feature',
app: [],
app: ['fooApp'],
navLinkId: 'foo',
privileges: null,
}),
Expand All @@ -63,6 +63,7 @@ describe('usingPrivileges', () => {
Object.freeze({
navLinks: {
foo: true,
fooApp: true,
bar: true,
},
management: {
Expand All @@ -85,6 +86,7 @@ describe('usingPrivileges', () => {
expect(result).toEqual({
navLinks: {
foo: false,
fooApp: false,
bar: true,
},
management: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function disableUICapabilitiesFactory(
authz: AuthorizationServiceSetup
) {
const featureNavLinkIds = features
.map((feature) => feature.navLinkId)
.flatMap((feature) => [feature.navLinkId, ...feature.app])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: would you mind adding a comment here that explains why we use nav link IDs and app IDs? I took a look at the code before I read PR description I got confused a bit app IDs being a part of featureNavLinkIds 🙂

.filter((navLinkId) => navLinkId != null);

const shouldDisableFeatureUICapability = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const features = ([
id: 'feature_3',
name: 'Feature 3',
navLinkId: 'feature3',
app: [],
app: ['feature3_app'],
catalogue: ['feature3Entry'],
management: {
kibana: ['indices'],
Expand All @@ -67,6 +67,7 @@ const buildCapabilities = () =>
feature1: true,
feature2: true,
feature3: true,
feature3_app: true,
unknownFeature: true,
},
catalogue: {
Expand Down Expand Up @@ -241,6 +242,7 @@ describe('capabilitiesSwitcher', () => {
expectedCapabilities.feature_2.foo = false;

expectedCapabilities.navLinks.feature3 = false;
expectedCapabilities.navLinks.feature3_app = false;
expectedCapabilities.catalogue.feature3Entry = false;
expectedCapabilities.management.kibana.indices = false;
expectedCapabilities.feature_3.bar = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ function toggleDisabledFeatures(
navLinks[feature.navLinkId] = false;
}

feature.app.forEach((app) => {
if (navLinks.hasOwnProperty(app)) {
navLinks[app] = false;
}
});

// Disable associated catalogue entries
const privilegeCatalogueEntries = feature.catalogue || [];
privilegeCatalogueEntries.forEach((catalogueEntryId) => {
Expand Down