Skip to content

Commit

Permalink
[SR] Prevent change to snapshot name / repository for managed SLM pol…
Browse files Browse the repository at this point in the history
…icies (#172291)

## Summary

Managed SLM policies `Snapshot name` and `Repository` field values can
be changed from the **Snapshot and Restore** UI. This is particularly an
issue with the `cloud-snapshot-policy` as changes to the snapshot name
or target repository will lead to plan failures on ESS. Besides having a
warning message displayed for managed SLM policies:
> This is a managed policy. Changing this policy might affect other
systems that use it. Proceed with caution.
field values being editable is prone to errors.

This PR disable the `Snapshot name` and `Repository` field for managed
SLM policies to prevent edits.

**Example - Regular SLM policy:**

![Untitled2](https://github.com/elastic/kibana/assets/7076736/64d501d2-3ab5-462a-af64-e04c2bc7721e)

**Example - Managed SLM policy:**

![Untitled](https://github.com/elastic/kibana/assets/7076736/abf9f2a0-c672-4317-b6e6-942c80769cff)

I'm open to suggestions if there is a better way to do this.

This PR fixes #124916 

### Checklist

- [x] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Yulia Čech <[email protected]>
Co-authored-by: Yulia Cech <[email protected]>
  • Loading branch information
4 people authored Dec 12, 2023
1 parent 50cc8b8 commit f2ca740
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { act } from 'react-dom/test-utils';

import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { setupEnvironment, pageHelpers } from './helpers';
import { API_BASE_PATH } from '../../common';
import { PolicyForm } from '../../public/application/components/policy_form';
import { PolicyFormTestBed } from './helpers/policy_form.helpers';
Expand Down Expand Up @@ -39,12 +39,10 @@ describe('<PolicyEdit />', () => {
features: [{ name: 'kibana' }, { name: 'tasks' }],
});

testBed = await setup(httpSetup);

await act(async () => {
await nextTick();
testBed.component.update();
testBed = await setup(httpSetup);
});
testBed.component.update();
});

test('should set the correct page title', () => {
Expand All @@ -64,12 +62,10 @@ describe('<PolicyEdit />', () => {
repositories: [{ name: 'this-is-a-new-repository' }],
});

testBed = await setup(httpSetup);

await act(async () => {
await nextTick();
testBed.component.update();
testBed = await setup(httpSetup);
});
testBed.component.update();
});

test('should show repository-not-found warning', () => {
Expand Down Expand Up @@ -99,10 +95,7 @@ describe('<PolicyEdit />', () => {
test('should use the same Form component as the "<PolicyAdd />" section', async () => {
testBedPolicyAdd = await setupPolicyAdd(httpSetup);

await act(async () => {
await nextTick();
testBedPolicyAdd.component.update();
});
testBedPolicyAdd.component.update();

const formEdit = testBed.component.find(PolicyForm);
const formAdd = testBedPolicyAdd.component.find(PolicyForm);
Expand All @@ -118,6 +111,28 @@ describe('<PolicyEdit />', () => {
expect(nameInput.props().disabled).toEqual(true);
});

test('should disable the repo and snapshot fields for managed policies', async () => {
httpRequestsMockHelpers.setGetPolicyResponse(POLICY_EDIT.name, {
policy: {
...POLICY_EDIT,
isManagedPolicy: true,
},
});

await act(async () => {
testBed = await setup(httpSetup);
});
testBed.component.update();

const { find } = testBed;

const snapshotInput = find('snapshotNameInput');
expect(snapshotInput.props().disabled).toEqual(true);

const repoSelect = find('repositorySelect');
expect(repoSelect.props().disabled).toEqual(true);
});

describe('form payload', () => {
it('should send the correct payload with changed values', async () => {
const { form, actions } = testBed;
Expand All @@ -138,10 +153,7 @@ describe('<PolicyEdit />', () => {
form.setInputValue('expireAfterUnitSelect', EXPIRE_AFTER_UNIT);
actions.clickNextButton();

await act(async () => {
actions.clickSubmitButton();
await nextTick();
});
actions.clickSubmitButton();

const { name, isManagedPolicy, schedule, repository, retention } = POLICY_EDIT;

Expand Down Expand Up @@ -182,10 +194,7 @@ describe('<PolicyEdit />', () => {
form.setInputValue('expireAfterValueInput', EXPIRE_AFTER_VALUE);
actions.clickNextButton();

await act(async () => {
actions.clickSubmitButton();
await nextTick();
});
actions.clickSubmitButton();

const { name, isManagedPolicy, schedule, repository, retention, snapshotName } =
POLICY_EDIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
}}
fullWidth
data-test-subj="repositorySelect"
disabled={policy?.isManagedPolicy && isEditing}
/>
);
};
Expand Down Expand Up @@ -342,6 +343,7 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
}
)}
data-test-subj="snapshotNameInput"
disabled={policy?.isManagedPolicy && isEditing}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down

0 comments on commit f2ca740

Please sign in to comment.