mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
UI: Add validation for activity counter config retention_months max (#27429)
This commit is contained in:
@@ -15,6 +15,10 @@ const validations = {
|
|||||||
message: (model) =>
|
message: (model) =>
|
||||||
`Retention period must be greater than or equal to ${model.minimumRetentionMonths}.`,
|
`Retention period must be greater than or equal to ${model.minimumRetentionMonths}.`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
validator: (model) => parseInt(model.retentionMonths) <= 60,
|
||||||
|
message: 'Retention period must be less than or equal to 60.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
add,
|
|
||||||
addMonths,
|
addMonths,
|
||||||
differenceInCalendarMonths,
|
differenceInCalendarMonths,
|
||||||
endOfMonth,
|
endOfMonth,
|
||||||
@@ -37,7 +36,6 @@ export const CONFIG_RESPONSE = {
|
|||||||
request_id: 'some-config-id',
|
request_id: 'some-config-id',
|
||||||
data: {
|
data: {
|
||||||
billing_start_timestamp: formatRFC3339(LICENSE_START),
|
billing_start_timestamp: formatRFC3339(LICENSE_START),
|
||||||
default_report_months: 12,
|
|
||||||
enabled: 'default-enabled',
|
enabled: 'default-enabled',
|
||||||
minimum_retention_months: 48,
|
minimum_retention_months: 48,
|
||||||
queries_available: false,
|
queries_available: false,
|
||||||
@@ -251,41 +249,41 @@ export default function (server) {
|
|||||||
// we don't currently use build_date, including for accuracy. it's only tracked in versions >= 1.11.0
|
// we don't currently use build_date, including for accuracy. it's only tracked in versions >= 1.11.0
|
||||||
build_date: null,
|
build_date: null,
|
||||||
previous_version: null,
|
previous_version: null,
|
||||||
timestamp_installed: LICENSE_START.toISOString(),
|
timestamp_installed: '2023-07-02T00:00:00Z',
|
||||||
},
|
},
|
||||||
'1.9.1': {
|
'1.9.1': {
|
||||||
build_date: null,
|
build_date: null,
|
||||||
previous_version: '1.9.0',
|
previous_version: '1.9.0',
|
||||||
timestamp_installed: addMonths(LICENSE_START, 1).toISOString(),
|
timestamp_installed: '2023-08-02T00:00:00Z',
|
||||||
},
|
},
|
||||||
// auth mount attribution added in 1.10.0
|
// auth mount attribution added in 1.10.0
|
||||||
'1.10.1': {
|
'1.10.1': {
|
||||||
build_date: null,
|
build_date: null,
|
||||||
previous_version: '1.9.1',
|
previous_version: '1.9.1',
|
||||||
timestamp_installed: addMonths(LICENSE_START, 2).toISOString(), // same as UPGRADE_DATE
|
timestamp_installed: '2023-09-02T00:00:00Z', // same as UPGRADE_DATE
|
||||||
},
|
},
|
||||||
'1.10.3': {
|
'1.10.3': {
|
||||||
build_date: null,
|
build_date: null,
|
||||||
previous_version: '1.10.1',
|
previous_version: '1.10.1',
|
||||||
timestamp_installed: add(LICENSE_START, { months: 2, weeks: 3 }).toISOString(),
|
timestamp_installed: '2023-10-23T00:00:00Z',
|
||||||
},
|
},
|
||||||
// no notable UI changes
|
// no notable UI changes
|
||||||
'1.14.4': {
|
'1.14.4': {
|
||||||
build_date: addMonths(LICENSE_START, 3).toISOString(),
|
build_date: '2023-11-02T00:00:00Z',
|
||||||
previous_version: '1.10.3',
|
previous_version: '1.10.3',
|
||||||
timestamp_installed: addMonths(LICENSE_START, 3).toISOString(),
|
timestamp_installed: '2023-11-02T00:00:00Z',
|
||||||
},
|
},
|
||||||
// sync clients added
|
// sync clients added
|
||||||
'1.16.0': {
|
'1.16.0': {
|
||||||
build_date: addMonths(LICENSE_START, 4).toISOString(),
|
build_date: '2023-11-23T00:00:00Z',
|
||||||
previous_version: '1.14.4',
|
previous_version: '1.14.4',
|
||||||
timestamp_installed: addMonths(LICENSE_START, 4).toISOString(),
|
timestamp_installed: '2023-11-23T00:00:00Z',
|
||||||
},
|
},
|
||||||
// acme_clients separated from non-entity clients
|
// acme_clients separated from non-entity clients
|
||||||
'1.17.0': {
|
'1.17.0': {
|
||||||
build_date: addMonths(LICENSE_START, 5).toISOString(),
|
build_date: '2023-12-02T00:00:00Z',
|
||||||
previous_version: '1.16.0',
|
previous_version: '1.16.0',
|
||||||
timestamp_installed: addMonths(LICENSE_START, 5).toISOString(),
|
timestamp_installed: '2023-12-02T00:00:00Z',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
this.router = this.owner.lookup('service:router');
|
this.router = this.owner.lookup('service:router');
|
||||||
this.transitionStub = sinon.stub(this.router, 'transitionTo');
|
this.transitionStub = sinon.stub(this.router, 'transitionTo');
|
||||||
const store = this.owner.lookup('service:store');
|
const store = this.owner.lookup('service:store');
|
||||||
this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 24) => {
|
this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 48) => {
|
||||||
store.pushPayload('clients/config', {
|
store.pushPayload('clients/config', {
|
||||||
modelName: 'clients/config',
|
modelName: 'clients/config',
|
||||||
id: 'foo',
|
id: 'foo',
|
||||||
@@ -26,7 +26,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
enabled,
|
enabled,
|
||||||
reporting_enabled,
|
reporting_enabled,
|
||||||
minimum_retention_months,
|
minimum_retention_months,
|
||||||
retention_months: 24,
|
retention_months: 49,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.model = store.peekRecord('clients/config', 'foo');
|
this.model = store.peekRecord('clients/config', 'foo');
|
||||||
@@ -46,18 +46,18 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
'Enabled value matches model'
|
'Enabled value matches model'
|
||||||
);
|
);
|
||||||
assert.ok(
|
assert.ok(
|
||||||
find('[data-test-row-value="Retention period"]').textContent.includes('24'),
|
find('[data-test-row-value="Retention period"]').textContent.includes('49'),
|
||||||
'Retention period value matches model'
|
'Retention period value matches model'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it should function in edit mode when reporting is disabled', async function (assert) {
|
test('it should function in edit mode when reporting is disabled', async function (assert) {
|
||||||
assert.expect(12);
|
assert.expect(13);
|
||||||
|
const retentionMonths = 60;
|
||||||
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
||||||
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
||||||
const expected = { enabled: 'enable', retention_months: 24 };
|
const expected = { enabled: 'enable', retention_months: retentionMonths };
|
||||||
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
assert.deepEqual({ enabled, retention_months }, expected, 'Correct data sent in PUT request (1)');
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -71,19 +71,27 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
assert
|
assert
|
||||||
.dom('label[for="enabled"]')
|
.dom('label[for="enabled"]')
|
||||||
.hasText('Data collection is off', 'Correct label renders when data collection is off');
|
.hasText('Data collection is off', 'Correct label renders when data collection is off');
|
||||||
assert.dom('[data-test-input="retentionMonths"]').hasValue('24', 'Retention months render');
|
assert.dom('[data-test-input="retentionMonths"]').hasValue('49', 'Retention months render');
|
||||||
|
|
||||||
await click('[data-test-input="enabled"]');
|
await click('[data-test-input="enabled"]');
|
||||||
await fillIn('[data-test-input="retentionMonths"]', -3);
|
await fillIn('[data-test-input="retentionMonths"]', 20);
|
||||||
await click('[data-test-clients-config-save]');
|
await click('[data-test-clients-config-save]');
|
||||||
assert
|
assert
|
||||||
.dom('[data-test-inline-error-message]')
|
.dom('[data-test-inline-error-message]')
|
||||||
.hasText(
|
.hasText(
|
||||||
'Retention period must be greater than or equal to 24.',
|
'Retention period must be greater than or equal to 48.',
|
||||||
'Validation error shows for incorrect retention period'
|
'Validation error shows for min retention period'
|
||||||
|
);
|
||||||
|
await fillIn('[data-test-input="retentionMonths"]', 90);
|
||||||
|
await click('[data-test-clients-config-save]');
|
||||||
|
assert
|
||||||
|
.dom('[data-test-inline-error-message]')
|
||||||
|
.hasText(
|
||||||
|
'Retention period must be less than or equal to 60.',
|
||||||
|
'Validation error shows for max retention period'
|
||||||
);
|
);
|
||||||
|
|
||||||
await fillIn('[data-test-input="retentionMonths"]', 24);
|
await fillIn('[data-test-input="retentionMonths"]', retentionMonths);
|
||||||
await click('[data-test-clients-config-save]');
|
await click('[data-test-clients-config-save]');
|
||||||
assert
|
assert
|
||||||
.dom('[data-test-clients-config-modal="title"]')
|
.dom('[data-test-clients-config-modal="title"]')
|
||||||
@@ -114,7 +122,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
||||||
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
||||||
const expected = { enabled: 'enable', retention_months: 48 };
|
const expected = { enabled: 'enable', retention_months: 48 };
|
||||||
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
assert.deepEqual({ enabled, retention_months }, expected, 'Correct data sent in PUT request (2)');
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -125,7 +133,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
`);
|
`);
|
||||||
|
|
||||||
assert.dom('[data-test-input="enabled"]').doesNotExist('Data collection input not shown ');
|
assert.dom('[data-test-input="enabled"]').doesNotExist('Data collection input not shown ');
|
||||||
assert.dom('[data-test-input="retentionMonths"]').hasValue('24', 'Retention months render');
|
assert.dom('[data-test-input="retentionMonths"]').hasValue('49', 'Retention months render');
|
||||||
|
|
||||||
await fillIn('[data-test-input="retentionMonths"]', 5);
|
await fillIn('[data-test-input="retentionMonths"]', 5);
|
||||||
await click('[data-test-clients-config-save]');
|
await click('[data-test-clients-config-save]');
|
||||||
@@ -145,8 +153,8 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
|
|
||||||
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
this.server.put('/sys/internal/counters/config', (schema, req) => {
|
||||||
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
const { enabled, retention_months } = JSON.parse(req.requestBody);
|
||||||
const expected = { enabled: 'enable', retention_months: 24 };
|
const expected = { enabled: 'enable', retention_months: 48 };
|
||||||
assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request');
|
assert.deepEqual({ enabled, retention_months }, expected, 'Correct data sent in PUT request (3)');
|
||||||
return {};
|
return {};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -155,7 +163,7 @@ module('Integration | Component | client count config', function (hooks) {
|
|||||||
await render(hbs`
|
await render(hbs`
|
||||||
<Clients::Config @model={{this.model}} @mode="edit" />
|
<Clients::Config @model={{this.model}} @mode="edit" />
|
||||||
`);
|
`);
|
||||||
await fillIn('[data-test-input="retentionMonths"]', 24);
|
await fillIn('[data-test-input="retentionMonths"]', 48);
|
||||||
await click('[data-test-clients-config-save]');
|
await click('[data-test-clients-config-save]');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,23 +59,23 @@ module('Integration | Util | client count utils', function (hooks) {
|
|||||||
const expected = [
|
const expected = [
|
||||||
{
|
{
|
||||||
previousVersion: '1.9.0',
|
previousVersion: '1.9.0',
|
||||||
timestampInstalled: '2023-08-02T00:00:00.000Z',
|
timestampInstalled: '2023-08-02T00:00:00Z',
|
||||||
version: '1.9.1',
|
version: '1.9.1',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
previousVersion: '1.9.1',
|
previousVersion: '1.9.1',
|
||||||
timestampInstalled: '2023-09-02T00:00:00.000Z',
|
timestampInstalled: '2023-09-02T00:00:00Z',
|
||||||
version: '1.10.1',
|
version: '1.10.1',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
previousVersion: '1.16.0',
|
previousVersion: '1.16.0',
|
||||||
timestampInstalled: '2023-12-02T00:00:00.000Z',
|
timestampInstalled: '2023-12-02T00:00:00Z',
|
||||||
version: '1.17.0',
|
version: '1.17.0',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
// set start/end times longer than version history to test all relevant upgrades return
|
// set start/end times longer than version history to test all relevant upgrades return
|
||||||
const startTime = '2023-06-02T00:00:00Z'; // first upgrade installed '2023-07-02T00:00:00Z'
|
const startTime = '2023-06-02T00:00:00Z'; // first upgrade installed '2023-07-02T00:00:00Z'
|
||||||
const endTime = '2024-03-04T16:14:21.000Z'; // latest upgrade installed '2023-12-02T01:00:00.000Z'
|
const endTime = '2024-03-04T16:14:21Z'; // latest upgrade installed '2023-12-02T00:00:00Z'
|
||||||
const filteredHistory = filterVersionHistory(this.versionHistory, startTime, endTime);
|
const filteredHistory = filterVersionHistory(this.versionHistory, startTime, endTime);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
JSON.stringify(filteredHistory),
|
JSON.stringify(filteredHistory),
|
||||||
@@ -99,17 +99,17 @@ module('Integration | Util | client count utils', function (hooks) {
|
|||||||
const expected = [
|
const expected = [
|
||||||
{
|
{
|
||||||
previousVersion: '1.9.0',
|
previousVersion: '1.9.0',
|
||||||
timestampInstalled: '2023-08-02T00:00:00.000Z',
|
timestampInstalled: '2023-08-02T00:00:00Z',
|
||||||
version: '1.9.1',
|
version: '1.9.1',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
previousVersion: '1.9.1',
|
previousVersion: '1.9.1',
|
||||||
timestampInstalled: '2023-09-02T00:00:00.000Z',
|
timestampInstalled: '2023-09-02T00:00:00Z',
|
||||||
version: '1.10.1',
|
version: '1.10.1',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const startTime = '2023-08-02T00:00:00.000Z'; // same date as 1.9.1 install date to catch same day edge cases
|
const startTime = '2023-08-02T00:00:00Z'; // same date as 1.9.1 install date to catch same day edge cases
|
||||||
const endTime = '2023-11-02T00:00:00.000Z';
|
const endTime = '2023-11-02T00:00:00Z';
|
||||||
const filteredHistory = filterVersionHistory(this.versionHistory, startTime, endTime);
|
const filteredHistory = filterVersionHistory(this.versionHistory, startTime, endTime);
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
JSON.stringify(filteredHistory),
|
JSON.stringify(filteredHistory),
|
||||||
@@ -121,7 +121,7 @@ module('Integration | Util | client count utils', function (hooks) {
|
|||||||
{
|
{
|
||||||
version: '1.10.3',
|
version: '1.10.3',
|
||||||
previousVersion: '1.10.1',
|
previousVersion: '1.10.1',
|
||||||
timestampInstalled: '2023-09-23T00:00:00.000Z',
|
timestampInstalled: '2023-09-23T00:00:00Z',
|
||||||
},
|
},
|
||||||
'it does not return subsequent patch versions of the same notable upgrade version'
|
'it does not return subsequent patch versions of the same notable upgrade version'
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user