Skip to content

Commit

Permalink
fix capabilities paths in route file
Browse files Browse the repository at this point in the history
  • Loading branch information
hellobontempo committed Sep 11, 2024
1 parent 2ef2121 commit 6efc65a
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions ui/lib/replication/addon/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import { service } from '@ember/service';
import { setProperties } from '@ember/object';
import { hash } from 'rsvp';
import Route from '@ember/routing/route';
import ClusterRoute from 'vault/mixins/cluster-route';

Expand All @@ -14,6 +13,23 @@ export default Route.extend(ClusterRoute, {
store: service(),
auth: service(),
router: service(),
capabilities: service(),

async fetchCapabilities() {
const enablePath = (type, cluster) => `sys/replication/${type}/${cluster}/enable`;
const perms = await this.capabilities.fetchMultiplePaths([
enablePath('dr', 'primary'),
enablePath('dr', 'primary'),
enablePath('performance', 'secondary'),
enablePath('performance', 'secondary'),
]);
return {
canEnablePrimaryDr: perms[enablePath('dr', 'primary')].canUpdate,
canEnableSecondaryDr: perms[enablePath('dr', 'primary')].canUpdate,
canEnablePrimaryPerformance: perms[enablePath('performance', 'secondary')].canUpdate,
canEnableSecondaryPerformance: perms[enablePath('performance', 'secondary')].canUpdate,
};
},

beforeModel() {
if (this.auth.activeCluster.replicationRedacted) {
Expand All @@ -29,21 +45,21 @@ export default Route.extend(ClusterRoute, {
return this.auth.activeCluster;
},

afterModel(model) {
return hash({
canEnablePrimary: this.store
.findRecord('capabilities', 'sys/replication/primary/enable')
.then((c) => c.canUpdate),
canEnableSecondary: this.store
.findRecord('capabilities', 'sys/replication/secondary/enable')
.then((c) => c.canUpdate),
}).then(({ canEnablePrimary, canEnableSecondary }) => {
setProperties(model, {
canEnablePrimary,
canEnableSecondary,
});
return model;
async afterModel(model) {
const {
canEnablePrimaryDr,
canEnableSecondaryDr,
canEnablePrimaryPerformance,
canEnableSecondaryPerformance,
} = await this.fetchCapabilities();

setProperties(model, {
canEnablePrimaryDr,
canEnableSecondaryDr,
canEnablePrimaryPerformance,
canEnableSecondaryPerformance,
});
return model;
},
actions: {
refresh() {
Expand Down

0 comments on commit 6efc65a

Please sign in to comment.