mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-13 04:48:37 -05:00
Add read-only credential form depending on access
This commit is contained in:
@@ -217,12 +217,55 @@ function find (method, keys) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function has (method, keys) {
|
||||
if (!keys) {
|
||||
keys = method;
|
||||
method = 'GET';
|
||||
}
|
||||
|
||||
method = method.toUpperCase();
|
||||
|
||||
let value;
|
||||
switch (method) {
|
||||
case 'OPTIONS':
|
||||
value = this.options(keys);
|
||||
break;
|
||||
default:
|
||||
value = this.get(keys);
|
||||
}
|
||||
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
function normalizePath (resource) {
|
||||
let version = '/api/v2/';
|
||||
|
||||
return `${version}${resource}/`;
|
||||
}
|
||||
|
||||
function isEditable () {
|
||||
let canEdit = this.get('summary_fields.user_capabilities.edit');
|
||||
|
||||
if (canEdit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.has('options', 'actions.PUT')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
function isCreatable () {
|
||||
if (this.has('options', 'actions.POST')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function graft (id) {
|
||||
let item = this.get('results').filter(result => result.id === id);
|
||||
|
||||
@@ -255,6 +298,9 @@ function BaseModel (path) {
|
||||
this.find = find;
|
||||
this.get = get;
|
||||
this.graft = graft;
|
||||
this.has = has;
|
||||
this.isEditable = isEditable;
|
||||
this.isCreatable = isCreatable;
|
||||
this.match = match;
|
||||
this.model = {};
|
||||
this.normalizePath = normalizePath;
|
||||
|
||||
@@ -3,18 +3,21 @@ const ENCRYPTED_VALUE = '$encrypted$';
|
||||
let BaseModel;
|
||||
|
||||
function createFormSchema (method, config) {
|
||||
if (!config) {
|
||||
config = method;
|
||||
method = 'GET';
|
||||
}
|
||||
|
||||
let schema = Object.assign({}, this.options(`actions.${method.toUpperCase()}`));
|
||||
|
||||
if (config && config.omit) {
|
||||
config.omit.forEach(key => {
|
||||
delete schema[key];
|
||||
});
|
||||
config.omit.forEach(key => delete schema[key]);
|
||||
}
|
||||
|
||||
for (let key in schema) {
|
||||
schema[key].id = key;
|
||||
|
||||
if (method === 'put') {
|
||||
if (this.has(key)) {
|
||||
schema[key]._value = this.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user