From 08d90960d13cd74f3bb2af9951e6c2c867398579 Mon Sep 17 00:00:00 2001 From: Larry Gregory Date: Mon, 30 Jul 2018 11:27:36 -0400 Subject: [PATCH] cleanup and additional testing --- src/core_plugins/kibana/public/index.css | 32 +++ .../__snapshots__/space_selector.test.js.snap | 223 +++++++++--------- .../kibana/space_aware_privilege_form.js | 4 +- .../get_available_privileges.test.js.snap | 3 + .../lib/get_application_privileges.js | 14 -- ...issions.js => get_available_privileges.js} | 2 +- .../lib/get_available_privileges.test.js | 26 ++ .../edit_role/lib/privilege_transforms.js | 43 ---- .../lib/set_application_privileges.js | 49 ---- .../spaces_url_parser.test.js.snap | 3 - 10 files changed, 178 insertions(+), 221 deletions(-) create mode 100644 src/core_plugins/kibana/public/index.css create mode 100644 x-pack/plugins/security/public/views/management/edit_role/lib/__snapshots__/get_available_privileges.test.js.snap rename x-pack/plugins/security/public/views/management/edit_role/lib/{get_available_permissions.js => get_available_privileges.js} (90%) create mode 100644 x-pack/plugins/security/public/views/management/edit_role/lib/get_available_privileges.test.js delete mode 100644 x-pack/plugins/security/public/views/management/edit_role/lib/privilege_transforms.js delete mode 100644 x-pack/plugins/security/public/views/management/edit_role/lib/set_application_privileges.js delete mode 100644 x-pack/plugins/spaces/common/__snapshots__/spaces_url_parser.test.js.snap diff --git a/src/core_plugins/kibana/public/index.css b/src/core_plugins/kibana/public/index.css new file mode 100644 index 0000000000000..25783f8d3e042 --- /dev/null +++ b/src/core_plugins/kibana/public/index.css @@ -0,0 +1,32 @@ +@keyframes euiAnimFadeIn { + 0% { + opacity: 0; } + 100% { + opacity: 1; } } + +@keyframes euiGrow { + 0% { + opacity: 0; } + 1% { + opacity: 0; + transform: scale(0); } + 100% { + opacity: 1; + transform: scale(1); } } + +/** + * Set scroll bar appearance on Chrome. + */ +@keyframes focusRingAnimate { + 0% { + box-shadow: 0 0 0 6px rgba(0, 121, 165, 0); } + 100% { + box-shadow: 0 0 0 2px rgba(0, 121, 165, 0.3); } } + +@keyframes focusRingAnimateLarge { + 0% { + box-shadow: 0 0 0 10px rgba(0, 121, 165, 0); } + 100% { + box-shadow: 0 0 0 4px rgba(0, 121, 165, 0.3); } } + +/*# sourceMappingURL=data:application/json;base64,ewoJInZlcnNpb24iOiAzLAoJImZpbGUiOiAiaW5kZXguY3NzIiwKCSJzb3VyY2VzIjogWwoJCSJpbmRleC5zY3NzIiwKCQkiLi4vLi4vLi4vdWkvcHVibGljL3N0eWxlcy9fc3R5bGluZ19jb25zdGFudHMuc2NzcyIsCgkJIi4uLy4uLy4uLy4uL25vZGVfbW9kdWxlcy9AZWxhc3RpYy9ldWkvc3JjL3RoZW1lcy9rNi9rNl9nbG9iYWxzLnNjc3MiLAoJCSIuLi8uLi8uLi8uLi9ub2RlX21vZHVsZXMvQGVsYXN0aWMvZXVpL3NyYy90aGVtZXMvazYvazZfY29sb3JzX2xpZ2h0LnNjc3MiLAoJCSIuLi8uLi8uLi8uLi9ub2RlX21vZHVsZXMvQGVsYXN0aWMvZXVpL3NyYy9nbG9iYWxfc3R5bGluZy9mdW5jdGlvbnMvX2luZGV4LnNjc3MiLAoJCSIuLi8uLi8uLi8uLi9ub2RlX21vZHVsZXMvQGVsYXN0aWMvZXVpL3NyYy9nbG9iYWxfc3R5bGluZy9mdW5jdGlvbnMvX21hdGguc2NzcyIsCgkJIi4uLy4uLy4uLy4uL25vZGVfbW9kdWxlcy9AZWxhc3RpYy9ldWkvc3JjL2dsb2JhbF9zdHlsaW5nL2Z1bmN0aW9ucy9fY29sb3JzLnNjc3MiLAoJCSIuLi8uLi8uLi8uLi9ub2RlX21vZHVsZXMvQGVsYXN0aWMvZXVpL3NyYy9nbG9iYWxfc3R5bGluZy92YXJpYWJsZXMvX2luZGV4LnNjc3MiLAoJCSIuLi8uLi8uLi8uLi9ub2RlX21vZHVsZXMvQGVsYXN0aWMvZXVpL3NyYy9nbG9iYWxfc3R5bGluZy92YXJpYWJsZXMvX3NpemUuc2NzcyIsCgkJIi4uLy4uLy4uLy4uL25v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U8sRUFBRSxDQUFDO0lBQ1YsU0FBUyxFQUFFLFFBQVE7O0FZQ3ZCOztHQUVHO0FDakJILFVBQVUsQ0FBVixnQkFBVTtFQUNSLEVBQUU7SUFDQSxVQUFVLEVBQUUsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsR0FBRyxDZGhCUCxvQkFBTztFY2tCdkIsSUFBSTtJQUNGLFVBQVUsRUFBRSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FoQkYsR0FBRyxDZEhKLHNCQUFPOztBY3VCekIsVUFBVSxDQUFWLHFCQUFVO0VBQ1IsRUFBRTtJQUNBLFVBQVUsRUFBRSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENkekJSLG9CQUFPO0VjMkJ2QixJQUFJO0lBQ0YsVUFBVSxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQXhCRyxHQUFHLENkSlQsc0JBQU8iCn0= */ \ No newline at end of file diff --git a/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/__snapshots__/space_selector.test.js.snap b/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/__snapshots__/space_selector.test.js.snap index c669ebf7541e7..4cac2df26563b 100644 --- a/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/__snapshots__/space_selector.test.js.snap +++ b/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/__snapshots__/space_selector.test.js.snap @@ -11,6 +11,7 @@ exports[`SpaceSelector renders without crashing 1`] = ` onChange={[Function]} options={Array []} placeholder="choose space(s)" + renderOption={[Function]} selectedOptions={Array []} singleSelection={false} > @@ -58,123 +59,111 @@ exports[`SpaceSelector renders without crashing 1`] = ` className="euiFormControlLayout" >
-

