vault/ui/lib/replication/addon/routes/mode/secondaries/config-create.js
claire bontempo 7774261c15
UI: Ember upgrade: Handle deprecation router service from host (#28603)
* use alias for router injection

* update @router declarations in engine files

* fix remaining pki router imports

* dynamically set router based on owner

* address replication routers

* update markdown docs

* use non-deprecated import for getOwner

* revert out of scope changes

* add transition-to test
2024-10-08 09:01:46 -07:00

63 lines
1.6 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { hash } from 'rsvp';
import { service } from '@ember/service';
import Base from '../../replication-base';
export default Base.extend({
flashMessages: service(),
router: service('app-router'),
modelPath: 'model.config',
findOrCreate(id) {
const flash = this.flashMessages;
return this.store
.findRecord('path-filter-config', id)
.then(() => {
// if we find a record, transition to the edit view
return this.router
.transitionTo('vault.cluster.replication.mode.secondaries.config-edit', id)
.followRedirects()
.then(() => {
flash.info(
`${id} already had a path filter config, so we loaded the config edit screen for you.`
);
});
})
.catch((e) => {
if (e.httpStatus === 404) {
return this.store.createRecord('path-filter-config', {
id,
mode: null,
paths: [],
});
} else {
throw e;
}
});
},
redirect(model) {
const cluster = model.cluster;
const replicationMode = this.replicationMode;
if (
!this.version.hasPerfReplication ||
replicationMode !== 'performance' ||
!cluster[replicationMode].isPrimary ||
!cluster.canAddSecondary
) {
return this.router.transitionTo('vault.cluster.replication.mode', replicationMode);
}
},
model(params) {
return hash({
cluster: this.modelFor('mode'),
config: this.findOrCreate(params.secondary_id),
});
},
});