diff --git a/src/core_plugins/kibana/public/discover/discover_config.js b/src/core_plugins/kibana/public/discover/discover_config.js deleted file mode 100644 index d98a3093704817..00000000000000 --- a/src/core_plugins/kibana/public/discover/discover_config.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 { uiModules } from 'ui/modules'; - -uiModules.get('kibana') - .provider('discoverConfig', () => { - return { - $get() { - return { - getHideWriteControls() { - return false; - } - }; - } - }; - }); diff --git a/src/core_plugins/kibana/public/discover/index.js b/src/core_plugins/kibana/public/discover/index.js index 45d62fed5a47ac..5b23bbd4c01c6f 100644 --- a/src/core_plugins/kibana/public/discover/index.js +++ b/src/core_plugins/kibana/public/discover/index.js @@ -17,7 +17,6 @@ * under the License. */ -import './discover_config'; import './saved_searches/saved_searches'; import './directives'; import 'ui/collapsible_sidebar'; diff --git a/src/ui/public/chrome/api/config.js b/src/ui/public/chrome/api/config.js deleted file mode 100644 index fe12384c58a52c..00000000000000 --- a/src/ui/public/chrome/api/config.js +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 { uiModules } from '../../modules'; - -export function initConfig() { - uiModules.get('kibana') - .provider('chromeConfig', () => { - return { - $get() { - return { - shouldHideNavLink() { - return false; - } - }; - } - }; - }); -} diff --git a/src/ui/public/chrome/chrome.js b/src/ui/public/chrome/chrome.js index d17155fe473d3c..7eba9510768036 100644 --- a/src/ui/public/chrome/chrome.js +++ b/src/ui/public/chrome/chrome.js @@ -38,7 +38,6 @@ import { initChromeNavApi } from './api/nav'; import { initBreadcrumbsApi } from './api/breadcrumbs'; import templateApi from './api/template'; import { initChromeThemeApi } from './api/theme'; -import { initConfig } from './api/config'; import { initChromeXsrfApi } from './api/xsrf'; import { initUiSettingsApi } from './api/ui_settings'; import { initLoadingCountApi } from './api/loading_count'; @@ -62,7 +61,6 @@ const internals = _.defaults( } ); -initConfig(); initUiSettingsApi(chrome); initSavedObjectClient(chrome); appsApi(chrome, internals); diff --git a/x-pack/plugins/security/index.js b/x-pack/plugins/security/index.js index fba44d136fa74c..c4a7b9080fc10b 100644 --- a/x-pack/plugins/security/index.js +++ b/x-pack/plugins/security/index.js @@ -24,8 +24,6 @@ import { createAuthorizationService, registerPrivilegesWithCluster } from './ser import { watchStatusAndLicenseToInitialize } from '../../server/lib/watch_status_and_license_to_initialize'; import { SecureSavedObjectsClientWrapper } from './server/lib/saved_objects_client/secure_saved_objects_client_wrapper'; import { deepFreeze } from './server/lib/deep_freeze'; -import { capabilityDecorator } from './server/lib/capability_decorator'; -import { registerUserProfileCapabilityDecorator } from '../xpack_main/server/lib/user_profile'; export const security = (kibana) => new kibana.Plugin({ id: 'security', @@ -129,8 +127,6 @@ export const security = (kibana) => new kibana.Plugin({ } }); - registerUserProfileCapabilityDecorator(Number.MIN_SAFE_INTEGER, capabilityDecorator); - const auditLogger = new SecurityAuditLogger(server.config(), new AuditLogger(server, 'security')); savedObjects.setScopedSavedObjectsClientFactory(({ diff --git a/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/kibana_privileges.test.tsx b/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/kibana_privileges.test.tsx index 2a7a1d3e00f4bc..27dfc263e57326 100644 --- a/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/kibana_privileges.test.tsx +++ b/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/kibana_privileges.test.tsx @@ -7,7 +7,6 @@ import { shallow } from 'enzyme'; import React from 'react'; import { KibanaPrivilege } from '../../../../../../../../security/common/model/kibana_privilege'; -import { UserProfile } from '../../../../../../../../xpack_main/common/user_profile'; import { RoleValidator } from '../../../lib/validate_role'; import { KibanaPrivileges } from './kibana_privileges'; import { SimplePrivilegeForm } from './simple_privilege_form'; diff --git a/x-pack/plugins/security/public/views/management/edit_role/index.js b/x-pack/plugins/security/public/views/management/edit_role/index.js index 373f1c4dce82ab..9a9f01d16ef1a0 100644 --- a/x-pack/plugins/security/public/views/management/edit_role/index.js +++ b/x-pack/plugins/security/public/views/management/edit_role/index.js @@ -87,7 +87,7 @@ routes.when(`${EDIT_ROLES_PATH}/:name?`, { } }, controllerAs: 'editRole', - controller($injector, $scope, $http, enableSpaceAwarePrivileges, userProfile) { + controller($injector, $scope, $http, enableSpaceAwarePrivileges) { const $route = $injector.get('$route'); const Private = $injector.get('Private'); diff --git a/x-pack/plugins/spaces/public/views/management/page_routes.tsx b/x-pack/plugins/spaces/public/views/management/page_routes.tsx index d76cf1d25aff8e..1263d1beead450 100644 --- a/x-pack/plugins/spaces/public/views/management/page_routes.tsx +++ b/x-pack/plugins/spaces/public/views/management/page_routes.tsx @@ -14,7 +14,6 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; // @ts-ignore import routes from 'ui/routes'; -import { UserProfile } from '../../../../xpack_main/common/user_profile'; import { SpacesManager } from '../../lib/spaces_manager'; import { ManageSpacePage } from './edit_space'; import { SpacesGridPage } from './spaces_grid'; @@ -28,8 +27,7 @@ routes.when('/management/spaces/list', { $http: any, chrome: any, spacesNavState: SpacesNavState, - spaceSelectorURL: string, - userProfile: UserProfile + spaceSelectorURL: string ) { $scope.$$postDigest(() => { const domNode = document.getElementById(reactRootNodeId); @@ -60,8 +58,7 @@ routes.when('/management/spaces/create', { $http: any, chrome: any, spacesNavState: SpacesNavState, - spaceSelectorURL: string, - userProfile: UserProfile + spaceSelectorURL: string ) { $scope.$$postDigest(() => { const domNode = document.getElementById(reactRootNodeId); @@ -98,8 +95,7 @@ routes.when('/management/spaces/edit/:spaceId', { chrome: any, Private: any, spacesNavState: SpacesNavState, - spaceSelectorURL: string, - userProfile: UserProfile + spaceSelectorURL: string ) { $scope.$$postDigest(() => { const domNode = document.getElementById(reactRootNodeId); diff --git a/x-pack/plugins/spaces/public/views/nav_control/nav_control.tsx b/x-pack/plugins/spaces/public/views/nav_control/nav_control.tsx index 0c2dff2cbc71d6..180d9114ee40bf 100644 --- a/x-pack/plugins/spaces/public/views/nav_control/nav_control.tsx +++ b/x-pack/plugins/spaces/public/views/nav_control/nav_control.tsx @@ -21,7 +21,6 @@ import { uiModules } from 'ui/modules'; import { chromeHeaderNavControlsRegistry } from 'ui/registry/chrome_header_nav_controls'; // @ts-ignore import { chromeNavControlsRegistry } from 'ui/registry/chrome_nav_controls'; -import { UserProfile } from '../../../../xpack_main/common/user_profile'; import { Space } from '../../../common/model/space'; import { SpacesGlobalNavButton } from './components/spaces_global_nav_button'; import { SpacesHeaderNavButton } from './components/spaces_header_nav_button'; @@ -94,7 +93,7 @@ module.service('spacesNavState', (activeSpace: any) => { }); chromeHeaderNavControlsRegistry.register( - ($http: any, chrome: any, Private: any, activeSpace: any, userProfile: UserProfile) => ({ + ($http: any, chrome: any, Private: any, activeSpace: any) => ({ name: 'spaces', order: 1000, side: NavControlSide.Left, diff --git a/x-pack/plugins/spaces/public/views/nav_control/nav_control_popover.test.tsx b/x-pack/plugins/spaces/public/views/nav_control/nav_control_popover.test.tsx index 581ff88b26f413..1f743bfba7e5ae 100644 --- a/x-pack/plugins/spaces/public/views/nav_control/nav_control_popover.test.tsx +++ b/x-pack/plugins/spaces/public/views/nav_control/nav_control_popover.test.tsx @@ -6,7 +6,6 @@ import { mount, shallow } from 'enzyme'; import React from 'react'; -import { UserProfile } from '../../../../xpack_main/common/user_profile'; import { SpaceAvatar } from '../../components'; import { SpacesManager } from '../../lib/spaces_manager'; import { SpacesGlobalNavButton } from './components/spaces_global_nav_button'; diff --git a/x-pack/plugins/xpack_main/server/lib/user_profile/index.ts b/x-pack/plugins/spaces/server/lib/toggle_ui_capabilities.test.ts similarity index 60% rename from x-pack/plugins/xpack_main/server/lib/user_profile/index.ts rename to x-pack/plugins/spaces/server/lib/toggle_ui_capabilities.test.ts index 73880d8c0e81ba..a6b3796bf94243 100644 --- a/x-pack/plugins/xpack_main/server/lib/user_profile/index.ts +++ b/x-pack/plugins/spaces/server/lib/toggle_ui_capabilities.test.ts @@ -4,5 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -export { userProfileMixin } from './user_profile_mixin'; -export { registerUserProfileCapabilityDecorator } from './user_profile_capability_registry'; +describe('toggleUiCapabilities', () => { + // TODO: implement tests once spaces have the concept of disabled features + it('should be tested', () => null); +}); diff --git a/x-pack/plugins/xpack_main/common/index.ts b/x-pack/plugins/xpack_main/common/index.ts deleted file mode 100644 index 23c27385776c2b..00000000000000 --- a/x-pack/plugins/xpack_main/common/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export { Capabilities, UserProfile } from './user_profile'; diff --git a/x-pack/plugins/xpack_main/common/user_profile/capabilities.ts b/x-pack/plugins/xpack_main/common/user_profile/capabilities.ts deleted file mode 100644 index c1e893d5a1bc1f..00000000000000 --- a/x-pack/plugins/xpack_main/common/user_profile/capabilities.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export interface Capabilities { - [capability: string]: boolean; -} diff --git a/x-pack/plugins/xpack_main/common/user_profile/index.ts b/x-pack/plugins/xpack_main/common/user_profile/index.ts deleted file mode 100644 index ef5c9c037ebaec..00000000000000 --- a/x-pack/plugins/xpack_main/common/user_profile/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -export { Capabilities } from './capabilities'; -export { UserProfile } from './user_profile'; diff --git a/x-pack/plugins/xpack_main/common/user_profile/user_profile.ts b/x-pack/plugins/xpack_main/common/user_profile/user_profile.ts deleted file mode 100644 index 7d657b0f3ccf91..00000000000000 --- a/x-pack/plugins/xpack_main/common/user_profile/user_profile.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { Capabilities } from './capabilities'; - -export class UserProfile { - private capabilities: Capabilities; - constructor(profileData: Capabilities = {}) { - this.capabilities = { - ...profileData, - }; - } - - public hasCapability(capability: string, defaultValue: boolean = true): boolean { - return capability in this.capabilities ? this.capabilities[capability] : defaultValue; - } - - public canAccessFeature(feature: string, defaultValue: boolean = true): boolean { - return this.hasCapability(`ui:${feature}/read`, defaultValue); - } - - public canReadSavedObject(savedObjectType: string, defaultValue: boolean = true): boolean { - return this.hasCapability(`saved_objects/${savedObjectType}/get`, defaultValue); - } - - public canWriteSavedObject(savedObjectType: string, defaultValue: boolean = true): boolean { - return this.hasCapability(`saved_objects/${savedObjectType}/create`, defaultValue); - } - - public toJSON() { - return { - ...this.capabilities, - }; - } -} diff --git a/x-pack/plugins/xpack_main/index.js b/x-pack/plugins/xpack_main/index.js index 77a837b24dc152..448a08f528b8c6 100644 --- a/x-pack/plugins/xpack_main/index.js +++ b/x-pack/plugins/xpack_main/index.js @@ -22,7 +22,6 @@ import { CONFIG_TELEMETRY_DESC, } from './common/constants'; import { settingsRoute } from './server/routes/api/v1/settings'; -import { userProfileMixin } from './server/lib/user_profile'; import mappings from './mappings.json'; export { callClusterFactory } from './server/lib/call_cluster_factory'; @@ -103,8 +102,6 @@ export const xpackMain = (kibana) => { 'plugins/xpack_main/hacks/check_xpack_info_change', 'plugins/xpack_main/hacks/telemetry_opt_in', 'plugins/xpack_main/hacks/telemetry_trigger', - 'plugins/xpack_main/hacks/user_profile', - 'plugins/xpack_main/hacks/user_profile_config_decorators', ], replaceInjectedVars, __webpackPluginProvider__(webpack) { @@ -125,8 +122,6 @@ export const xpackMain = (kibana) => { setupXPackMain(server); registerOssFeatures(); - userProfileMixin(this.kbnServer, server); - // register routes xpackInfoRoute(server); telemetryRoute(server); diff --git a/x-pack/plugins/xpack_main/public/hacks/user_profile.ts b/x-pack/plugins/xpack_main/public/hacks/user_profile.ts deleted file mode 100644 index 91cdcb419e545b..00000000000000 --- a/x-pack/plugins/xpack_main/public/hacks/user_profile.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import chrome from 'ui/chrome'; -// @ts-ignore -import { uiModules } from 'ui/modules'; -import { UserProfile } from '../../common'; - -uiModules.get('userProfile').provider('userProfile', function userProfileProvider() { - // @ts-ignore - this.$get = () => { - return new UserProfile(chrome.getInjected('userProfileData')); - }; -}); diff --git a/x-pack/plugins/xpack_main/public/hacks/user_profile_config_decorators.js b/x-pack/plugins/xpack_main/public/hacks/user_profile_config_decorators.js deleted file mode 100644 index 851a3a2e189501..00000000000000 --- a/x-pack/plugins/xpack_main/public/hacks/user_profile_config_decorators.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { uiModules } from 'ui/modules'; - -uiModules.get('kibana') - .config(($provide, $injector) => { - if ($injector.has('dashboardConfig')) { - $provide.decorator('dashboardConfig', function ($delegate, userProfile) { - return { - getHideWriteControls() { - if (!userProfile.canWriteSavedObject('dashboard')) { - return true; - } - - return $delegate.getHideWriteControls(); - } - }; - }); - } - - if ($injector.has('discoverConfig')) { - $provide.decorator('discoverConfig', function ($delegate, userProfile) { - return { - getHideWriteControls() { - if (!userProfile.canWriteSavedObject('search')) { - return true; - } - - return $delegate.getHideWriteControls(); - } - }; - }); - } - - if ($injector.has('chromeConfig')) { - $provide.decorator('chromeConfig', function ($delegate, userProfile) { - return { - shouldHideNavLink(navLink) { - if (!userProfile.canAccessFeature(navLink.id)) { - return true; - } - - return $delegate.shouldHideNavLink(navLink); - } - }; - }); - } - }); diff --git a/x-pack/plugins/xpack_main/server/lib/__tests__/replace_injected_vars.js b/x-pack/plugins/xpack_main/server/lib/__tests__/replace_injected_vars.js index 4681e4cf660965..f44e11b876676e 100644 --- a/x-pack/plugins/xpack_main/server/lib/__tests__/replace_injected_vars.js +++ b/x-pack/plugins/xpack_main/server/lib/__tests__/replace_injected_vars.js @@ -19,9 +19,6 @@ const buildRequest = (telemetryOptedIn = null, path = '/app/kibana') => { return { path, - getUserProfile: async () => ({ - toJSON: () => ({}) - }), getSavedObjectsClient: () => { return { get, diff --git a/x-pack/plugins/xpack_main/server/lib/user_profile/priority_collection.ts b/x-pack/plugins/xpack_main/server/lib/user_profile/priority_collection.ts deleted file mode 100644 index 2bb4337f045254..00000000000000 --- a/x-pack/plugins/xpack_main/server/lib/user_profile/priority_collection.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -interface PriorityCollectionEntry { - priority: number; - value: T; -} - -export class PriorityCollection { - private readonly array: Array> = []; - - public add(priority: number, value: T) { - const foundIndex = this.array.findIndex(current => { - if (priority === current.priority) { - throw new Error('Already have entry with this priority'); - } - - return priority < current.priority; - }); - - const spliceIndex = foundIndex === -1 ? this.array.length : foundIndex; - this.array.splice(spliceIndex, 0, { priority, value }); - } - - public toPrioritizedArray(): T[] { - return this.array.map(entry => entry.value); - } -} diff --git a/x-pack/plugins/xpack_main/server/lib/user_profile/user_profile_capability_registry.ts b/x-pack/plugins/xpack_main/server/lib/user_profile/user_profile_capability_registry.ts deleted file mode 100644 index ec07ec66d7d7f8..00000000000000 --- a/x-pack/plugins/xpack_main/server/lib/user_profile/user_profile_capability_registry.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { Capabilities } from 'x-pack/plugins/xpack_main/common'; -import { PriorityCollection } from './priority_collection'; - -export type CapabilityDecorator = ( - server: Record, - request: Record, - capabilities: Capabilities -) => Promise; - -const decorators: PriorityCollection = new PriorityCollection(); - -export function registerUserProfileCapabilityDecorator( - priority: number, - decorator: CapabilityDecorator -) { - decorators.add(priority, decorator); -} - -export async function buildUserCapabilities( - server: Record, - request: Record -): Promise { - const decoratedCapabilities = await executeDecorators(server, request, {}); - - return decoratedCapabilities; -} - -async function executeDecorators( - server: Record, - request: Record, - capabilities: Capabilities -): Promise { - return await asyncForEach(decorators.toPrioritizedArray(), server, request, capabilities); -} - -async function asyncForEach( - array: CapabilityDecorator[], - server: Record, - request: Record, - initialCapabilities: Capabilities -) { - let capabilities = initialCapabilities; - - for (const callback of array) { - capabilities = await callback(server, request, capabilities); - } - - return capabilities; -} diff --git a/x-pack/plugins/xpack_main/server/lib/user_profile/user_profile_mixin.ts b/x-pack/plugins/xpack_main/server/lib/user_profile/user_profile_mixin.ts deleted file mode 100644 index b0aadb201f470d..00000000000000 --- a/x-pack/plugins/xpack_main/server/lib/user_profile/user_profile_mixin.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { UserProfile } from '../../../common'; -import { buildUserCapabilities } from './user_profile_capability_registry'; - -export function userProfileMixin(kbnServer: Record, server: Record) { - const profileCache = new WeakMap(); - - server.decorate('request', 'getUserProfile', async function getUserProfile() { - // @ts-ignore - const request: Record = this; - - if (profileCache.has(request)) { - return profileCache.get(request); - } - - const userCapabilities = await buildUserCapabilities(server, request); - const profile = new UserProfile(userCapabilities); - - profileCache.set(request, profile); - - return profile; - }); -}