open-vault/ui/app/adapters/kmip/role.js
Matthew Irish ddf8c20219
UI - add delete for the various kmip models (#7015)
* add menu-loader component to show menu loading button when the model relationship isPending

* list what keys we've got in api-path error

* fix spacing issue on error flash

* add an action on list-controller that bubbles to the list-route mixin to refresh the route

* empty store when creating scopes

* don't delete _requestQuery in the loop, do it after

* add scope deletion from the scope list

* add deleteRecord to kmip adapters

* add model-wrap component

* delete role from detail page and list

* add revoke credentials functionality

* fix comment

* treat all operations fields specially on kmip roles

* adjust kmip role edit form for new fields

* fix api-path test

* update document blocks for menu-loader and model-wrap components
2019-07-02 16:23:07 -05:00

71 lines
1.8 KiB
JavaScript

import BaseAdapter from './base';
import { decamelize } from '@ember/string';
import { getProperties } from '@ember/object';
export default BaseAdapter.extend({
createRecord(store, type, snapshot) {
let name = snapshot.id || snapshot.attr('name');
let url = this._url(
type.modelName,
{
backend: snapshot.record.backend,
scope: snapshot.record.scope,
},
name
);
return this.ajax(url, 'POST', { data: this.serialize(snapshot) }).then(() => {
return {
id: name,
name,
backend: snapshot.record.backend,
scope: snapshot.record.scope,
};
});
},
deleteRecord(store, type, snapshot) {
let name = snapshot.id || snapshot.attr('name');
let url = this._url(
type.modelName,
{
backend: snapshot.record.backend,
scope: snapshot.record.scope,
},
name
);
return this.ajax(url, 'DELETE');
},
serialize(snapshot) {
// the endpoint here won't allow sending `operation_all` and `operation_none` at the same time or with
// other values, so we manually check for them and send an abbreviated object
let json = snapshot.serialize();
let keys = snapshot.record.nonOperationFields.map(decamelize);
let nonOperationFields = getProperties(json, keys);
for (let field in nonOperationFields) {
if (nonOperationFields[field] == null) {
delete nonOperationFields[field];
}
}
if (json.operation_all) {
return {
operation_all: true,
...nonOperationFields,
};
}
if (json.operation_none) {
return {
operation_none: true,
...nonOperationFields,
};
}
delete json.operation_none;
delete json.operation_all;
return json;
},
updateRecord() {
return this.createRecord(...arguments);
},
});