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

Expose spaces plugin function signatures in TypeScript #42133

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SpacesPlugin } from '../../../../spaces/types';
import { SpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
import { checkPrivilegesDynamicallyWithRequestFactory } from './check_privileges_dynamically';

Expand All @@ -18,6 +18,10 @@ test(`checkPrivileges.atSpace when spaces is enabled`, async () => {
const mockSpaces = {
isEnabled: true,
getSpaceId: jest.fn().mockReturnValue(spaceId),
spaceIdToNamespace: jest.fn(),
namespaceToSpaceId: jest.fn(),
getBasePath: jest.fn(),
getScopedSpacesClient: jest.fn(),
} as OptionalPlugin<SpacesPlugin>;
const request = Symbol();
const privilegeOrPrivileges = ['foo', 'bar'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Legacy } from 'kibana';
import { CheckPrivilegesAtResourceResponse, CheckPrivilegesWithRequest } from './check_privileges';

/*
Expand All @@ -12,22 +13,22 @@ import { CheckPrivilegesAtResourceResponse, CheckPrivilegesWithRequest } from '.
* you may not use this file except in compliance with the Elastic License.
*/

import { SpacesPlugin } from '../../../../spaces/types';
import { SpacesPlugin } from '../../../../spaces';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';

export type CheckPrivilegesDynamically = (
privilegeOrPrivileges: string | string[]
) => Promise<CheckPrivilegesAtResourceResponse>;

export type CheckPrivilegesDynamicallyWithRequest = (
request: Record<string, any>
request: Legacy.Request
) => CheckPrivilegesDynamically;

export function checkPrivilegesDynamicallyWithRequestFactory(
checkPrivilegesWithRequest: CheckPrivilegesWithRequest,
spaces: OptionalPlugin<SpacesPlugin>
): CheckPrivilegesDynamicallyWithRequest {
return function checkPrivilegesDynamicallyWithRequest(request: Record<string, any>) {
return function checkPrivilegesDynamicallyWithRequest(request: Legacy.Request) {
const checkPrivileges = checkPrivilegesWithRequest(request);
return async function checkPrivilegesDynamically(privilegeOrPrivileges: string | string[]) {
if (spaces.isEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { Server } from 'hapi';

import { getClient } from '../../../../../server/lib/get_client_shield';
import { SpacesPlugin } from '../../../../spaces/types';
import { SpacesPlugin } from '../../../../spaces';
import { XPackFeature, XPackMainPlugin } from '../../../../xpack_main/xpack_main';
import { APPLICATION_PREFIX } from '../../../common/constants';
import { OptionalPlugin } from '../../../../../server/lib/optional_plugin';
Expand Down
10 changes: 10 additions & 0 deletions x-pack/legacy/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ import {
} from './server/new_platform/plugin';
import { initSpacesRequestInterceptors } from './server/lib/request_interceptors';
import { SecurityPlugin } from '../security';
import { SpacesServiceSetup } from './server/new_platform/spaces_service/spaces_service';

export interface SpacesPlugin {
getSpaceId: SpacesServiceSetup['getSpaceId'];
spaceIdToNamespace: SpacesServiceSetup['spaceIdToNamespace'];
namespaceToSpaceId: SpacesServiceSetup['namespaceToSpaceId'];
getBasePath: SpacesServiceSetup['getBasePath'];
getScopedSpacesClient: SpacesServiceSetup['scopedClient'];
}

export const spaces = (kibana: Record<string, any>) =>
new kibana.Plugin({
id: 'spaces',
Expand Down
10 changes: 0 additions & 10 deletions x-pack/legacy/plugins/spaces/types.d.ts

This file was deleted.