d56f0ccb72
* wait for all hash promises to be settled * skeleton tests with policies for write without read * adjust what gets returned from the model hook * refactor secret-edit model hook to use async/await * return a stub version if we can't read secret data * return a stub model for v1 kv * tweak tests to make re-runs friendlier * allow write without CAS if both v2 models cannot be read * show warnings on edit pages for different write without read scenarios * add no read empty states on secret show pages * review feedback * make message language consistent * use version models from metadata if we can read it * refresh route on delete / undelete / destroy * hide controls in the toolbar when you can't read the secret data * show deleted / destroyed messaging over cannot read messaging on the show page * fix test with model stub * refactor large model hook into several functions * comment clarifications
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { get } from '@ember/object';
|
|
import { assign } from '@ember/polyfills';
|
|
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 = 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');
|
|
// if both models failed to read from the server, we need to write without CAS
|
|
if (secret.record.failedServerRead && snapshot.record.failedServerRead) {
|
|
return {
|
|
data: snapshot.attr('secretData'),
|
|
};
|
|
}
|
|
let version = secret.record.failedServerRead ? snapshot.attr('version') : secret.attr('currentVersion');
|
|
version = version || 0;
|
|
return {
|
|
data: snapshot.attr('secretData'),
|
|
options: {
|
|
cas: version,
|
|
},
|
|
};
|
|
},
|
|
});
|