Skip to content

Commit b9c5bbd

Browse files
[7.x] Feature Controls: addressing bugs for enterprise search (#70538) (#70808)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent d7c68b9 commit b9c5bbd

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/feature_table.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,4 +846,43 @@ describe('FeatureTable', () => {
846846
},
847847
});
848848
});
849+
850+
it('does not render features which lack privileges', () => {
851+
const role = createRole([
852+
{
853+
spaces: ['foo'],
854+
base: [],
855+
feature: {},
856+
},
857+
]);
858+
859+
const featureWithoutPrivileges = createFeature({
860+
id: 'no_privs',
861+
name: 'No Privileges Feature',
862+
privileges: null,
863+
});
864+
865+
const { displayedPrivileges } = setup({
866+
role,
867+
features: [...kibanaFeatures, featureWithoutPrivileges],
868+
privilegeIndex: 0,
869+
calculateDisplayedPrivileges: true,
870+
canCustomizeSubFeaturePrivileges: false,
871+
});
872+
873+
expect(displayedPrivileges).toEqual({
874+
excluded_from_base: {
875+
primaryFeaturePrivilege: 'none',
876+
},
877+
no_sub_features: {
878+
primaryFeaturePrivilege: 'none',
879+
},
880+
with_excluded_sub_features: {
881+
primaryFeaturePrivilege: 'none',
882+
},
883+
with_sub_features: {
884+
primaryFeaturePrivilege: 'none',
885+
},
886+
});
887+
});
849888
});

x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/feature_table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ export class FeatureTable extends Component<Props, State> {
6363
public render() {
6464
const { role, kibanaPrivileges } = this.props;
6565

66-
const featurePrivileges = kibanaPrivileges.getSecuredFeatures();
66+
const featurePrivileges = kibanaPrivileges
67+
.getSecuredFeatures()
68+
.filter((feature) => feature.privileges != null || feature.reserved != null);
6769

6870
const items: TableRow[] = featurePrivileges
6971
.sort((feature1, feature2) => {

x-pack/plugins/security/server/authorization/disable_ui_capabilities.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('usingPrivileges', () => {
5050
new Feature({
5151
id: 'fooFeature',
5252
name: 'Foo Feature',
53-
app: [],
53+
app: ['fooApp'],
5454
navLinkId: 'foo',
5555
privileges: null,
5656
}),
@@ -63,6 +63,7 @@ describe('usingPrivileges', () => {
6363
Object.freeze({
6464
navLinks: {
6565
foo: true,
66+
fooApp: true,
6667
bar: true,
6768
},
6869
management: {
@@ -85,6 +86,7 @@ describe('usingPrivileges', () => {
8586
expect(result).toEqual({
8687
navLinks: {
8788
foo: false,
89+
fooApp: false,
8890
bar: true,
8991
},
9092
management: {

x-pack/plugins/security/server/authorization/disable_ui_capabilities.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ export function disableUICapabilitiesFactory(
1818
logger: Logger,
1919
authz: AuthorizationServiceSetup
2020
) {
21+
// nav links are sourced from two places:
22+
// 1) The `navLinkId` property. This is deprecated and will be removed (https://github.com/elastic/kibana/issues/66217)
23+
// 2) The apps property. The Kibana Platform associates nav links to the app which registers it, in a 1:1 relationship.
24+
// This behavior is replacing the `navLinkId` property above.
2125
const featureNavLinkIds = features
22-
.map((feature) => feature.navLinkId)
26+
.flatMap((feature) => [feature.navLinkId, ...feature.app])
2327
.filter((navLinkId) => navLinkId != null);
2428

2529
const shouldDisableFeatureUICapability = (

x-pack/plugins/spaces/server/capabilities/capabilities_switcher.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const features = ([
4343
id: 'feature_3',
4444
name: 'Feature 3',
4545
navLinkId: 'feature3',
46-
app: [],
46+
app: ['feature3_app'],
4747
catalogue: ['feature3Entry'],
4848
management: {
4949
kibana: ['indices'],
@@ -67,6 +67,7 @@ const buildCapabilities = () =>
6767
feature1: true,
6868
feature2: true,
6969
feature3: true,
70+
feature3_app: true,
7071
unknownFeature: true,
7172
},
7273
catalogue: {
@@ -241,6 +242,7 @@ describe('capabilitiesSwitcher', () => {
241242
expectedCapabilities.feature_2.foo = false;
242243

243244
expectedCapabilities.navLinks.feature3 = false;
245+
expectedCapabilities.navLinks.feature3_app = false;
244246
expectedCapabilities.catalogue.feature3Entry = false;
245247
expectedCapabilities.management.kibana.indices = false;
246248
expectedCapabilities.feature_3.bar = false;

x-pack/plugins/spaces/server/capabilities/capabilities_switcher.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ function toggleDisabledFeatures(
6868
navLinks[feature.navLinkId] = false;
6969
}
7070

71+
feature.app.forEach((app) => {
72+
if (navLinks.hasOwnProperty(app)) {
73+
navLinks[app] = false;
74+
}
75+
});
76+
7177
// Disable associated catalogue entries
7278
const privilegeCatalogueEntries = feature.catalogue || [];
7379
privilegeCatalogueEntries.forEach((catalogueEntryId) => {

0 commit comments

Comments
 (0)