From d66520d12b4451c44a456f86177c36a97e82cc9d Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Thu, 6 Jul 2023 16:01:32 -0400 Subject: [PATCH] backport of commit 4fd4a0693db30825109de89f23d84b0bc7db663c (#21402) Co-authored-by: Angel Garbarino --- ui/app/serializers/clients/config.js | 22 ++++++++++++------- .../components/clients/config-test.js | 13 +++++------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ui/app/serializers/clients/config.js b/ui/app/serializers/clients/config.js index 50bcb6331f..49be1a755f 100644 --- a/ui/app/serializers/clients/config.js +++ b/ui/app/serializers/clients/config.js @@ -1,10 +1,16 @@ import ApplicationSerializer from '../application'; -export default ApplicationSerializer.extend({ +export default class ClientsConfigSerializer extends ApplicationSerializer { + // these attrs are readOnly + attrs = { + billingStartTimestamp: { serialize: false }, + minimumRetentionMonths: { serialize: false }, + reportingEnabled: { serialize: false }, + }; + normalizeResponse(store, primaryModelClass, payload, id, requestType) { if (!payload.data) { - // CBS TODO: Remove this if block once API is published - return this._super(store, primaryModelClass, payload, id, requestType); + return super.normalizeResponse(...arguments); } const normalizedPayload = { id: payload.id, @@ -13,11 +19,11 @@ export default ApplicationSerializer.extend({ enabled: payload.data.enabled?.includes('enable') ? 'On' : 'Off', }, }; - return this._super(store, primaryModelClass, normalizedPayload, id, requestType); - }, + return super.normalizeResponse(store, primaryModelClass, normalizedPayload, id, requestType); + } serialize() { - const json = this._super(...arguments); + const json = super.serialize(...arguments); if (json.enabled === 'On' || json.enabled === 'Off') { const oldEnabled = json.enabled; json.enabled = oldEnabled === 'On' ? 'enable' : 'disable'; @@ -28,5 +34,5 @@ export default ApplicationSerializer.extend({ } delete json.queries_available; return json; - }, -}); + } +} diff --git a/ui/tests/integration/components/clients/config-test.js b/ui/tests/integration/components/clients/config-test.js index 045066ee6f..72179af2e7 100644 --- a/ui/tests/integration/components/clients/config-test.js +++ b/ui/tests/integration/components/clients/config-test.js @@ -13,7 +13,7 @@ module('Integration | Component | client count config', function (hooks) { this.router = this.owner.lookup('service:router'); this.transitionStub = sinon.stub(this.router, 'transitionTo'); const store = this.owner.lookup('service:store'); - this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 0) => { + this.createModel = (enabled = 'enable', reporting_enabled = false, minimum_retention_months = 24) => { store.pushPayload('clients/config', { modelName: 'clients/config', id: 'foo', @@ -51,7 +51,7 @@ module('Integration | Component | client count config', function (hooks) { this.server.put('/sys/internal/counters/config', (schema, req) => { const { enabled, retention_months } = JSON.parse(req.requestBody); - const expected = { enabled: 'enable', retention_months: 5 }; + const expected = { enabled: 'enable', retention_months: 24 }; assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request'); return {}; }); @@ -75,11 +75,11 @@ module('Integration | Component | client count config', function (hooks) { assert .dom('[data-test-inline-error-message]') .hasText( - 'Retention period must be greater than or equal to 0.', + 'Retention period must be greater than or equal to 24.', 'Validation error shows for incorrect retention period' ); - await fillIn('[data-test-input="retentionMonths"]', 5); + await fillIn('[data-test-input="retentionMonths"]', 24); await click('[data-test-clients-config-save]'); assert.dom('.modal.is-active').exists('Modal renders'); assert @@ -149,7 +149,7 @@ module('Integration | Component | client count config', function (hooks) { this.server.put('/sys/internal/counters/config', (schema, req) => { const { enabled, retention_months } = JSON.parse(req.requestBody); - const expected = { enabled: 'enable', retention_months: 5 }; + const expected = { enabled: 'enable', retention_months: 24 }; assert.deepEqual(expected, { enabled, retention_months }, 'Correct data sent in PUT request'); return {}; }); @@ -160,8 +160,7 @@ module('Integration | Component | client count config', function (hooks) { `); - - await fillIn('[data-test-input="retentionMonths"]', 5); + await fillIn('[data-test-input="retentionMonths"]', 24); await click('[data-test-clients-config-save]'); }); });