open-vault/ui/app/serializers/secret-v2-version.js
Matthew Irish af8eda9322
UI - kv v2 graceful degrade (#5879)
* turns out sourcemaps are useful

* add test for restricted policy in kv v2

* only include version param on fetch if it's encoded in the id

* rename some vars for clarity and use model.id when persisting a secret

* fix delete attributes on the models

* allow data edit when there's metadata access is disallowed

* add tests for edit with restricted policy

* hide metadata fields if you can't edit them
2018-12-03 08:22:13 -06:00

30 lines
973 B
JavaScript

import { get } from '@ember/object';
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
secretDataPath: 'data.data',
normalizeItems(payload) {
let path = this.secretDataPath;
// move response that is the contents of the secret from the dataPath
// to `secret_data` so it will be `secretData` in the model
payload.secret_data = get(payload, path);
payload = Object.assign({}, payload, payload.data.metadata);
delete payload.data;
payload.path = payload.id;
// return the payload if it's expecting a single object or wrap
// it as an array if not
return payload;
},
serialize(snapshot) {
let secret = snapshot.belongsTo('secret');
let version = secret.record.isStub ? snapshot.attr('version') : secret.attr('currentVersion');
version = version || 0;
return {
data: snapshot.attr('secretData'),
options: {
cas: version,
},
};
},
});