mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 03:01:21 -04:00
[Serverless Search] Fix absent user profile breaking Kibana (#165880)
## Summary This fixes an absent user profile breaking Kibana in Serverless ES3. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
4710d8c561
commit
62911d2bc9
5 changed files with 32 additions and 30 deletions
|
@ -9,6 +9,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { EuiFlexGroup, EuiFlexItem, EuiTitle, EuiSpacer, EuiImage, EuiText } from '@elastic/eui';
|
import { EuiFlexGroup, EuiFlexItem, EuiTitle, EuiSpacer, EuiImage, EuiText } from '@elastic/eui';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
|
import { AuthenticatedUser } from '@kbn/security-plugin/common';
|
||||||
|
|
||||||
export * from './components/code_box';
|
export * from './components/code_box';
|
||||||
export * from './components/github_link';
|
export * from './components/github_link';
|
||||||
|
@ -24,19 +25,14 @@ export * from './types';
|
||||||
export * from './utils';
|
export * from './utils';
|
||||||
|
|
||||||
export interface WelcomeBannerProps {
|
export interface WelcomeBannerProps {
|
||||||
userProfile: {
|
user?: AuthenticatedUser;
|
||||||
user: {
|
|
||||||
full_name?: string;
|
|
||||||
username?: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
assetBasePath?: string;
|
assetBasePath?: string;
|
||||||
image?: string;
|
image?: string;
|
||||||
showDescription?: boolean;
|
showDescription?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WelcomeBanner: React.FC<WelcomeBannerProps> = ({
|
export const WelcomeBanner: React.FC<WelcomeBannerProps> = ({
|
||||||
userProfile,
|
user,
|
||||||
assetBasePath,
|
assetBasePath,
|
||||||
image,
|
image,
|
||||||
showDescription = true,
|
showDescription = true,
|
||||||
|
@ -54,16 +50,18 @@ export const WelcomeBanner: React.FC<WelcomeBannerProps> = ({
|
||||||
</h1>
|
</h1>
|
||||||
</EuiTitle>
|
</EuiTitle>
|
||||||
</EuiFlexItem>
|
</EuiFlexItem>
|
||||||
<EuiFlexItem grow={false}>
|
{Boolean(user) && (
|
||||||
<EuiTitle size="xxxs">
|
<EuiFlexItem grow={false}>
|
||||||
<h2>
|
<EuiTitle size="xxxs">
|
||||||
{i18n.translate('searchApiPanels.welcomeBanner.header.greeting.title', {
|
<h2>
|
||||||
defaultMessage: 'Hi {name}!',
|
{i18n.translate('searchApiPanels.welcomeBanner.header.greeting.title', {
|
||||||
values: { name: userProfile?.user?.full_name || userProfile?.user?.username },
|
defaultMessage: 'Hi {name}!',
|
||||||
})}
|
values: { name: user?.full_name || user.username },
|
||||||
</h2>
|
})}
|
||||||
</EuiTitle>
|
</h2>
|
||||||
</EuiFlexItem>
|
</EuiTitle>
|
||||||
|
</EuiFlexItem>
|
||||||
|
)}
|
||||||
</EuiFlexGroup>
|
</EuiFlexGroup>
|
||||||
<EuiSpacer />
|
<EuiSpacer />
|
||||||
{showDescription && (
|
{showDescription && (
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
"@kbn/core-http-browser",
|
"@kbn/core-http-browser",
|
||||||
"@kbn/core-application-browser",
|
"@kbn/core-application-browser",
|
||||||
"@kbn/share-plugin",
|
"@kbn/share-plugin",
|
||||||
"@kbn/i18n-react"
|
"@kbn/i18n-react",
|
||||||
|
"@kbn/security-plugin"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ export const ElasticsearchOverview = () => {
|
||||||
const [selectedLanguage, setSelectedLanguage] =
|
const [selectedLanguage, setSelectedLanguage] =
|
||||||
useState<LanguageDefinition>(javascriptDefinition);
|
useState<LanguageDefinition>(javascriptDefinition);
|
||||||
const [clientApiKey, setClientApiKey] = useState<string>(API_KEY_PLACEHOLDER);
|
const [clientApiKey, setClientApiKey] = useState<string>(API_KEY_PLACEHOLDER);
|
||||||
const { application, cloud, http, userProfile, share } = useKibanaServices();
|
const { application, cloud, http, user, share } = useKibanaServices();
|
||||||
|
|
||||||
const elasticsearchURL = useMemo(() => {
|
const elasticsearchURL = useMemo(() => {
|
||||||
return cloud?.elasticsearchUrl ?? ELASTICSEARCH_URL_PLACEHOLDER;
|
return cloud?.elasticsearchUrl ?? ELASTICSEARCH_URL_PLACEHOLDER;
|
||||||
|
@ -73,7 +73,7 @@ export const ElasticsearchOverview = () => {
|
||||||
<EuiPageTemplate offset={0} grow restrictWidth data-test-subj="svlSearchOverviewPage">
|
<EuiPageTemplate offset={0} grow restrictWidth data-test-subj="svlSearchOverviewPage">
|
||||||
<EuiPageTemplate.Section alignment="top" className="serverlessSearchHeaderSection">
|
<EuiPageTemplate.Section alignment="top" className="serverlessSearchHeaderSection">
|
||||||
<EuiText color="ghost">
|
<EuiText color="ghost">
|
||||||
<WelcomeBanner userProfile={userProfile} assetBasePath={assetBasePath} />
|
<WelcomeBanner user={user} assetBasePath={assetBasePath} />
|
||||||
</EuiText>
|
</EuiText>
|
||||||
</EuiPageTemplate.Section>
|
</EuiPageTemplate.Section>
|
||||||
<EuiPageTemplate.Section color="subdued" bottomBorder="extended">
|
<EuiPageTemplate.Section color="subdued" bottomBorder="extended">
|
||||||
|
|
|
@ -9,12 +9,12 @@ import { CloudStart } from '@kbn/cloud-plugin/public';
|
||||||
import type { CoreStart } from '@kbn/core/public';
|
import type { CoreStart } from '@kbn/core/public';
|
||||||
import type { SharePluginStart } from '@kbn/share-plugin/public';
|
import type { SharePluginStart } from '@kbn/share-plugin/public';
|
||||||
import { useKibana as useKibanaBase } from '@kbn/kibana-react-plugin/public';
|
import { useKibana as useKibanaBase } from '@kbn/kibana-react-plugin/public';
|
||||||
import { GetUserProfileResponse, UserProfileData } from '@kbn/security-plugin/common';
|
import { AuthenticatedUser } from '@kbn/security-plugin/common';
|
||||||
|
|
||||||
export interface ServerlessSearchContext {
|
export interface ServerlessSearchContext {
|
||||||
cloud: CloudStart;
|
cloud: CloudStart;
|
||||||
share: SharePluginStart;
|
share: SharePluginStart;
|
||||||
userProfile: GetUserProfileResponse<UserProfileData>;
|
user?: AuthenticatedUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerlessSearchKibanaContext = CoreStart & ServerlessSearchContext;
|
type ServerlessSearchKibanaContext = CoreStart & ServerlessSearchContext;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
|
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { appIds } from '@kbn/management-cards-navigation';
|
import { appIds } from '@kbn/management-cards-navigation';
|
||||||
|
import { AuthenticatedUser } from '@kbn/security-plugin/common';
|
||||||
import { createServerlessSearchSideNavComponent as createComponent } from './layout/nav';
|
import { createServerlessSearchSideNavComponent as createComponent } from './layout/nav';
|
||||||
import { docLinks } from '../common/doc_links';
|
import { docLinks } from '../common/doc_links';
|
||||||
import {
|
import {
|
||||||
|
@ -41,10 +42,15 @@ export class ServerlessSearchPlugin
|
||||||
const [coreStart, services] = await core.getStartServices();
|
const [coreStart, services] = await core.getStartServices();
|
||||||
const { security } = services;
|
const { security } = services;
|
||||||
docLinks.setDocLinks(coreStart.docLinks.links);
|
docLinks.setDocLinks(coreStart.docLinks.links);
|
||||||
|
let user: AuthenticatedUser | undefined;
|
||||||
|
try {
|
||||||
|
const response = await security.authc.getCurrentUser();
|
||||||
|
user = response;
|
||||||
|
} catch {
|
||||||
|
user = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const userProfile = await security.userProfiles.getCurrent();
|
return await renderApp(element, coreStart, { user, ...services });
|
||||||
|
|
||||||
return await renderApp(element, coreStart, { userProfile, ...services });
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -58,12 +64,9 @@ export class ServerlessSearchPlugin
|
||||||
async mount({ element }: AppMountParameters) {
|
async mount({ element }: AppMountParameters) {
|
||||||
const { renderApp } = await import('./application/connectors');
|
const { renderApp } = await import('./application/connectors');
|
||||||
const [coreStart, services] = await core.getStartServices();
|
const [coreStart, services] = await core.getStartServices();
|
||||||
const { security } = services;
|
|
||||||
docLinks.setDocLinks(coreStart.docLinks.links);
|
docLinks.setDocLinks(coreStart.docLinks.links);
|
||||||
|
return await renderApp(element, coreStart, { ...services });
|
||||||
const userProfile = await security.userProfiles.getCurrent();
|
|
||||||
|
|
||||||
return await renderApp(element, coreStart, { userProfile, ...services });
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue