Files
nomad/ui/app/adapters/variable.js
Phil Renaud 9f51a5deb2 UI variables made to be unique by namespace and path (#14072)
* Starting on namespaced id

* Traversal for variables uniqued by namespace

* Delog

* Basic CRUD complete w namespaces included

* Correct secvar breadcrumb joining and testfix now that namespaces are included

* Testfixes with namespaces in place

* Namespace-aware duplicate path warning

* Duplicate path warning test additions

* Trimpath reimplemented on dupe check

* Solves a bug where slash was not being passed to the can write check

* PR fixes

* variable paths integration test fix now uses store

* Seems far less hacky in retrospect

* PR feedback addressed

* test fixes after inclusion of path as local non-model var

* Prevent confusion by dropping namespace from QPs on PUT, since its already in .data

* Solves a harsh bug where you have namespace access but no secvars access (#14098)

* Solves a harsh bug where you have namespace access but no secvars access

* Lint cleanup

* Remove unneeded condition
2022-08-15 11:56:09 -04:00

54 lines
1.6 KiB
JavaScript

import ApplicationAdapter from './application';
import { pluralize } from 'ember-inflector';
import classic from 'ember-classic-decorator';
@classic
export default class VariableAdapter extends ApplicationAdapter {
pathForType = () => 'var';
// PUT instead of POST on create;
// /v1/var instead of /v1/vars on create (urlForFindRecord)
createRecord(_store, type, snapshot) {
let data = this.serialize(snapshot);
let baseUrl = this.buildURL(type.modelName, data.ID);
return this.ajax(baseUrl, 'PUT', { data });
}
urlForFindAll(modelName) {
let baseUrl = this.buildURL(modelName);
return pluralize(baseUrl);
}
urlForQuery(_query, modelName) {
let baseUrl = this.buildURL(modelName);
return pluralize(baseUrl);
}
urlForFindRecord(identifier, modelName, snapshot) {
const { namespace, id } = _extractIDAndNamespace(identifier, snapshot);
let baseUrl = this.buildURL(modelName, id);
return `${baseUrl}?namespace=${namespace}`;
}
urlForUpdateRecord(identifier, modelName, snapshot) {
const { id } = _extractIDAndNamespace(identifier, snapshot);
let baseUrl = this.buildURL(modelName, id);
return `${baseUrl}`;
}
urlForDeleteRecord(identifier, modelName, snapshot) {
const { namespace, id } = _extractIDAndNamespace(identifier, snapshot);
const baseUrl = this.buildURL(modelName, id);
return `${baseUrl}?namespace=${namespace}`;
}
}
function _extractIDAndNamespace(identifier, snapshot) {
const namespace = snapshot?.attr('namespace') || 'default';
const id = snapshot?.attr('path') || identifier;
return {
namespace,
id,
};
}