forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ResponseOps][MW] Fix bug when creating repeating Maintenance Window (e…
…lastic#207084) Closes elastic#198774 ## Summary - There was a bug when submitting `rrule` with a `byweekday` I fixed that validation to use a more inclusive regex. `byweekday` can be the expected `MO`, `TU`, etc but also `-1FR` or `+3SA` where the number corresponds to the week in a month. - The model version for the maintenance window was incorrect so when saving the SO the validation was failing. I fixed that and now we are allowed to save `number[]` as expected. - I removed some duplicated code and we now use the `rrule` schema from the `common` folder
- Loading branch information
Showing
19 changed files
with
158 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { validateRecurrenceByWeekday } from './v1'; | ||
|
||
describe('validateRecurrenceByWeekday', () => { | ||
it('validates empty array', () => { | ||
expect(validateRecurrenceByWeekday([])).toEqual('rRule byweekday cannot be empty'); | ||
}); | ||
|
||
it('validates properly formed byweekday strings', () => { | ||
const weekdays = ['+1MO', '+2TU', '+3WE', '+4TH', '-4FR', '-3SA', '-2SU', '-1MO']; | ||
|
||
expect(validateRecurrenceByWeekday(weekdays)).toBeUndefined(); | ||
}); | ||
|
||
it('validates improperly formed byweekday strings', () => { | ||
expect(validateRecurrenceByWeekday(['+1MO', 'FOO', '+3WE', 'BAR', '-4FR'])).toEqual( | ||
'invalid byweekday values in rRule byweekday: FOO,BAR' | ||
); | ||
}); | ||
|
||
it('validates byweekday strings without recurrence', () => { | ||
expect(validateRecurrenceByWeekday(['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'])).toBeUndefined(); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...gins/shared/alerting/common/routes/r_rule/validation/validate_recurrence_by_weekday/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const validateRecurrenceByWeekday = (array: string[]) => { | ||
if (array.length === 0) { | ||
return 'rRule byweekday cannot be empty'; | ||
} | ||
|
||
const byWeekDayRegex = new RegExp('^(((\\+|-)[1-4])?(MO|TU|WE|TH|FR|SA|SU))$'); | ||
const invalidDays: string[] = []; | ||
|
||
array.forEach((day) => { | ||
if (!byWeekDayRegex.test(day)) { | ||
invalidDays.push(day); | ||
} | ||
}); | ||
|
||
if (invalidDays.length > 0) { | ||
return `invalid byweekday values in rRule byweekday: ${invalidDays.join(',')}`; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ | |
*/ | ||
|
||
export { rRuleSchema } from './r_rule_schema'; | ||
export { rRuleRequestSchema } from './r_rule_request_schema'; |
63 changes: 0 additions & 63 deletions
63
...atform/plugins/shared/alerting/server/application/r_rule/schemas/r_rule_request_schema.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ | |
*/ | ||
|
||
export type { RRule } from './r_rule'; | ||
export type { RRuleRequest } from './r_rule_request'; |
10 changes: 0 additions & 10 deletions
10
x-pack/platform/plugins/shared/alerting/server/application/r_rule/types/r_rule_request.ts
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
x-pack/platform/plugins/shared/alerting/server/application/r_rule/validation/index.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...latform/plugins/shared/alerting/server/application/r_rule/validation/validate_end_date.ts
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
...rm/plugins/shared/alerting/server/application/r_rule/validation/validate_recurrence_by.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.