mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] Fix space_ids validation and spaces UI (#191083)
This commit is contained in:
parent
bd9dde8ba7
commit
8f7ea3c34e
3 changed files with 57 additions and 11 deletions
|
@ -77,9 +77,8 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
|
|||
validation,
|
||||
disabled = false,
|
||||
}) => {
|
||||
const useSpaceAwareness = ExperimentalFeaturesService.get()?.useSpaceAwareness ?? false;
|
||||
const { docLinks } = useStartServices();
|
||||
const { spaceId } = useFleetStatus();
|
||||
const { spaceId, isSpaceAwarenessEnabled } = useFleetStatus();
|
||||
|
||||
const { getAbsolutePath } = useLink();
|
||||
const AgentTamperProtectionWrapper = useUIExtension(
|
||||
|
@ -263,21 +262,21 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
|
|||
/>
|
||||
</EuiFormRow>
|
||||
</EuiDescribedFormGroup>
|
||||
{useSpaceAwareness ? (
|
||||
{isSpaceAwarenessEnabled ? (
|
||||
<EuiDescribedFormGroup
|
||||
fullWidth
|
||||
title={
|
||||
<h3>
|
||||
<FormattedMessage
|
||||
id="xpack.fleet.agentPolicyForm.spaceFieldLabel"
|
||||
defaultMessage="Space"
|
||||
defaultMessage="Spaces"
|
||||
/>
|
||||
</h3>
|
||||
}
|
||||
description={
|
||||
<FormattedMessage
|
||||
id="xpack.fleet.agentPolicyForm.spaceDescription"
|
||||
defaultMessage="Select a space for this policy or create a new one. {link}"
|
||||
defaultMessage="Select one or more spaces for this policy or create a new one. {link}"
|
||||
values={{
|
||||
link: (
|
||||
<EuiLink
|
||||
|
@ -312,6 +311,9 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
|
|||
: [spaceId || 'default']
|
||||
}
|
||||
onChange={(newValue) => {
|
||||
if (newValue.length === 0) {
|
||||
return;
|
||||
}
|
||||
updateAgentPolicy({
|
||||
space_ids: newValue,
|
||||
});
|
||||
|
|
|
@ -41,11 +41,7 @@ function isInteger(n: number) {
|
|||
|
||||
export const AgentPolicyBaseSchema = {
|
||||
id: schema.maybe(schema.string()),
|
||||
space_ids: schema.maybe(
|
||||
schema.arrayOf(schema.string(), {
|
||||
minSize: 1,
|
||||
})
|
||||
),
|
||||
space_ids: schema.maybe(schema.arrayOf(schema.string())),
|
||||
name: schema.string({ minLength: 1, validate: validateNonEmptyString }),
|
||||
namespace: AgentPolicyNamespaceSchema,
|
||||
description: schema.maybe(schema.string()),
|
||||
|
|
|
@ -906,6 +906,7 @@ export default function (providerContext: FtrProviderContext) {
|
|||
describe('PUT /api/fleet/agent_policies/{agentPolicyId}', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/fleet/empty_fleet_server');
|
||||
await kibanaServer.savedObjects.cleanStandardList();
|
||||
});
|
||||
const createdPolicyIds: string[] = [];
|
||||
after(async () => {
|
||||
|
@ -967,6 +968,53 @@ export default function (providerContext: FtrProviderContext) {
|
|||
});
|
||||
});
|
||||
|
||||
it('should support empty space_ids', async () => {
|
||||
const {
|
||||
body: { item: originalPolicy },
|
||||
} = await supertest
|
||||
.post(`/api/fleet/agent_policies`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({
|
||||
name: 'Initial name 2',
|
||||
space_ids: [],
|
||||
description: 'Initial description',
|
||||
namespace: 'default',
|
||||
})
|
||||
.expect(200);
|
||||
agentPolicyId = originalPolicy.id;
|
||||
const {
|
||||
body: { item: updatedPolicy },
|
||||
} = await supertest
|
||||
.put(`/api/fleet/agent_policies/${agentPolicyId}`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({
|
||||
name: 'Updated name 2',
|
||||
space_ids: [],
|
||||
description: 'Updated description',
|
||||
namespace: 'default',
|
||||
is_protected: false,
|
||||
})
|
||||
.expect(200);
|
||||
createdPolicyIds.push(updatedPolicy.id);
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const { id, updated_at, version, ...newPolicy } = updatedPolicy;
|
||||
|
||||
expect(newPolicy).to.eql({
|
||||
status: 'active',
|
||||
name: 'Updated name 2',
|
||||
description: 'Updated description',
|
||||
namespace: 'default',
|
||||
is_managed: false,
|
||||
revision: 2,
|
||||
schema_version: FLEET_AGENT_POLICIES_SCHEMA_VERSION,
|
||||
updated_by: 'elastic',
|
||||
inactivity_timeout: 1209600,
|
||||
package_policies: [],
|
||||
is_protected: false,
|
||||
space_ids: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a 409 if policy already exists with name given', async () => {
|
||||
const sharedBody = {
|
||||
name: 'Initial name',
|
||||
|
@ -1053,7 +1101,7 @@ export default function (providerContext: FtrProviderContext) {
|
|||
.put(`/api/fleet/agent_policies/${originalPolicy.id}`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({
|
||||
name: 'Updated name',
|
||||
name: `Updated name ${Date.now()}`,
|
||||
description: 'Initial description',
|
||||
namespace: 'default',
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue