open-nomad/ui/app/abilities/variable.js
Jai b2d703b53c dx: update canCreate logic and token generation for secure var dev environment (#13438)
* ui:  add logic for create permission computed property

* ui:  update token factory and variable ability to simulate create permissions for dev env
2022-07-11 13:34:06 -04:00

36 lines
1.1 KiB
JavaScript

import AbstractAbility from './abstract';
import { computed, get } from '@ember/object';
import { or } from '@ember/object/computed';
export default class extends AbstractAbility {
@or(
'bypassAuthorization',
'selfTokenIsManagement',
'policiesSupportVariableView'
)
canList;
@or(
'bypassAuthorization',
'selfTokenIsManagement',
'policiesSupportVariableCreation'
)
canCreate;
@computed('rulesForNamespace.@each.capabilities')
get policiesSupportVariableView() {
return this.rulesForNamespace.some((rules) => {
return get(rules, 'SecureVariables');
});
}
@computed('rulesForNamespace.@each.capabilities') // TODO: edit computed property to be SecureVariables.Path "DYNAMIC PATH"
get policiesSupportVariableCreation() {
return this.rulesForNamespace.some((rules) => {
const keyName = `SecureVariables.Path "*".Capabilities`; // TODO: add ability to edit path, however computed properties can't take parameters
const capabilities = get(rules, keyName) || [];
return capabilities.includes('create');
});
}
}