- choose space(s) -

- -
+ choose space(s) +

+ -
-
-
-
- + +
+
+
+
+ -
- - - -
-
+ + + + + + + + diff --git a/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/space_aware_privilege_form.js b/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/space_aware_privilege_form.js index 0a084a88ccd12..dcb5384bdf7b8 100644 --- a/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/space_aware_privilege_form.js +++ b/x-pack/plugins/security/public/views/management/edit_role/components/privileges/kibana/space_aware_privilege_form.js @@ -20,7 +20,7 @@ import { } from '@elastic/eui'; import { isReservedRole } from '../../../../../../lib/role'; import { copyRole } from '../../../lib/copy_role'; -import { getAvailablePermissions } from '../../../lib/get_available_permissions'; +import { getAvailablePrivileges } from '../../../lib/get_available_privileges'; import { PrivilegeSpaceTable } from './privilege_space_table'; import { ALL_RESOURCE } from '../../../../../../../common/constants'; import { getKibanaPrivilegesViewModel } from '../../../lib/get_application_privileges'; @@ -200,7 +200,7 @@ export class SpaceAwarePrivilegeForm extends Component { key={index} availableSpaces={availableSpaces} selectedSpaceIds={selectedSpaceIds} - availablePrivileges={getAvailablePermissions(basePrivilege)} + availablePrivileges={getAvailablePrivileges(basePrivilege)} selectedPrivilege={privilege} onChange={this.onPrivilegeSpacePermissionChange(index)} onDelete={this.onPrivilegeSpacePermissionDelete(index)} diff --git a/x-pack/plugins/security/public/views/management/edit_role/lib/__snapshots__/get_available_privileges.test.js.snap b/x-pack/plugins/security/public/views/management/edit_role/lib/__snapshots__/get_available_privileges.test.js.snap new file mode 100644 index 0000000000000..177ffc1707836 --- /dev/null +++ b/x-pack/plugins/security/public/views/management/edit_role/lib/__snapshots__/get_available_privileges.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`getAvailablePrivileges throws when given an unexpected minimum privilege 1`] = `"Unexpected minimumPrivilege value: idk"`; diff --git a/x-pack/plugins/security/public/views/management/edit_role/lib/get_application_privileges.js b/x-pack/plugins/security/public/views/management/edit_role/lib/get_application_privileges.js index 1b2f857f73c96..a5e9f2d035643 100644 --- a/x-pack/plugins/security/public/views/management/edit_role/lib/get_application_privileges.js +++ b/x-pack/plugins/security/public/views/management/edit_role/lib/get_application_privileges.js @@ -34,17 +34,3 @@ export function getKibanaPrivilegesViewModel(applicationPrivileges, roleKibanaPr return viewModel; } - -export function getKibanaPrivileges(kibanaPrivilegesViewModel) { - const kibanaPrivileges = {}; - - const resources = Object.keys(kibanaPrivilegesViewModel); - resources.forEach(resource => { - const selectedPrivileges = Object.keys(kibanaPrivilegesViewModel[resource]).filter(key => kibanaPrivilegesViewModel[resource][key]); - if (selectedPrivileges.length > 0) { - kibanaPrivileges[resource] = selectedPrivileges; - } - }); - - return kibanaPrivileges; -} diff --git a/x-pack/plugins/security/public/views/management/edit_role/lib/get_available_permissions.js b/x-pack/plugins/security/public/views/management/edit_role/lib/get_available_privileges.js similarity index 90% rename from x-pack/plugins/security/public/views/management/edit_role/lib/get_available_permissions.js rename to x-pack/plugins/security/public/views/management/edit_role/lib/get_available_privileges.js index 5d77e12dcbcd9..0c686a93a28f6 100644 --- a/x-pack/plugins/security/public/views/management/edit_role/lib/get_available_permissions.js +++ b/x-pack/plugins/security/public/views/management/edit_role/lib/get_available_privileges.js @@ -6,7 +6,7 @@ import { NO_PRIVILEGE_VALUE } from './constants'; -export function getAvailablePermissions(minimumPrivilege) { +export function getAvailablePrivileges(minimumPrivilege) { switch (minimumPrivilege) { case NO_PRIVILEGE_VALUE: return ['read', 'all']; diff --git a/x-pack/plugins/security/public/views/management/edit_role/lib/get_available_privileges.test.js b/x-pack/plugins/security/public/views/management/edit_role/lib/get_available_privileges.test.js new file mode 100644 index 0000000000000..77f64549601d3 --- /dev/null +++ b/x-pack/plugins/security/public/views/management/edit_role/lib/get_available_privileges.test.js @@ -0,0 +1,26 @@ +/* + * 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 { getAvailablePrivileges } from './get_available_privileges'; +import { NO_PRIVILEGE_VALUE } from './constants'; + +describe('getAvailablePrivileges', () => { + it('throws when given an unexpected minimum privilege', () => { + expect(() => getAvailablePrivileges('idk')).toThrowErrorMatchingSnapshot(); + }); + + it(`returns all privileges when the minimum privilege is none`, () => { + expect(getAvailablePrivileges(NO_PRIVILEGE_VALUE)).toEqual(['read', 'all']); + }); + + it(`returns all privileges when the minimum privilege is read`, () => { + expect(getAvailablePrivileges('read')).toEqual(['read', 'all']); + }); + + it(`returns just the "all" privilege when the minimum privilege is all`, () => { + expect(getAvailablePrivileges('all')).toEqual(['all']); + }); +}); diff --git a/x-pack/plugins/security/public/views/management/edit_role/lib/privilege_transforms.js b/x-pack/plugins/security/public/views/management/edit_role/lib/privilege_transforms.js deleted file mode 100644 index ed3eaa88c3f31..0000000000000 --- a/x-pack/plugins/security/public/views/management/edit_role/lib/privilege_transforms.js +++ /dev/null @@ -1,43 +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 function denormalizePrivileges(role, application) { - const { - applications - } = role; - - const rolePrivileges = applications.filter(a => a.application === application); - - let basePrivilege; - const spacePrivileges = {}; - - rolePrivileges.forEach(privilege => { - const { - resources, - privileges - } = privilege; - - if (privileges.length !== 1) { - throw new Error(`Malformed privilege on role ${role.name}. Expected a single privilege, but found ${privileges.length}.`); - } - - if (resources.length === 1 && resources[0] === "*") { - basePrivilege = privileges[0]; - } else { - resources.forEach(resource => { - const existingSpacePrivs = spacePrivileges[resource] || []; - spacePrivileges[resource] = [...existingSpacePrivs, ...privileges]; - }); - } - }); - - - return { - basePrivilege, - spacePrivileges - }; -} diff --git a/x-pack/plugins/security/public/views/management/edit_role/lib/set_application_privileges.js b/x-pack/plugins/security/public/views/management/edit_role/lib/set_application_privileges.js deleted file mode 100644 index d900c13743a14..0000000000000 --- a/x-pack/plugins/security/public/views/management/edit_role/lib/set_application_privileges.js +++ /dev/null @@ -1,49 +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 { ALL_RESOURCE } from '../../../../../common/constants'; - -export function setApplicationPrivileges(kibanaPrivileges, role, application) { - if (!role.applications) { - role.applications = []; - } - - // we first remove the matching application entries - role.applications = role.applications.filter(x => { - return x.application !== application; - }); - - const privileges = Object.keys(kibanaPrivileges).filter(key => kibanaPrivileges[key]); - - // if we still have them, put the application entry back - if (privileges.length > 0) { - role.applications = [...role.applications, { - application, - privileges, - resources: [ALL_RESOURCE] - }]; - } -} - -export function togglePrivilege(role, application, permission) { - const appPermissions = role.applications - .find(a => a.application === application && a.resources[0] === ALL_RESOURCE); - - if (!appPermissions) { - role.applications.push({ - application, - privileges: [permission], - resources: [ALL_RESOURCE] - }); - } else { - const indexOfExisting = appPermissions.privileges.indexOf(permission); - if (indexOfExisting >= 0) { - appPermissions.privileges.splice(indexOfExisting, 1); - } else { - appPermissions.privileges.push(permission); - } - } -} diff --git a/x-pack/plugins/spaces/common/__snapshots__/spaces_url_parser.test.js.snap b/x-pack/plugins/spaces/common/__snapshots__/spaces_url_parser.test.js.snap deleted file mode 100644 index a42d029097b67..0000000000000 --- a/x-pack/plugins/spaces/common/__snapshots__/spaces_url_parser.test.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`addSpaceUrlContext it throws an error when the requested path does not start with a slash 1`] = `"path must start with a /"`;