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

[DataViews] Use client-side authc.getCurrentUser from core.security #186856

Merged
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
1 change: 0 additions & 1 deletion src/plugins/data_views/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export type {
DataViewsContract,
HasDataViewsResponse,
IndicesViaSearchResponse,
UserIdGetter,
} from './types';

// Export plugin after all other imports
Expand Down
20 changes: 4 additions & 16 deletions src/plugins/data_views/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@

import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import type { SecurityPluginStart } from '@kbn/security-plugin-types-public';
import { getIndexPatternLoad } from './expressions';
import type { ClientConfigType } from '../common/types';
import {
DataViewsPublicPluginSetup,
DataViewsPublicPluginStart,
DataViewsPublicSetupDependencies,
DataViewsPublicStartDependencies,
UserIdGetter,
} from './types';

import { DataViewsApiClient } from '.';
Expand All @@ -43,7 +41,6 @@ export class DataViewsPublicPlugin
{
private readonly hasData = new HasData();
private rollupsEnabled: boolean = false;
private userIdGetter: UserIdGetter = async () => undefined;

constructor(private readonly initializerContext: PluginInitializerContext) {}

Expand All @@ -63,18 +60,6 @@ export class DataViewsPublicPlugin
}),
});

core.plugins.onStart<{ security: SecurityPluginStart }>('security').then(({ security }) => {
if (security.found) {
const getUserId = async function getUserId(): Promise<string | undefined> {
const currentUser = await security.contract.authc.getCurrentUser();
return currentUser?.profile_uid;
};
this.userIdGetter = getUserId;
} else {
throw new Error('Security plugin is not available, but is required for Data Views plugin');
}
});

return {
enableRollups: () => (this.rollupsEnabled = true),
};
Expand All @@ -101,7 +86,10 @@ export class DataViewsPublicPlugin
hasData: this.hasData.start(core),
uiSettings: new UiSettingsPublicToCommon(uiSettings),
savedObjectsClient: new ContentMagementWrapper(contentManagement.client),
apiClient: new DataViewsApiClient(http, () => this.userIdGetter()),
apiClient: new DataViewsApiClient(http, async () => {
const currentUser = await core.security.authc.getCurrentUser();
return currentUser?.profile_uid;
}),
fieldFormats,
http,
onNotification: (toastInputFields, key) => {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data_views/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ export interface DataViewsPublicStartDependencies {
contentManagement: ContentManagementPublicStart;
}

export type UserIdGetter = () => Promise<string | undefined>;

/**
* Data plugin public Setup contract
*/
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data_views/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@kbn/object-versioning",
"@kbn/core-saved-objects-server",
"@kbn/logging",
"@kbn/security-plugin-types-public",
"@kbn/crypto-browser",
],
"exclude": [
Expand Down