Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update template/templates data on transformation #9838

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ui/app/adapters/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,20 @@ export default ApplicationAdapter.extend({
results.forEach(result => {
if (result.value) {
if (result.value.data.roles) {
// TODO: Check if this is needed and remove if not
resp.data = assign({}, resp.data, { zero_address_roles: result.value.data.roles });
} else {
resp.data = assign({}, resp.data, result.value.data);
let d = result.value.data;
if (d.templates) {
// In Transformations data goes up as "template", but comes down as "templates"
// To keep the keys consistent we're translating here
d = {
...d,
template: [d.templates],
};
delete d.templates;
}
resp.data = assign({}, resp.data, d);
}
}
});
Expand Down
7 changes: 3 additions & 4 deletions ui/app/models/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Model = DS.Model.extend({
label: 'Masking character',
subText: 'Specify which character you’d like to mask your data.',
}),
template: attr('string', {
template: attr('array', {
editType: 'searchSelect',
fallbackComponent: 'string-list',
label: 'Template', // TODO: make this required for making a transformation
Expand All @@ -73,7 +73,6 @@ const Model = DS.Model.extend({
subText:
'Templates allow Vault to determine what and how to capture the value to be transformed. Type to use an existing template or create a new one.',
}),
templates: attr('array'), // TODO: remove once BE changes the returned property to a singular template on the GET request.
allowed_roles: attr('array', {
editType: 'searchSelect',
label: 'Allowed roles',
Expand All @@ -83,9 +82,9 @@ const Model = DS.Model.extend({
}),
transformAttrs: computed('type', function() {
if (this.type === 'masking') {
return ['name', 'type', 'masking_character', 'template', 'templates', 'allowed_roles'];
return ['name', 'type', 'masking_character', 'template', 'allowed_roles'];
}
return ['name', 'type', 'tweak_source', 'template', 'templates', 'allowed_roles'];
return ['name', 'type', 'tweak_source', 'template', 'allowed_roles'];
}),
transformFieldAttrs: computed('transformAttrs', function() {
return expandAttributeMeta(this, this.get('transformAttrs'));
Expand Down
10 changes: 9 additions & 1 deletion ui/app/serializers/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ export default ApplicationSerializer.extend({
if (payload.data.masking_character) {
payload.data.masking_character = String.fromCharCode(payload.data.masking_character);
}
// TODO: the BE is working on a ticket to amend these response, so revisit.
return this._super(store, primaryModelClass, payload, id, requestType);
},

serialize() {
let json = this._super(...arguments);
if (json.template && Array.isArray(json.template)) {
// Transformations should only ever have one template
json.template = json.template[0];
}
return json;
},
});
20 changes: 5 additions & 15 deletions ui/app/templates/components/transform-create-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@
{{!-- TODO: figure out what this ?? --}}
{{!-- <NamespaceReminder @mode={{mode}} @noun="SSH role" /> --}}
{{#each model.transformFieldAttrs as |attr|}}
{{#if (eq attr.name 'templates')}}
{{!-- TODO: for now don't show until backend makes api changes. --}}
{{else if (eq attr.name 'template')}}
<FormField
data-test-field
@attr={{attr}}
@model={{model}}
/>
{{else}}
<FormField
data-test-field
@attr={{attr}}
@model={{model}}
/>
{{/if}}
<FormField
data-test-field
@attr={{attr}}
@model={{model}}
/>
{{/each}}
</div>
<div class="field is-grouped-split box is-fullwidth is-bottomless">
Expand Down
16 changes: 0 additions & 16 deletions ui/app/templates/components/transform-edit-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@
<input data-test-input={{attr.name}} id={{attr.name}} autocomplete="off" spellcheck="false"
value={{or (get model attr.name) attr.options.defaultValue}} readonly class="field input is-readOnly" type={{attr.type}} />
{{/if}}
{{else if (eq attr.name 'template')}}
<FormField
data-test-field
@attr={{attr}}
@model={{model}}
@initialSelected={{model.templates}}
/>
{{else if (eq attr.name 'templates')}}
{{!-- TODO: for now don't show until backend makes api changes. --}}
{{else if (eq attr.name 'allowed_roles')}}
<FormField
data-test-field
@attr={{attr}}
@model={{model}}
@initialSelected={{model.allowed_roles}}
/>
{{else}}
<FormField
data-test-field
Expand Down