open-vault/ui/app/components/wizard/features-selection.js
Jordan Reimer 5c2a08de6d
Ember Upgrade to 3.24 (#13443)
* Update browserslist

* Add browserslistrc

* ember-cli-update --to 3.26, fix conflicts

* Run codemodes that start with ember-*

* More codemods - before cp*

* More codemods (curly data-test-*)

* WIP ember-basic-dropdown template errors

* updates ember-basic-dropdown and related deps to fix build issues

* updates basic dropdown instances to new version API

* updates more deps -- ember-template-lint is working again

* runs no-implicit-this codemod

* creates and runs no-quoteless-attributes codemod

* runs angle brackets codemod

* updates lint:hbs globs to only touch hbs files

* removes yield only templates

* creates and runs deprecated args transform

* supresses lint error for invokeAction on LinkTo component

* resolves remaining ambiguous path lint errors

* resolves simple-unless lint errors

* adds warnings for deprecated tagName arg on LinkTo components

* adds warnings for remaining curly component invocation

* updates global template lint rules

* resolves remaining template lint errors

* disables some ember specfic lint rules that target pre octane patterns

* js lint fix run

* resolves remaining js lint errors

* fixes test run

* adds npm-run-all dep

* fixes test attribute issues

* fixes console acceptance tests

* fixes tests

* adds yield only wizard/tutorial-active template

* fixes more tests

* attempts to fix more flaky tests

* removes commented out settled in transit test

* updates deprecations workflow and adds initializer to filter by version

* updates flaky policies acl old test

* updates to flaky transit test

* bumps ember deps down to LTS version

* runs linters after main merge

* fixes client count tests after bad merge conflict fixes

* fixes client count history test

* more updates to lint config

* another round of hbs lint fixes after extending stylistic rule

* updates lint-staged commands

* removes indent eslint rule since it seems to break things

* fixes bad attribute in transform-edit-form template

* test fixes

* fixes enterprise tests

* adds changelog

* removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters

* flaky test fix

Co-authored-by: hashishaw <cshaw@hashicorp.com>
2021-12-16 20:44:29 -07:00

146 lines
4.2 KiB
JavaScript

import { or, not } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { FEATURE_MACHINE_TIME } from 'vault/helpers/wizard-constants';
import { htmlSafe } from '@ember/template';
export default Component.extend({
wizard: service(),
version: service(),
permissions: service(),
init() {
this._super(...arguments);
this.maybeHideFeatures();
},
maybeHideFeatures() {
let features = this.allFeatures;
features.forEach((feat) => {
feat.disabled = this.doesNotHavePermission(feat.requiredPermissions);
});
if (this.showReplication === false) {
let feature = this.allFeatures.findBy('key', 'replication');
feature.show = false;
}
},
doesNotHavePermission(requiredPermissions) {
// requiredPermissions is an object of paths and capabilities defined within allFeatures.
// the expected shape is:
// {
// 'example/path': ['capability'],
// 'second/example/path': ['update', 'sudo'],
// }
return !Object.keys(requiredPermissions).every((path) => {
return this.permissions.hasPermission(path, requiredPermissions[path]);
});
},
estimatedTime: computed('selectedFeatures', function () {
let time = 0;
for (let feature of Object.keys(FEATURE_MACHINE_TIME)) {
if (this.selectedFeatures.includes(feature)) {
time += FEATURE_MACHINE_TIME[feature];
}
}
return time;
}),
selectProgress: computed('selectedFeatures', function () {
let bar = this.selectedFeatures.map((feature) => {
return { style: htmlSafe('width:0%;'), completed: false, showIcon: true, feature: feature };
});
if (bar.length === 0) {
bar = [{ style: htmlSafe('width:0%;'), showIcon: false }];
}
return bar;
}),
allFeatures: computed(function () {
return [
{
key: 'secrets',
name: 'Secrets',
steps: ['Enabling a Secrets Engine', 'Adding a secret'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/mounts/example': ['update'],
},
},
{
key: 'authentication',
name: 'Authentication',
steps: ['Enabling an Auth Method', 'Managing your Auth Method'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/auth': ['read'],
'sys/auth/foo': ['update', 'sudo'],
},
},
{
key: 'policies',
name: 'Policies',
steps: [
'Choosing a policy type',
'Creating a policy',
'Deleting your policy',
'Other types of policies',
],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/policies/acl': ['list'],
},
},
{
key: 'replication',
name: 'Replication',
steps: ['Setting up replication', 'Your cluster information'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/replication/performance/primary/enable': ['update'],
'sys/replication/dr/primary/enable': ['update'],
},
},
{
key: 'tools',
name: 'Tools',
steps: ['Wrapping data', 'Lookup wrapped data', 'Rewrapping your data', 'Unwrapping your data'],
selected: false,
show: true,
disabled: false,
requiredPermissions: {
'sys/wrapping/wrap': ['update'],
'sys/wrapping/lookup': ['update'],
'sys/wrapping/unwrap': ['update'],
'sys/wrapping/rewrap': ['update'],
},
},
];
}),
showReplication: or('version.hasPerfReplication', 'version.hasDRReplication'),
selectedFeatures: computed('allFeatures.@each.selected', function () {
return this.allFeatures.filterBy('selected').mapBy('key');
}),
cannotStartWizard: not('selectedFeatures.length'),
actions: {
saveFeatures() {
let wizard = this.wizard;
wizard.saveFeatures(this.selectedFeatures);
wizard.transitionTutorialMachine('active.select', 'CONTINUE');
},
},
});