mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 22:49:32 -02:30
Fix login after source variables change
This commit is contained in:
@@ -7,11 +7,10 @@ import styled from 'styled-components';
|
|||||||
import { LoginForm, LoginPage as PFLoginPage } from '@patternfly/react-core';
|
import { LoginForm, LoginPage as PFLoginPage } from '@patternfly/react-core';
|
||||||
import useRequest, { useDismissableError } from '../../util/useRequest';
|
import useRequest, { useDismissableError } from '../../util/useRequest';
|
||||||
import { RootAPI } from '../../api';
|
import { RootAPI } from '../../api';
|
||||||
import { BrandName } from '../../variables';
|
|
||||||
import AlertModal from '../../components/AlertModal';
|
import AlertModal from '../../components/AlertModal';
|
||||||
import ErrorDetail from '../../components/ErrorDetail';
|
import ErrorDetail from '../../components/ErrorDetail';
|
||||||
|
|
||||||
import brandLogo from './brand-logo.svg';
|
const loginLogoSrc = '/static/media/logo-login.svg';
|
||||||
|
|
||||||
const LoginPage = styled(PFLoginPage)`
|
const LoginPage = styled(PFLoginPage)`
|
||||||
& .pf-c-brand {
|
& .pf-c-brand {
|
||||||
@@ -24,21 +23,27 @@ function AWXLogin({ alt, i18n, isAuthenticated }) {
|
|||||||
isLoading: isCustomLoginInfoLoading,
|
isLoading: isCustomLoginInfoLoading,
|
||||||
error: customLoginInfoError,
|
error: customLoginInfoError,
|
||||||
request: fetchCustomLoginInfo,
|
request: fetchCustomLoginInfo,
|
||||||
result: { logo, loginInfo },
|
result: { brandName, logo, loginInfo },
|
||||||
} = useRequest(
|
} = useRequest(
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
const {
|
const [
|
||||||
data: { custom_logo, custom_login_info },
|
{
|
||||||
} = await RootAPI.read();
|
data: { custom_logo, custom_login_info },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: { BRAND_NAME },
|
||||||
|
},
|
||||||
|
] = await Promise.all([RootAPI.read(), RootAPI.readAssetVariables()]);
|
||||||
const logoSrc = custom_logo
|
const logoSrc = custom_logo
|
||||||
? `data:image/jpeg;${custom_logo}`
|
? `data:image/jpeg;${custom_logo}`
|
||||||
: brandLogo;
|
: loginLogoSrc;
|
||||||
return {
|
return {
|
||||||
|
brandName: BRAND_NAME,
|
||||||
logo: logoSrc,
|
logo: logoSrc,
|
||||||
loginInfo: custom_login_info,
|
loginInfo: custom_login_info,
|
||||||
};
|
};
|
||||||
}, []),
|
}, []),
|
||||||
{ logo: brandLogo, loginInfo: null }
|
{ brandName: null, logo: loginLogoSrc, loginInfo: null }
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -70,8 +75,6 @@ function AWXLogin({ alt, i18n, isAuthenticated }) {
|
|||||||
await authenticate(values);
|
await authenticate(values);
|
||||||
};
|
};
|
||||||
|
|
||||||
const brandName = BrandName;
|
|
||||||
|
|
||||||
if (isCustomLoginInfoLoading) {
|
if (isCustomLoginInfoLoading) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -91,7 +94,11 @@ function AWXLogin({ alt, i18n, isAuthenticated }) {
|
|||||||
<LoginPage
|
<LoginPage
|
||||||
brandImgSrc={logo}
|
brandImgSrc={logo}
|
||||||
brandImgAlt={alt || brandName}
|
brandImgAlt={alt || brandName}
|
||||||
loginTitle={i18n._(t`Welcome to Ansible ${brandName}! Please Sign In.`)}
|
loginTitle={
|
||||||
|
brandName
|
||||||
|
? i18n._(t`Welcome to Ansible ${brandName}! Please Sign In.`)
|
||||||
|
: ''
|
||||||
|
}
|
||||||
textContent={loginInfo}
|
textContent={loginInfo}
|
||||||
>
|
>
|
||||||
<Formik
|
<Formik
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ import AWXLogin from './Login';
|
|||||||
|
|
||||||
jest.mock('../../api');
|
jest.mock('../../api');
|
||||||
|
|
||||||
|
RootAPI.readAssetVariables.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
BRAND_NAME: 'AWX',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
describe('<Login />', () => {
|
describe('<Login />', () => {
|
||||||
async function findChildren(wrapper) {
|
async function findChildren(wrapper) {
|
||||||
const [
|
const [
|
||||||
@@ -100,7 +106,7 @@ describe('<Login />', () => {
|
|||||||
});
|
});
|
||||||
const { loginHeaderLogo } = await findChildren(wrapper);
|
const { loginHeaderLogo } = await findChildren(wrapper);
|
||||||
const { alt, src } = loginHeaderLogo.props();
|
const { alt, src } = loginHeaderLogo.props();
|
||||||
expect([alt, src]).toEqual(['AWX', 'brand-logo.svg']);
|
expect([alt, src]).toEqual(['AWX', '/static/media/logo-login.svg']);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -123,7 +129,7 @@ describe('<Login />', () => {
|
|||||||
});
|
});
|
||||||
const { loginHeaderLogo } = await findChildren(wrapper);
|
const { loginHeaderLogo } = await findChildren(wrapper);
|
||||||
const { alt, src } = loginHeaderLogo.props();
|
const { alt, src } = loginHeaderLogo.props();
|
||||||
expect([alt, src]).toEqual(['AWX', 'brand-logo.svg']);
|
expect([alt, src]).toEqual([null, '/static/media/logo-login.svg']);
|
||||||
expect(wrapper.find('AlertModal').length).toBe(1);
|
expect(wrapper.find('AlertModal').length).toBe(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user