[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:
Sander Philipse 2023-09-07 17:52:35 +02:00 committed by GitHub
parent 4710d8c561
commit 62911d2bc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 30 deletions

View file

@ -9,6 +9,7 @@
import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiTitle, EuiSpacer, EuiImage, EuiText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { AuthenticatedUser } from '@kbn/security-plugin/common';
export * from './components/code_box';
export * from './components/github_link';
@ -24,19 +25,14 @@ export * from './types';
export * from './utils';
export interface WelcomeBannerProps {
userProfile: {
user: {
full_name?: string;
username?: string;
};
};
user?: AuthenticatedUser;
assetBasePath?: string;
image?: string;
showDescription?: boolean;
}
export const WelcomeBanner: React.FC<WelcomeBannerProps> = ({
userProfile,
user,
assetBasePath,
image,
showDescription = true,
@ -54,16 +50,18 @@ export const WelcomeBanner: React.FC<WelcomeBannerProps> = ({
</h1>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiTitle size="xxxs">
<h2>
{i18n.translate('searchApiPanels.welcomeBanner.header.greeting.title', {
defaultMessage: 'Hi {name}!',
values: { name: userProfile?.user?.full_name || userProfile?.user?.username },
})}
</h2>
</EuiTitle>
</EuiFlexItem>
{Boolean(user) && (
<EuiFlexItem grow={false}>
<EuiTitle size="xxxs">
<h2>
{i18n.translate('searchApiPanels.welcomeBanner.header.greeting.title', {
defaultMessage: 'Hi {name}!',
values: { name: user?.full_name || user.username },
})}
</h2>
</EuiTitle>
</EuiFlexItem>
)}
</EuiFlexGroup>
<EuiSpacer />
{showDescription && (

View file

@ -20,6 +20,7 @@
"@kbn/core-http-browser",
"@kbn/core-application-browser",
"@kbn/share-plugin",
"@kbn/i18n-react"
"@kbn/i18n-react",
"@kbn/security-plugin"
]
}

View file

@ -52,7 +52,7 @@ export const ElasticsearchOverview = () => {
const [selectedLanguage, setSelectedLanguage] =
useState<LanguageDefinition>(javascriptDefinition);
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(() => {
return cloud?.elasticsearchUrl ?? ELASTICSEARCH_URL_PLACEHOLDER;
@ -73,7 +73,7 @@ export const ElasticsearchOverview = () => {
<EuiPageTemplate offset={0} grow restrictWidth data-test-subj="svlSearchOverviewPage">
<EuiPageTemplate.Section alignment="top" className="serverlessSearchHeaderSection">
<EuiText color="ghost">
<WelcomeBanner userProfile={userProfile} assetBasePath={assetBasePath} />
<WelcomeBanner user={user} assetBasePath={assetBasePath} />
</EuiText>
</EuiPageTemplate.Section>
<EuiPageTemplate.Section color="subdued" bottomBorder="extended">

View file

@ -9,12 +9,12 @@ import { CloudStart } from '@kbn/cloud-plugin/public';
import type { CoreStart } from '@kbn/core/public';
import type { SharePluginStart } from '@kbn/share-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 {
cloud: CloudStart;
share: SharePluginStart;
userProfile: GetUserProfileResponse<UserProfileData>;
user?: AuthenticatedUser;
}
type ServerlessSearchKibanaContext = CoreStart & ServerlessSearchContext;

View file

@ -8,6 +8,7 @@
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { appIds } from '@kbn/management-cards-navigation';
import { AuthenticatedUser } from '@kbn/security-plugin/common';
import { createServerlessSearchSideNavComponent as createComponent } from './layout/nav';
import { docLinks } from '../common/doc_links';
import {
@ -41,10 +42,15 @@ export class ServerlessSearchPlugin
const [coreStart, services] = await core.getStartServices();
const { security } = services;
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, { userProfile, ...services });
return await renderApp(element, coreStart, { user, ...services });
},
});
@ -58,12 +64,9 @@ export class ServerlessSearchPlugin
async mount({ element }: AppMountParameters) {
const { renderApp } = await import('./application/connectors');
const [coreStart, services] = await core.getStartServices();
const { security } = services;
docLinks.setDocLinks(coreStart.docLinks.links);
const userProfile = await security.userProfiles.getCurrent();
return await renderApp(element, coreStart, { userProfile, ...services });
return await renderApp(element, coreStart, { ...services });
},
});