UI: Ember deprecation prep for 5.0: ember-data:deprecate-array-like (#26170)

* remove .get() from cluster and vault route

* replace .get() use in adapters

* remove .get() from components part 1

* remove .get() from string-list

* remaining components

* controller .get() removal

* remove .get() use in mixins

* routes/cluster/access* .get() replacement

* policy index route

* routes/secrets/backend*

* route/cluster*

* serializers

* is-active-route

* remaining top-level addon gets

* replication get()

* revery change that broke things

* woops, revert other store service change

* revert some controller changes

* revert get on URLSearchParams class

* remove .sortBy ember method

* small cleanup items

* small cleanups from PR review
This commit is contained in:
claire bontempo
2024-03-28 12:13:33 -07:00
committed by GitHub
parent 7d575bf979
commit 918642bd9c
53 changed files with 101 additions and 107 deletions

View File

@@ -8,6 +8,7 @@ import { encodePath } from 'vault/utils/path-encoding-helpers';
import { service } from '@ember/service'; import { service } from '@ember/service';
import AdapterError from '@ember-data/adapter/error'; import AdapterError from '@ember-data/adapter/error';
import { addManyToArray } from 'vault/helpers/add-to-array'; import { addManyToArray } from 'vault/helpers/add-to-array';
import sortObjects from 'vault/utils/sort-objects';
export default class LdapRoleAdapter extends NamedPathAdapter { export default class LdapRoleAdapter extends NamedPathAdapter {
@service flashMessages; @service flashMessages;
@@ -72,7 +73,7 @@ export default class LdapRoleAdapter extends NamedPathAdapter {
} }
// must return an object in this shape for lazyPaginatedQuery to function // must return an object in this shape for lazyPaginatedQuery to function
// changing the responsePath or providing the extractLazyPaginatedData serializer method causes normalizeResponse to return data: [undefined] // changing the responsePath or providing the extractLazyPaginatedData serializer method causes normalizeResponse to return data: [undefined]
return { data: { keys: roles.sortBy('name') } }; return { data: { keys: sortObjects(roles, 'name') } };
} }
queryRecord(store, type, query) { queryRecord(store, type, query) {
const { backend, name, type: roleType } = query; const { backend, name, type: roleType } = query;

View File

@@ -34,7 +34,7 @@ export default ApplicationAdapter.extend({
deleteRecord(store, type, snapshot) { deleteRecord(store, type, snapshot) {
const { id } = snapshot; const { id } = snapshot;
return this.ajax(this.urlForRole(snapshot.record.get('backend'), id), 'DELETE'); return this.ajax(this.urlForRole(snapshot.record.backend, id), 'DELETE');
}, },
pathForType() { pathForType() {

View File

@@ -34,7 +34,7 @@ export default ApplicationAdapter.extend({
deleteRecord(store, type, snapshot) { deleteRecord(store, type, snapshot) {
const { id } = snapshot; const { id } = snapshot;
return this.ajax(this.urlForRole(snapshot.record.get('backend'), id), 'DELETE'); return this.ajax(this.urlForRole(snapshot.record.backend, id), 'DELETE');
}, },
pathForType() { pathForType() {

View File

@@ -33,7 +33,7 @@ export default ApplicationAdapter.extend({
deleteRecord(store, type, snapshot) { deleteRecord(store, type, snapshot) {
const { id } = snapshot; const { id } = snapshot;
return this.ajax(this.urlForTransformations(snapshot.record.get('backend'), id), 'DELETE'); return this.ajax(this.urlForTransformations(snapshot.record.backend, id), 'DELETE');
}, },
pathForType() { pathForType() {

View File

@@ -36,7 +36,7 @@ export default ApplicationAdapter.extend({
deleteRecord(store, type, snapshot) { deleteRecord(store, type, snapshot) {
const { id } = snapshot; const { id } = snapshot;
return this.ajax(this.url(snapshot.record.get('backend'), type.modelName, id), 'DELETE'); return this.ajax(this.url(snapshot.record.backend, type.modelName, id), 'DELETE');
}, },
url(backend, modelType, id) { url(backend, modelType, id) {

View File

@@ -14,7 +14,7 @@ export default ApplicationAdapter.extend({
const serializer = store.serializerFor(type.modelName); const serializer = store.serializerFor(type.modelName);
const data = serializer.serialize(snapshot, requestType); const data = serializer.serialize(snapshot, requestType);
const name = snapshot.attr('name'); const name = snapshot.attr('name');
let url = this.urlForSecret(snapshot.record.get('backend'), name); let url = this.urlForSecret(snapshot.record.backend, name);
if (requestType === 'update') { if (requestType === 'update') {
url = url + '/config'; url = url + '/config';
} }
@@ -36,7 +36,7 @@ export default ApplicationAdapter.extend({
deleteRecord(store, type, snapshot) { deleteRecord(store, type, snapshot) {
const { id } = snapshot; const { id } = snapshot;
return this.ajax(this.urlForSecret(snapshot.record.get('backend'), id), 'DELETE'); return this.ajax(this.urlForSecret(snapshot.record.backend, id), 'DELETE');
}, },
pathForType(type) { pathForType(type) {

View File

@@ -105,7 +105,7 @@ export default Component.extend({
refreshRoute: task(function* () { refreshRoute: task(function* () {
const owner = getOwner(this); const owner = getOwner(this);
const currentRoute = owner.lookup(`router:main`).get('currentRouteName'); const currentRoute = owner.lookup(`router:main`).currentRouteName;
try { try {
this.store.clearAllDatasets(); this.store.clearAllDatasets();

View File

@@ -77,7 +77,7 @@ export default Component.extend({
// components are torn down after store is disconnected and will cause an error if attempt to unload record // components are torn down after store is disconnected and will cause an error if attempt to unload record
const noTeardown = this.store && !this.store.isDestroying; const noTeardown = this.store && !this.store.isDestroying;
const model = this.model; const model = this.model;
if (noTeardown && model && model.get('isDirty') && !model.isDestroyed && !model.isDestroying) { if (noTeardown && model && model.isDirty && !model.isDestroyed && !model.isDestroying) {
model.rollbackAttributes(); model.rollbackAttributes();
} }
this._super(...arguments); this._super(...arguments);

View File

@@ -60,7 +60,8 @@ export default Component.extend({
return; return;
} }
const isAdding = leaves.length > lastLeaves.length; const isAdding = leaves.length > lastLeaves.length;
const changedLeaf = (isAdding ? leaves : lastLeaves).get('lastObject'); const changedLeaves = isAdding ? leaves : lastLeaves;
const [changedLeaf] = changedLeaves.slice(-1);
this.set('isAdding', isAdding); this.set('isAdding', isAdding);
this.set('changedLeaf', changedLeaf); this.set('changedLeaf', changedLeaf);

View File

@@ -105,7 +105,7 @@ export default class SecretCreateOrUpdate extends Component {
const secret = this.args.model; const secret = this.args.model;
const secretData = this.args.modelForData; const secretData = this.args.modelForData;
let key = secretData.get('path') || secret.id; let key = secretData?.path || secret.id;
if (key.startsWith('/')) { if (key.startsWith('/')) {
key = key.replace(/^\/+/g, ''); key = key.replace(/^\/+/g, '');

View File

@@ -28,7 +28,7 @@ export default Component.extend({
isBuiltin: computed('item', 'itemType', function () { isBuiltin: computed('item', 'itemType', function () {
const item = this.item; const item = this.item;
if (this.itemType === 'alphabet' || this.itemType === 'template') { if (this.itemType === 'alphabet' || this.itemType === 'template') {
return item.get('id').startsWith('builtin/'); return item.id.startsWith('builtin/');
} }
return false; return false;
}), }),

View File

@@ -24,7 +24,7 @@ export default Controller.extend(ListController, {
actions: { actions: {
delete(model) { delete(model) {
const type = model.get('identityType'); const type = model.identityType;
const id = model.id; const id = model.id;
return model return model
.destroyRecord() .destroyRecord()
@@ -41,8 +41,8 @@ export default Controller.extend(ListController, {
}, },
toggleDisabled(model) { toggleDisabled(model) {
const action = model.get('disabled') ? ['enabled', 'enabling'] : ['disabled', 'disabling']; const action = model.disabled ? ['enabled', 'enabling'] : ['disabled', 'disabling'];
const type = model.get('identityType'); const type = model.identityType;
const id = model.id; const id = model.id;
model.toggleProperty('disabled'); model.toggleProperty('disabled');

View File

@@ -8,6 +8,7 @@ import { dropTask } from 'ember-concurrency';
import { service } from '@ember/service'; import { service } from '@ember/service';
import { action } from '@ember/object'; import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking'; import { tracked } from '@glimmer/tracking';
import sortObjects from 'vault/utils/sort-objects';
export default class VaultClusterAccessMethodsController extends Controller { export default class VaultClusterAccessMethodsController extends Controller {
@service flashMessages; @service flashMessages;
@@ -23,6 +24,7 @@ export default class VaultClusterAccessMethodsController extends Controller {
pageFilter = null; pageFilter = null;
filter = null; filter = null;
// list returned by getter is sorted in template
get authMethodList() { get authMethodList() {
// return an options list to filter by engine type, ex: 'kv' // return an options list to filter by engine type, ex: 'kv'
if (this.selectedAuthType) { if (this.selectedAuthType) {
@@ -39,7 +41,7 @@ export default class VaultClusterAccessMethodsController extends Controller {
if (this.selectedAuthName) { if (this.selectedAuthName) {
return this.model.filter((method) => this.selectedAuthName === method.id); return this.model.filter((method) => this.selectedAuthName === method.id);
} }
// no filters, return full sorted list. // no filters, return full list
return this.model; return this.model;
} }
@@ -85,4 +87,7 @@ export default class VaultClusterAccessMethodsController extends Controller {
this.methodToDisable = null; this.methodToDisable = null;
} }
} }
// template helper
sortMethods = (methods) => sortObjects(methods.slice(), 'path');
} }

View File

@@ -50,7 +50,7 @@ export default Controller.extend({
return filterMatchesKey return filterMatchesKey
? null ? null
: content.find(function (key) { : content.find(function (key) {
return re.test(key.get('id')); return re.test(key.id);
}); });
}), }),
@@ -62,7 +62,7 @@ export default Controller.extend({
this.set('filterFocused', bool); this.set('filterFocused', bool);
}, },
deletePolicy(model) { deletePolicy(model) {
const policyType = model.get('policyType'); const { policyType } = model;
const name = model.id; const name = model.id;
const flash = this.flashMessages; const flash = this.flashMessages;
model model

View File

@@ -36,7 +36,7 @@ export default Controller.extend({
newModel() { newModel() {
const model = this.model; const model = this.model;
const roleModel = model.get('role'); const roleModel = model.role;
model.unloadRecord(); model.unloadRecord();
const newModel = this.store.createRecord('ssh-sign', { const newModel = this.store.createRecord('ssh-sign', {
role: roleModel, role: roleModel,

View File

@@ -58,7 +58,7 @@ export default Route.extend({
// Assuming we have a URL, push it into browser history and update the // Assuming we have a URL, push it into browser history and update the
// location bar for the user // location bar for the user
if (errorURL) { if (errorURL) {
router.get('location').setURL(errorURL); router.location.setURL(errorURL);
} }
return true; return true;

View File

@@ -42,7 +42,7 @@ export default class VaultRoute extends Route {
} }
redirect(model, transition) { redirect(model, transition) {
if (model.get('length') === 1 && transition.targetName === 'vault.index') { if (model.length === 1 && transition.targetName === 'vault.index') {
return this.router.transitionTo('vault.cluster', model[0].name); return this.router.transitionTo('vault.cluster', model[0].name);
} }
} }

View File

@@ -51,13 +51,13 @@ export default Route.extend(ModelBoundaryRoute, ClusterRoute, {
const { cluster_name } = params; const { cluster_name } = params;
const records = this.store.peekAll('cluster'); const records = this.store.peekAll('cluster');
const cluster = records.find((record) => record.name === cluster_name); const cluster = records.find((record) => record.name === cluster_name);
return cluster ? cluster.get('id') : null; return cluster?.id ?? null;
}, },
async beforeModel() { async beforeModel() {
const params = this.paramsFor(this.routeName); const params = this.paramsFor(this.routeName);
let namespace = params.namespaceQueryParam; let namespace = params.namespaceQueryParam;
const currentTokenName = this.auth.get('currentTokenName'); const currentTokenName = this.auth.currentTokenName;
const managedRoot = this.featureFlagService.managedNamespaceRoot; const managedRoot = this.featureFlagService.managedNamespaceRoot;
assert( assert(
'Cannot use VAULT_CLOUD_ADMIN_NAMESPACE flag with non-enterprise Vault version', 'Cannot use VAULT_CLOUD_ADMIN_NAMESPACE flag with non-enterprise Vault version',

View File

@@ -30,7 +30,7 @@ export default Route.extend({
let model = this.store.peekRecord(modelType, params.item_id); let model = this.store.peekRecord(modelType, params.item_id);
// if we don't have creationTime, we only have a partial model so reload // if we don't have creationTime, we only have a partial model so reload
if (model && !model.get('creationTime')) { if (model && !model?.creationTime) {
model = model.reload(); model = model.reload();
} }
@@ -51,14 +51,14 @@ export default Route.extend({
if (this.currentModel) { if (this.currentModel) {
next(() => { next(() => {
/* eslint-disable-next-line ember/no-controller-access-in-routes */ /* eslint-disable-next-line ember/no-controller-access-in-routes */
this.controller.get('model').reload(); this.controller.model.reload();
}); });
} }
}, },
afterModel(resolvedModel) { afterModel(resolvedModel) {
const { section, model } = resolvedModel; const { section, model } = resolvedModel;
if (model.get('identityType') === 'group' && model.get('type') === 'internal' && section === 'aliases') { if (model?.identityType === 'group' && model?.type === 'internal' && section === 'aliases') {
return this.router.transitionTo('vault.cluster.access.identity.show', model.id, 'details'); return this.router.transitionTo('vault.cluster.access.identity.show', model.id, 'details');
} }
}, },

View File

@@ -10,10 +10,7 @@ export default class LeasesIndexRoute extends Route {
@service router; @service router;
beforeModel(transition) { beforeModel(transition) {
if ( if (this.modelFor('vault.cluster.access.leases').canList && transition.targetName === this.routeName) {
this.modelFor('vault.cluster.access.leases').get('canList') &&
transition.targetName === this.routeName
) {
return this.router.replaceWith('vault.cluster.access.leases.list-root'); return this.router.replaceWith('vault.cluster.access.leases.list-root');
} else { } else {
return; return;

View File

@@ -24,7 +24,7 @@ export default Route.extend({
model(params) { model(params) {
const prefix = params.prefix || ''; const prefix = params.prefix || '';
if (this.modelFor('vault.cluster.access.leases').get('canList')) { if (this.modelFor('vault.cluster.access.leases').canList) {
return hash({ return hash({
leases: this.store leases: this.store
.lazyPaginatedQuery('lease', { .lazyPaginatedQuery('lease', {
@@ -73,7 +73,7 @@ export default Route.extend({
} }
controller.setProperties({ controller.setProperties({
filter: filter || '', filter: filter || '',
page: model.leases.get('meta.currentPage'), page: model.leases?.meta?.currentPage,
}); });
} }
}, },
@@ -91,7 +91,7 @@ export default Route.extend({
set(error, 'keyId', prefix); set(error, 'keyId', prefix);
/* eslint-disable-next-line ember/no-controller-access-in-routes */ /* eslint-disable-next-line ember/no-controller-access-in-routes */
const hasModel = this.controllerFor(this.routeName).get('hasModel'); const hasModel = this.controllerFor(this.routeName).hasModel;
// only swallow the error if we have a previous model // only swallow the error if we have a previous model
if (hasModel && error.httpStatus === 404) { if (hasModel && error.httpStatus === 404) {
this.set('has404', true); this.set('has404', true);

View File

@@ -63,7 +63,7 @@ export default Route.extend(UnloadModel, {
actions: { actions: {
error(error, transition) { error(error, transition) {
/* eslint-disable-next-line ember/no-controller-access-in-routes */ /* eslint-disable-next-line ember/no-controller-access-in-routes */
const hasModel = this.controllerFor(this.routeName).get('hasModel'); const hasModel = this.controllerFor(this.routeName).hasModel;
if (hasModel && error.httpStatus === 404) { if (hasModel && error.httpStatus === 404) {
this.set('has404', true); this.set('has404', true);
transition.abort(); transition.abort();

View File

@@ -29,7 +29,7 @@ export default class VaultClusterOidcProviderRoute extends Route {
} }
beforeModel(transition) { beforeModel(transition) {
const currentToken = this.auth.get('currentTokenName'); const currentToken = this.auth.currentTokenName;
const qp = transition.to.queryParams; const qp = transition.to.queryParams;
// remove redirect_to if carried over from auth // remove redirect_to if carried over from auth
qp.redirect_to = null; qp.redirect_to = null;

View File

@@ -13,7 +13,7 @@ export default Route.extend(ClusterRoute, ListRoute, {
version: service(), version: service(),
shouldReturnEmptyModel(policyType, version) { shouldReturnEmptyModel(policyType, version) {
return policyType !== 'acl' && (version.get('isCommunity') || !version.get('hasSentinel')); return policyType !== 'acl' && (version.isCommunity || !version.hasSentinel);
}, },
model(params) { model(params) {
@@ -49,7 +49,7 @@ export default Route.extend(ClusterRoute, ListRoute, {
controller.setProperties({ controller.setProperties({
model, model,
filter: params.pageFilter || '', filter: params.pageFilter || '',
page: model.get('meta.currentPage') || 1, page: model.meta?.currentPage || 1,
policyType: this.policyType(), policyType: this.policyType(),
}); });
}, },

View File

@@ -27,7 +27,7 @@ export default Route.extend({
}, },
afterModel(model, transition) { afterModel(model, transition) {
const path = model && model.get('path'); const path = model && model.path;
if (transition.targetName === this.routeName) { if (transition.targetName === this.routeName) {
return this.router.replaceWith('vault.cluster.secrets.backend.list-root', path); return this.router.replaceWith('vault.cluster.secrets.backend.list-root', path);
} }

View File

@@ -16,10 +16,6 @@ export default Route.extend({
router: service(), router: service(),
store: service(), store: service(),
backendModel() {
return this.modelFor('vault.cluster.secrets.backend');
},
beforeModel() { beforeModel() {
const { backend } = this.paramsFor('vault.cluster.secrets.backend'); const { backend } = this.paramsFor('vault.cluster.secrets.backend');
if (backend != 'ssh') { if (backend != 'ssh') {
@@ -57,15 +53,13 @@ export default Route.extend({
async model(params) { async model(params) {
const role = params.secret; const role = params.secret;
const backendModel = this.backendModel(); const { id: backendPath, type: backendType } = this.modelFor('vault.cluster.secrets.backend');
const backendPath = backendModel.get('id');
const backendType = backendModel.get('type');
const roleType = params.roleType; const roleType = params.roleType;
let dbCred; let dbCred;
if (backendType === 'database') { if (backendType === 'database') {
dbCred = await this.getDatabaseCredential(backendPath, role, roleType); dbCred = await this.getDatabaseCredential(backendPath, role, roleType);
} }
if (!SUPPORTED_DYNAMIC_BACKENDS.includes(backendModel.get('type'))) { if (!SUPPORTED_DYNAMIC_BACKENDS.includes(backendType)) {
return this.router.transitionTo('vault.cluster.secrets.backend.list-root', backendPath); return this.router.transitionTo('vault.cluster.secrets.backend.list-root', backendPath);
} }
return resolve({ return resolve({

View File

@@ -146,7 +146,7 @@ export default Route.extend({
const backendModel = this.store.peekRecord('secret-engine', backend); const backendModel = this.store.peekRecord('secret-engine', backend);
const has404 = this.has404; const has404 = this.has404;
// only clear store cache if this is a new model // only clear store cache if this is a new model
if (secret !== controller.get('baseKey.id')) { if (secret !== controller?.baseKey?.id) {
this.store.clearAllDatasets(); this.store.clearAllDatasets();
} }
controller.set('hasModel', true); controller.set('hasModel', true);
@@ -156,7 +156,7 @@ export default Route.extend({
backend, backend,
backendModel, backendModel,
baseKey: { id: secret }, baseKey: { id: secret },
backendType: backendModel.get('engineType'), backendType: backendModel.engineType,
}); });
if (!has404) { if (!has404) {
const pageFilter = secretParams.pageFilter; const pageFilter = secretParams.pageFilter;
@@ -187,7 +187,7 @@ export default Route.extend({
const backend = this.enginePathParam(); const backend = this.enginePathParam();
const is404 = error.httpStatus === 404; const is404 = error.httpStatus === 404;
/* eslint-disable-next-line ember/no-controller-access-in-routes */ /* eslint-disable-next-line ember/no-controller-access-in-routes */
const hasModel = this.controllerFor(this.routeName).get('hasModel'); const hasModel = this.controllerFor(this.routeName).hasModel;
// this will occur if we've deleted something, // this will occur if we've deleted something,
// and navigate to its parent and the parent doesn't exist - // and navigate to its parent and the parent doesn't exist -

View File

@@ -68,7 +68,7 @@ export default Route.extend({
}, },
backendType() { backendType() {
return this.modelFor('vault.cluster.secrets.backend').get('engineType'); return this.modelFor('vault.cluster.secrets.backend').engineType;
}, },
templateName: 'vault/cluster/secrets/backend/secretEditLayout', templateName: 'vault/cluster/secrets/backend/secretEditLayout',
@@ -116,7 +116,7 @@ export default Route.extend({
modelType(backend, secret, options = {}) { modelType(backend, secret, options = {}) {
const backendModel = this.modelFor('vault.cluster.secrets.backend', backend); const backendModel = this.modelFor('vault.cluster.secrets.backend', backend);
const type = backendModel.get('engineType'); const { engineType } = backendModel;
const types = { const types = {
database: secret && secret.startsWith('role/') ? 'database/role' : 'database/connection', database: secret && secret.startsWith('role/') ? 'database/role' : 'database/connection',
transit: 'transit-key', transit: 'transit-key',
@@ -128,12 +128,12 @@ export default Route.extend({
keymgmt: `keymgmt/${options.queryParams?.itemType || 'key'}`, keymgmt: `keymgmt/${options.queryParams?.itemType || 'key'}`,
generic: 'secret', generic: 'secret',
}; };
return types[type]; return types[engineType];
}, },
handleSecretModelError(capabilities, secretId, modelType, error) { handleSecretModelError(capabilities, secretId, modelType, error) {
// can't read the path and don't have update capability, so re-throw // can't read the path and don't have update capability, so re-throw
if (!capabilities.get('canUpdate') && modelType === 'secret') { if (!capabilities.canUpdate && modelType === 'secret') {
throw error; throw error;
} }
this.store.push({ this.store.push({
@@ -192,7 +192,7 @@ export default Route.extend({
const backend = this.enginePathParam(); const backend = this.enginePathParam();
const preferAdvancedEdit = const preferAdvancedEdit =
/* eslint-disable-next-line ember/no-controller-access-in-routes */ /* eslint-disable-next-line ember/no-controller-access-in-routes */
this.controllerFor('vault.cluster.secrets.backend').get('preferAdvancedEdit') || false; this.controllerFor('vault.cluster.secrets.backend').preferAdvancedEdit || false;
const backendType = this.backendType(); const backendType = this.backendType();
model.secret.setProperties({ backend }); model.secret.setProperties({ backend });
controller.setProperties({ controller.setProperties({

View File

@@ -29,13 +29,13 @@ export default Route.extend(UnloadModel, {
model(params) { model(params) {
const role = params.secret; const role = params.secret;
const backendModel = this.backendModel(); const backendModel = this.backendModel();
const backend = backendModel.get('id'); const backend = backendModel.id;
if (backendModel.get('type') !== 'ssh') { if (backendModel.type !== 'ssh') {
return this.router.transitionTo('vault.cluster.secrets.backend.list-root', backend); return this.router.transitionTo('vault.cluster.secrets.backend.list-root', backend);
} }
return this.store.queryRecord('capabilities', this.pathQuery(role, backend)).then((capabilities) => { return this.store.queryRecord('capabilities', this.pathQuery(role, backend)).then((capabilities) => {
if (!capabilities.get('canUpdate')) { if (!capabilities.canUpdate) {
return this.router.transitionTo('vault.cluster.secrets.backend.list-root', backend); return this.router.transitionTo('vault.cluster.secrets.backend.list-root', backend);
} }
return this.store.createRecord('ssh-sign', { return this.store.createRecord('ssh-sign', {

View File

@@ -53,7 +53,7 @@ export default Route.extend(UnloadModelRoute, {
section, section,
}); });
} }
const modelType = this.modelType(backend.get('type'), section); const modelType = this.modelType(backend.type, section);
if (!modelType) { if (!modelType) {
const error = new AdapterError(); const error = new AdapterError();
set(error, 'httpStatus', 404); set(error, 'httpStatus', 404);

View File

@@ -16,7 +16,7 @@ export default Route.extend({
const { backend } = this.paramsFor(this.routeName); const { backend } = this.paramsFor(this.routeName);
return this.store.query('secret-engine', { path: backend }).then((modelList) => { return this.store.query('secret-engine', { path: backend }).then((modelList) => {
const model = modelList && modelList[0]; const model = modelList && modelList[0];
if (!model || !CONFIGURABLE_BACKEND_TYPES.includes(model.get('type'))) { if (!model || !CONFIGURABLE_BACKEND_TYPES.includes(model.type)) {
const error = new AdapterError(); const error = new AdapterError();
set(error, 'httpStatus', 404); set(error, 'httpStatus', 404);
throw error; throw error;
@@ -33,7 +33,7 @@ export default Route.extend({
}, },
afterModel(model) { afterModel(model) {
const type = model.get('type'); const type = model.type;
if (type === 'aws') { if (type === 'aws') {
return this.store return this.store
@@ -50,7 +50,7 @@ export default Route.extend({
}, },
setupController(controller, model) { setupController(controller, model) {
if (model.get('publicKey')) { if (model.publicKey) {
controller.set('configured', true); controller.set('configured', true);
} }
return this._super(...arguments); return this._super(...arguments);

View File

@@ -66,10 +66,7 @@ export default RESTSerializer.extend({
serializeAttribute(snapshot, json, key, attributes) { serializeAttribute(snapshot, json, key, attributes) {
// Don't send values that are undefined // Don't send values that are undefined
if ( if (snapshot.attr(key) !== undefined && (snapshot.record.isNew || snapshot.changedAttributes()[key])) {
undefined !== snapshot.attr(key) &&
(snapshot.record.get('isNew') || snapshot.changedAttributes()[key])
) {
this._super(snapshot, json, key, attributes); this._super(snapshot, json, key, attributes);
} }
}, },

View File

@@ -78,7 +78,7 @@ export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
}, },
serialize(snapshot) { serialize(snapshot) {
const type = snapshot.record.get('engineType'); const type = snapshot.record.engineType;
const data = this._super(...arguments); const data = this._super(...arguments);
// move version back to options // move version back to options
data.options = data.version ? { version: data.version } : {}; data.options = data.version ? { version: data.version } : {};

View File

@@ -46,7 +46,7 @@
</ToolbarActions> </ToolbarActions>
</Toolbar> </Toolbar>
{{#each (sort-by "path" this.authMethodList) as |method|}} {{#each (this.sortMethods this.authMethodList) as |method|}}
<LinkedBlock <LinkedBlock
@params={{array "vault.cluster.access.method" method.id}} @params={{array "vault.cluster.access.method" method.id}}
class="list-item-row" class="list-item-row"

View File

@@ -3,6 +3,10 @@
* SPDX-License-Identifier: BUSL-1.1 * SPDX-License-Identifier: BUSL-1.1
*/ */
/*
this util sorts the original array
pass in a copy of the array, i.e. myArray.slice(), if you do not want to modify the original array
*/
export default function sortObjects(array, key) { export default function sortObjects(array, key) {
if (Array.isArray(array) && array?.every((e) => e[key] && typeof e[key] === 'string')) { if (Array.isArray(array) && array?.every((e) => e[key] && typeof e[key] === 'string')) {
return array.sort((a, b) => { return array.sort((a, b) => {

View File

@@ -40,7 +40,7 @@ export default class MessagesList extends Component {
super.willDestroy(); super.willDestroy();
const noTeardown = this.store && !this.store.isDestroying; const noTeardown = this.store && !this.store.isDestroying;
const { model } = this; const { model } = this;
if (noTeardown && model && model.get('isDirty') && !model.isDestroyed && !model.isDestroying) { if (noTeardown && model && model.isDirty && !model.isDestroyed && !model.isDestroying) {
model.rollbackAttributes(); model.rollbackAttributes();
} }
} }

View File

@@ -71,7 +71,7 @@ export default Component.extend({
return; return;
} }
if (this.flashEnabled) { if (this.flashEnabled) {
this.flashMessages.success(this.get(messageKey)); this.flashMessages.success(this[messageKey]);
} }
if (this.callOnSaveAfterRender) { if (this.callOnSaveAfterRender) {
next(() => { next(() => {
@@ -87,7 +87,7 @@ export default Component.extend({
// components are torn down after store is unloaded and will cause an error if attempt to unload record // components are torn down after store is unloaded and will cause an error if attempt to unload record
const noTeardown = this.store && !this.store.isDestroying; const noTeardown = this.store && !this.store.isDestroying;
const { model } = this; const { model } = this;
if (noTeardown && model && model.get('isDirty') && !model.isDestroyed && !model.isDestroying) { if (noTeardown && model && model.isDirty && !model.isDestroyed && !model.isDestroying) {
model.rollbackAttributes(); model.rollbackAttributes();
} }
this._super(...arguments); this._super(...arguments);

View File

@@ -50,7 +50,7 @@ export default class KvObjectEditor extends Component {
}; };
} }
get hasDuplicateKeys() { get hasDuplicateKeys() {
return this.kvData.uniqBy('name').length !== this.kvData.get('length'); return this.kvData.uniqBy('name').length !== this.kvData.length;
} }
// fired on did-insert from render modifier // fired on did-insert from render modifier

View File

@@ -106,9 +106,9 @@ export default class StringList extends Component {
@action @action
addInput() { addInput() {
const inputList = this.inputList; const [lastItem] = this.inputList.slice(-1);
if (inputList.get('lastObject.value') !== '') { if (lastItem?.value !== '') {
inputList.pushObject({ value: '' }); this.inputList.pushObject({ value: '' });
} }
} }

View File

@@ -21,8 +21,8 @@ export default Helper.extend({
compute([routeName, model], { isExact }) { compute([routeName, model], { isExact }) {
const router = this.router; const router = this.router;
const currentRoute = router.get('currentRouteName'); const currentRoute = router.currentRouteName;
let currentURL = router.get('currentURL'); let currentURL = router.currentURL;
// if we have any query params we want to discard them // if we have any query params we want to discard them
currentURL = currentURL?.split('?')[0]; currentURL = currentURL?.split('?')[0];
const comparator = isExact ? exact : startsWith; const comparator = isExact ? exact : startsWith;

View File

@@ -9,7 +9,7 @@ export function pathOrArray([maybeArray, target]) {
if (Array.isArray(maybeArray)) { if (Array.isArray(maybeArray)) {
return maybeArray; return maybeArray;
} }
return target.get(maybeArray); return target[maybeArray];
} }
export default buildHelper(pathOrArray); export default buildHelper(pathOrArray);

View File

@@ -30,7 +30,7 @@ export default Component.extend({
if (model.operationNone) { if (model.operationNone) {
return falseString; return falseString;
} }
return model.get(field.name) ? trueString : falseString; return model[field.name] ? trueString : falseString;
}, },
actions: { actions: {

View File

@@ -29,13 +29,13 @@ export default class SwaggerUiComponent extends Component {
return ( return (
taggedOps taggedOps
.map((tagObj) => { .map((tagObj) => {
const operations = tagObj.get('operations').filter((operationObj) => { const operations = tagObj.operations.filter((operationObj) => {
return operationObj.get('path').includes(phrase); return operationObj.path.includes(phrase);
}); });
return tagObj.set('operations', operations); return tagObj.set('operations', operations);
}) })
// then traverse again and remove the top level item if there are no operations left after filtering // then traverse again and remove the top level item if there are no operations left after filtering
.filter((tagObj) => !!tagObj.get('operations').size) .filter((tagObj) => !!tagObj.operations.size)
); );
}, },
}, },

View File

@@ -14,7 +14,7 @@ export default Controller.extend({
replicationMode: alias('rm.mode'), replicationMode: alias('rm.mode'),
actions: { actions: {
resetConfig(config) { resetConfig(config) {
if (config.get('isNew')) { if (config.isNew) {
config.setProperties({ config.setProperties({
mode: null, mode: null,
paths: [], paths: [],

View File

@@ -33,10 +33,10 @@ export default Route.extend(ClusterRoute, {
return hash({ return hash({
canEnablePrimary: this.store canEnablePrimary: this.store
.findRecord('capabilities', 'sys/replication/primary/enable') .findRecord('capabilities', 'sys/replication/primary/enable')
.then((c) => c.get('canUpdate')), .then((c) => c.canUpdate),
canEnableSecondary: this.store canEnableSecondary: this.store
.findRecord('capabilities', 'sys/replication/secondary/enable') .findRecord('capabilities', 'sys/replication/secondary/enable')
.then((c) => c.get('canUpdate')), .then((c) => c.canUpdate),
}).then(({ canEnablePrimary, canEnableSecondary }) => { }).then(({ canEnablePrimary, canEnableSecondary }) => {
setProperties(model, { setProperties(model, {
canEnablePrimary, canEnablePrimary,

View File

@@ -18,10 +18,10 @@ export default Route.extend({
cluster: this.modelFor('mode'), cluster: this.modelFor('mode'),
canAddSecondary: this.store canAddSecondary: this.store
.findRecord('capabilities', `sys/replication/${replicationMode}/primary/secondary-token`) .findRecord('capabilities', `sys/replication/${replicationMode}/primary/secondary-token`)
.then((c) => c.get('canUpdate')), .then((c) => c.canUpdate),
canRevokeSecondary: this.store canRevokeSecondary: this.store
.findRecord('capabilities', `sys/replication/${replicationMode}/primary/revoke-secondary`) .findRecord('capabilities', `sys/replication/${replicationMode}/primary/revoke-secondary`)
.then((c) => c.get('canUpdate')), .then((c) => c.canUpdate),
}).then(({ cluster, canAddSecondary, canRevokeSecondary }) => { }).then(({ cluster, canAddSecondary, canRevokeSecondary }) => {
setProperties(cluster, { setProperties(cluster, {
canRevokeSecondary, canRevokeSecondary,

View File

@@ -27,12 +27,12 @@ export default Route.extend({
const model = this.modelFor('mode'); const model = this.modelFor('mode');
const replicationMode = this.paramsFor('mode').replication_mode; const replicationMode = this.paramsFor('mode').replication_mode;
const clusterMode = model.get(replicationMode).get('modeForUrl'); const clusterMode = model[replicationMode].modeForUrl;
const actions = replicationActionForMode([replicationMode, clusterMode]); const actions = replicationActionForMode([replicationMode, clusterMode]);
return all( return all(
actions.map((action) => { actions.map((action) => {
return store.findRecord('capabilities', pathForAction(action)).then((capability) => { return store.findRecord('capabilities', pathForAction(action)).then((capability) => {
model.set(`can${camelize(action)}`, capability.get('canUpdate')); model.set(`can${camelize(action)}`, capability.canUpdate);
}); });
}) })
).then(() => { ).then(() => {
@@ -43,10 +43,8 @@ export default Route.extend({
beforeModel() { beforeModel() {
const model = this.modelFor('mode'); const model = this.modelFor('mode');
const replicationMode = this.paramsFor('mode').replication_mode; const replicationMode = this.paramsFor('mode').replication_mode;
if ( const modeModel = model[replicationMode];
model.get(replicationMode).get('replicationDisabled') || if (modeModel.replicationDisabled || modeModel.replicationUnsupported) {
model.get(replicationMode).get('replicationUnsupported')
) {
this.router.transitionTo('vault.cluster.replication.mode', replicationMode); this.router.transitionTo('vault.cluster.replication.mode', replicationMode);
} }
}, },

View File

@@ -18,10 +18,10 @@ export default Route.extend({
cluster: this.modelFor('mode'), cluster: this.modelFor('mode'),
canAddSecondary: this.store canAddSecondary: this.store
.findRecord('capabilities', `sys/replication/${replicationMode}/primary/secondary-token`) .findRecord('capabilities', `sys/replication/${replicationMode}/primary/secondary-token`)
.then((c) => c.get('canUpdate')), .then((c) => c.canUpdate),
canRevokeSecondary: this.store canRevokeSecondary: this.store
.findRecord('capabilities', `sys/replication/${replicationMode}/primary/revoke-secondary`) .findRecord('capabilities', `sys/replication/${replicationMode}/primary/revoke-secondary`)
.then((c) => c.get('canUpdate')), .then((c) => c.canUpdate),
}).then(({ cluster, canAddSecondary, canRevokeSecondary }) => { }).then(({ cluster, canAddSecondary, canRevokeSecondary }) => {
setProperties(cluster, { setProperties(cluster, {
canRevokeSecondary, canRevokeSecondary,
@@ -32,11 +32,8 @@ export default Route.extend({
}, },
afterModel(model) { afterModel(model) {
const replicationMode = this.paramsFor('mode').replication_mode; const replicationMode = this.paramsFor('mode').replication_mode;
if ( const modeModel = model[replicationMode];
!model.get(`${replicationMode}.isPrimary`) || if (!modeModel.isPrimary || modeModel.replicationDisabled || modeModel.replicationUnsupported) {
model.get(`${replicationMode}.replicationDisabled`) ||
model.get(`${replicationMode}.replicationUnsupported`)
) {
this.router.transitionTo('vault.cluster.replication.mode', replicationMode); this.router.transitionTo('vault.cluster.replication.mode', replicationMode);
} }
}, },

View File

@@ -12,7 +12,7 @@ export default Base.extend({
redirect(model) { redirect(model) {
const replicationMode = this.paramsFor('mode').replication_mode; const replicationMode = this.paramsFor('mode').replication_mode;
if (!model.get(`${replicationMode}.isPrimary`) || !model.get('canAddSecondary')) { if (!model[replicationMode].isPrimary || !model.canAddSecondary) {
return this.router.transitionTo('vault.cluster.replication.mode', replicationMode); return this.router.transitionTo('vault.cluster.replication.mode', replicationMode);
} }
}, },

View File

@@ -46,8 +46,8 @@ export default Base.extend({
if ( if (
!this.version.hasPerfReplication || !this.version.hasPerfReplication ||
replicationMode !== 'performance' || replicationMode !== 'performance' ||
!cluster.get(`${replicationMode}.isPrimary`) || !cluster[replicationMode].isPrimary ||
!cluster.get('canAddSecondary') !cluster.canAddSecondary
) { ) {
return this.router.transitionTo('vault.cluster.replication.mode', replicationMode); return this.router.transitionTo('vault.cluster.replication.mode', replicationMode);
} }

View File

@@ -22,8 +22,8 @@ export default Base.extend({
if ( if (
!this.version.hasPerfReplication || !this.version.hasPerfReplication ||
replicationMode !== 'performance' || replicationMode !== 'performance' ||
!cluster.get(`${replicationMode}.isPrimary`) || !cluster[replicationMode].isPrimary ||
!cluster.get('canAddSecondary') !cluster.canAddSecondary
) { ) {
return this.transitionTo('mode', replicationMode); return this.transitionTo('mode', replicationMode);
} }

View File

@@ -29,9 +29,9 @@ export default Base.extend({
if ( if (
!this.version.hasPerfReplication || !this.version.hasPerfReplication ||
replicationMode !== 'performance' || replicationMode !== 'performance' ||
!cluster.get(`${replicationMode}.isPrimary`) !cluster[replicationMode].isPrimary
) { ) {
return this.transitionTo('mode', cluster.get('name'), replicationMode); return this.transitionTo('mode', cluster.name, replicationMode);
} }
}, },
}); });

View File

@@ -12,7 +12,7 @@ export default Base.extend({
redirect(model) { redirect(model) {
const replicationMode = this.replicationMode; const replicationMode = this.replicationMode;
if (!model.get(`${replicationMode}.isPrimary`) || !model.get('canRevokeSecondary')) { if (!model[replicationMode].isPrimary || !model.canRevokeSecondary) {
return this.transitionTo('index'); return this.transitionTo('index');
} }
}, },