From 17d29f983c3facf5815ff98ae90de5a201713292 Mon Sep 17 00:00:00 2001 From: claire bontempo <68122737+hellobontempo@users.noreply.github.com> Date: Wed, 30 Oct 2024 09:10:22 -0700 Subject: [PATCH] UI: Upgrade Ember data 5.3.2 (and upgrade minor versions of `ember-source` and `ember-cli`) (#28798) * upgrade ember-data 5.3.2, uninstall legacy compat, upgrade ember-cli, ember-source * use query instead of findAll for auth methods, update tests * set mutableId for kmip * show generated private key data before transitioning to details * update kv metadata test * remove deprecated methods from path help service * add changelog, update readme version matrix * remove toggle template helper --- changelog/28798.txt | 3 + ui/README.md | 25 +- ui/app/adapters/auth-method.js | 34 +- ui/app/adapters/kmip/config.js | 11 +- ui/app/components/pgp-file.js | 3 + ui/app/routes/vault/cluster/access/method.js | 40 +- ui/app/routes/vault/cluster/access/methods.js | 2 +- .../settings/auth/configure/section.js | 2 +- ui/app/services/path-help.js | 7 - ui/app/templates/components/pgp-file.hbs | 2 +- ui/lib/kmip/addon/routes/configure.js | 2 +- ui/lib/pki/addon/components/pki-key-form.hbs | 125 +-- ui/lib/pki/addon/components/pki-key-form.ts | 10 +- ui/lib/pki/addon/routes/roles/create.js | 6 + ui/package.json | 7 +- ui/tests/acceptance/access/methods-test.js | 72 +- .../pki/pki-engine-workflow-test.js | 8 +- .../acceptance/settings/auth/enable-test.js | 38 +- ui/tests/pages/access/methods.js | 24 - ui/tests/unit/adapters/auth-method-test.js | 4 +- ui/tests/unit/adapters/kv/metadata-test.js | 2 +- ui/yarn.lock | 898 ++++++++++-------- 22 files changed, 705 insertions(+), 620 deletions(-) create mode 100644 changelog/28798.txt delete mode 100644 ui/tests/pages/access/methods.js diff --git a/changelog/28798.txt b/changelog/28798.txt new file mode 100644 index 0000000000..992e240ee6 --- /dev/null +++ b/changelog/28798.txt @@ -0,0 +1,3 @@ +```release-note:change +ui: Upgrade Ember data to v5.3.2 (and minor upgrade of ember-cli, ember-source to v5.8.0) +``` diff --git a/ui/README.md b/ui/README.md index 385ac068dd..b6d69f492b 100644 --- a/ui/README.md +++ b/ui/README.md @@ -24,20 +24,19 @@ This README outlines the details of collaborating on this Ember application. -## Ember CLI Version Upgrade Matrix +## Ember Version Upgrade Matrix -| Vault Version | Ember Version | -| ------------- | ------------- | -| 1.17.x | 5.4.2 | -| 1.15.x | 4.12.0 | -| 1.14.x | 4.4.0 | -| 1.13.x | 4.4.0 | -| 1.12.x | 3.28.5 | -| 1.11.x | 3.28.5 | -| 1.10.x | 3.28.5 | -| 1.9.x | 3.22.0 | -| 1.8.x | 3.22.0 | -| 1.7.x | 3.11.0 | +Respective versions for `ember-cli`, `ember-source` and `ember-data` for each version of Vault that contains an upgrade. + +| Vault Version | Ember CLI | Ember Source | Ember Data | +| ------------- | --------- | ------------ | ---------- | +| 1.19.x | 5.8.0 | 5.8.0 | 5.3.2 | +| 1.17.x | 5.4.2 | 5.4.0 | 4.12.4 | +| 1.15.x | 4.12.1 | 4.12.0 | 4.11.3 | +| 1.13.x | 4.4.0 | 4.4.4 | 4.5.0 | +| 1.11.x | 3.28.5 | 3.28.10 | 3.28.6 | +| 1.10.x | 3.24.0 | 3.24.7 | 3.24.0 | +| 1.9.x | 3.22.0 | 3.22.0 | 3.22.0 | ## Prerequisites diff --git a/ui/app/adapters/auth-method.js b/ui/app/adapters/auth-method.js index f23146de3a..418e0e3366 100644 --- a/ui/app/adapters/auth-method.js +++ b/ui/app/adapters/auth-method.js @@ -23,26 +23,21 @@ export default ApplicationAdapter.extend({ const isUnauthenticated = snapshotRecordArray?.adapterOptions?.unauthenticated; // sys/internal/ui/mounts returns the actual value of the system TTL // instead of '0' which just indicates the mount is using system defaults - const useMountsEndpoint = snapshotRecordArray?.adapterOptions?.useMountsEndpoint; - if (isUnauthenticated || useMountsEndpoint) { + if (isUnauthenticated) { const url = `/${this.urlPrefix()}/internal/ui/mounts`; return this.ajax(url, 'GET', { - unauthenticated: isUnauthenticated, + unauthenticated: true, }) .then((result) => { return { data: result.data.auth, }; }) - .catch((e) => { - if (isUnauthenticated) return { data: {} }; - - if (e instanceof AdapterError) { - set(e, 'policyPath', 'sys/internal/ui/mounts'); - } - throw e; + .catch(() => { + return { data: {} }; }); } + // if authenticated, findAll will use GET sys/auth instead return this.ajax(this.url(), 'GET').catch((e) => { if (e instanceof AdapterError) { set(e, 'policyPath', 'sys/auth'); @@ -51,6 +46,25 @@ export default ApplicationAdapter.extend({ }); }, + // findAll makes a network request and supplements the ember-data store with what the API returns. + // after upgrading to ember-data 5.3.2 the store was becoming cluttered with outdated records, so + // use query to refresh the store with each request. this is ideal for list views + query() { + const url = `/${this.urlPrefix()}/internal/ui/mounts`; + return this.ajax(url, 'GET') + .then((result) => { + return { + data: result.data.auth, + }; + }) + .catch((e) => { + if (e instanceof AdapterError) { + set(e, 'policyPath', 'sys/internal/ui/mounts'); + } + throw e; + }); + }, + createRecord(store, type, snapshot) { const serializer = store.serializerFor(type.modelName); const data = serializer.serialize(snapshot); diff --git a/ui/app/adapters/kmip/config.js b/ui/app/adapters/kmip/config.js index 2c659c04a6..80e08b7755 100644 --- a/ui/app/adapters/kmip/config.js +++ b/ui/app/adapters/kmip/config.js @@ -16,9 +16,18 @@ export default BaseAdapter.extend({ return this._url(...arguments); }, urlForCreateRecord(modelName, snapshot) { - return this._url(snapshot.id, modelName, snapshot); + const id = snapshot.record.mutableId; + return this._url(id, modelName, snapshot); }, urlForUpdateRecord() { return this._url(...arguments); }, + + createRecord(store, type, snapshot) { + return this._super(...arguments).then(() => { + // saving returns a 204, return object with id to please ember-data... + const id = snapshot.record.mutableId; + return { id }; + }); + }, }); diff --git a/ui/app/components/pgp-file.js b/ui/app/components/pgp-file.js index 20f4e54e07..3cdc9c2715 100644 --- a/ui/app/components/pgp-file.js +++ b/ui/app/components/pgp-file.js @@ -64,6 +64,9 @@ export default Component.extend({ ), actions: { + handleToggle(e) { + set(this.key, 'enterAsText', e.target.checked); + }, pickedFile(e) { const { files } = e.target; if (!files.length) { diff --git a/ui/app/routes/vault/cluster/access/method.js b/ui/app/routes/vault/cluster/access/method.js index 1eeb581bdf..a102b9c3df 100644 --- a/ui/app/routes/vault/cluster/access/method.js +++ b/ui/app/routes/vault/cluster/access/method.js @@ -15,28 +15,26 @@ export default Route.extend({ model(params) { const { path } = params; - return this.store - .findAll('auth-method', { adapterOptions: { useMountsEndpoint: true } }) - .then((modelArray) => { - const model = modelArray.find((m) => m.id === path); - if (!model) { - const error = new AdapterError(); - set(error, 'httpStatus', 404); - throw error; - } - const supportManaged = supportedManagedAuthBackends(); - if (!supportManaged.includes(model.methodType)) { - // do not fetch path-help for unmanaged auth types - model.set('paths', { - apiPath: model.apiPath, - paths: [], - }); - return model; - } - return this.pathHelp.getPaths(model.apiPath, path).then((paths) => { - model.set('paths', paths); - return model; + return this.store.query('auth-method', {}).then((modelArray) => { + const model = modelArray.find((m) => m.id === path); + if (!model) { + const error = new AdapterError(); + set(error, 'httpStatus', 404); + throw error; + } + const supportManaged = supportedManagedAuthBackends(); + if (!supportManaged.includes(model.methodType)) { + // do not fetch path-help for unmanaged auth types + model.set('paths', { + apiPath: model.apiPath, + paths: [], }); + return model; + } + return this.pathHelp.getPaths(model.apiPath, path).then((paths) => { + model.set('paths', paths); + return model; }); + }); }, }); diff --git a/ui/app/routes/vault/cluster/access/methods.js b/ui/app/routes/vault/cluster/access/methods.js index bb7bfe4b00..e522e7e14b 100644 --- a/ui/app/routes/vault/cluster/access/methods.js +++ b/ui/app/routes/vault/cluster/access/methods.js @@ -19,6 +19,6 @@ export default class VaultClusterAccessMethodsRoute extends Route { }; model() { - return this.store.findAll('auth-method'); + return this.store.query('auth-method', {}); } } diff --git a/ui/app/routes/vault/cluster/settings/auth/configure/section.js b/ui/app/routes/vault/cluster/settings/auth/configure/section.js index 0111f636ee..a5977f6dd2 100644 --- a/ui/app/routes/vault/cluster/settings/auth/configure/section.js +++ b/ui/app/routes/vault/cluster/settings/auth/configure/section.js @@ -86,7 +86,7 @@ export default Route.extend(UnloadModelRoute, { // if you haven't saved a config, the API 404s, so create one here to edit and return it if (e.httpStatus === 404) { config = this.store.createRecord(modelType, { - id: backend.id, + mutableId: backend.id, }); config.set('backend', backend); diff --git a/ui/app/services/path-help.js b/ui/app/services/path-help.js index 3d05344a93..4029c6f885 100644 --- a/ui/app/services/path-help.js +++ b/ui/app/services/path-help.js @@ -49,13 +49,6 @@ export default class PathHelpService extends Service { // bust cache in EmberData's model lookup delete store._modelFactoryCache[modelType]; - - // bust cache in schema service - const schemas = store.getSchemaDefinitionService?.(); - if (schemas) { - delete schemas._relationshipsDefCache[modelType]; - delete schemas._attributesDefCache[modelType]; - } } /** diff --git a/ui/app/templates/components/pgp-file.hbs b/ui/app/templates/components/pgp-file.hbs index 6dbce8385c..bd4a40942e 100644 --- a/ui/app/templates/components/pgp-file.hbs +++ b/ui/app/templates/components/pgp-file.hbs @@ -23,7 +23,7 @@ name={{concat "useText-" this.elementId}} class="toggle is-success is-small" checked={{this.key.enterAsText}} - onchange={{action (toggle "enterAsText" this.key)}} + onchange={{action "handleToggle"}} />