UI: Add transform for handling listing visibility (#20284)

This commit is contained in:
Chelsea Shaw 2023-08-25 10:02:31 -05:00 committed by GitHub
parent 04fc15471b
commit cdca4e831d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 27 deletions

View file

@ -32,11 +32,10 @@ export default class MountConfigModel extends Model {
})
auditNonHmacResponseKeys;
@attr('string', {
@attr('mountVisibility', {
editType: 'boolean',
label: 'List method when unauthenticated',
trueValue: 'unauth',
falseValue: 'hidden',
defaultValue: false,
})
listingVisibility;

View file

@ -133,7 +133,6 @@ export default class PkiRoleModel extends Model {
label: 'Generate lease with certificate',
subText:
'Specifies if certificates issued/signed against this role will have Vault leases attached to them.',
editType: 'boolean',
docLink: '/vault/api-docs/secret/pki#create-update-role',
})
generateLease;
@ -143,7 +142,6 @@ export default class PkiRoleModel extends Model {
detailsLabel: 'Store in storage backend', // template reverses value
subText:
'This can improve performance when issuing large numbers of certificates. However, certificates issued in this way cannot be enumerated or revoked.',
editType: 'boolean',
docLink: '/vault/api-docs/secret/pki#create-update-role',
})
noStore;
@ -152,7 +150,6 @@ export default class PkiRoleModel extends Model {
label: 'Basic constraints valid for non-CA',
detailsLabel: 'Add basic constraints',
subText: 'Mark Basic Constraints valid when issuing non-CA certificates.',
editType: 'boolean',
})
addBasicConstraints;
/* End of overriding default options */
@ -207,7 +204,6 @@ export default class PkiRoleModel extends Model {
@attr('boolean', {
label: 'Allow IP SANs',
subText: 'Specifies if clients can request IP Subject Alternative Names.',
editType: 'boolean',
defaultValue: true,
})
allowIpSans;
@ -223,7 +219,6 @@ export default class PkiRoleModel extends Model {
@attr('boolean', {
label: 'Allow URI SANs template',
subText: 'If true, the URI SANs above may contain templates, as with ACL Path Templating.',
editType: 'boolean',
docLink: '/vault/docs/concepts/policies',
})
allowUriSansTemplate;

View file

@ -0,0 +1,15 @@
import Transform from '@ember-data/serializer/transform';
/**
* correctly maps boolean values to the two options for listingVisibility
* attribute on seceret engines and auth engines
*/
export default class MountVisibilityTransform extends Transform {
deserialize(serialized) {
return serialized === 'unauth';
}
serialize(deserialized) {
return deserialized === true ? 'unauth' : 'hidden';
}
}

View file

@ -67,24 +67,6 @@
{{/if}}
</div>
{{/if}}
{{else if (and (eq @attr.type "string") (eq @attr.options.editType "boolean"))}}
<div class="b-checkbox">
<input
type="checkbox"
id={{@attr.name}}
class="styled"
checked={{eq (get @model this.valuePath) @attr.options.trueValue}}
onchange={{fn this.setAndBroadcastBool @attr.options.trueValue @attr.options.falseValue}}
data-test-input={{@attr.name}}
/>
<label for={{@attr.name}} class="is-label">
{{this.labelString}}
{{#if (and this.showHelpText @attr.options.helpText)}}
<InfoTooltip>{{@attr.options.helpText}}</InfoTooltip>
{{/if}}
</label>
</div>
{{else if (eq @attr.options.editType "searchSelect")}}
<div class="form-section">
<SearchSelect
@ -331,7 +313,7 @@
{{/if}}
{{/if}}
</div>
{{else if (eq @attr.type "boolean")}}
{{else if (or (eq @attr.type "boolean") (eq @attr.options.editType "boolean"))}}
<div class="b-checkbox">
<input
disabled={{this.disabled}}

View file

@ -0,0 +1,25 @@
import { module, test } from 'qunit';
import { setupTest } from 'vault/tests/helpers';
module('Unit | Transform | mount visibility', function (hooks) {
setupTest(hooks);
test('it serializes correctly for API', function (assert) {
const transform = this.owner.lookup('transform:mount-visibility');
assert.ok(transform);
let serialized = transform.serialize(true);
assert.strictEqual(serialized, 'unauth');
serialized = transform.serialize(false);
assert.strictEqual(serialized, 'hidden');
});
test('it deserializes correctly from API', function (assert) {
const transform = this.owner.lookup('transform:mount-visibility');
let deserialized = transform.deserialize('unauth');
assert.true(deserialized, 'deserializes "unauth" string value to true');
deserialized = transform.deserialize('hidden');
assert.false(deserialized, 'deserializes "hidden" string value to false');
deserialized = transform.deserialize('');
assert.false(deserialized, 'deserializes empty string to false');
});
});