Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Nov 13, 2018
1 parent 8800aa2 commit 14802d7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/ui/public/capabilities/ui_capabilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jest.mock(
() => ({
getInjected: (key: string) => {
if (key !== 'uiCapabilities') {
throw new Error(`Unxpected key for test: ${key}`);
throw new Error(`Unexpected key for test: ${key}`);
}

return {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ export const spaces = (kibana: any) =>
if (vars.activeSpace.space) {
vars.uiCapabilities = await toggleUiCapabilities(
vars.uiCapabilities,
vars.activeSpace.space,
spacesClient
vars.activeSpace.space
);
}

Expand Down
30 changes: 1 addition & 29 deletions x-pack/plugins/spaces/server/lib/toggle_ui_capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,13 @@

import { UICapabilities } from 'ui/capabilities';
import { Space } from '../../common/model/space';
import { SpacesClient } from './spaces_client';

export async function toggleUiCapabilities(
uiCapabilities: UICapabilities,
activeSpace: Space,
spacesClient: SpacesClient
) {
// 1) Determine if user can manage spaces
await toggleManageSpacesCapability(uiCapabilities, spacesClient);

// 2) Turn off capabilities that are disabled within this space
export async function toggleUiCapabilities(uiCapabilities: UICapabilities, activeSpace: Space) {
toggleDisabledFeatures(uiCapabilities, activeSpace);

return uiCapabilities;
}

async function toggleManageSpacesCapability(
uiCapabilities: UICapabilities,
spacesClient: SpacesClient
) {
// Spaces special case
// Security is normally responsible for toggling such features, but since Spaces themselves are part of a security construct,
// the Spaces plugin is responsible for determining this specific capability.
try {
const canManageSpaces = await spacesClient.canEnumerateSpaces();
if (!canManageSpaces) {
uiCapabilities.spaces.manage = false;
}
} catch (error) {
// TODO: Log
// Fail closed.
uiCapabilities.spaces.manage = false;
}
}

function toggleDisabledFeatures(uiCapabilities: UICapabilities, activeSpace: Space) {
// TODO: get disabled features from active space
// @ts-ignore
Expand Down

0 comments on commit 14802d7

Please sign in to comment.