mirror of
https://github.com/ansible/awx.git
synced 2026-03-10 22:19:28 -02:30
Add read-only credential form depending on access
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
.at-CredentialsPermissions {
|
.at-CredentialsPermissions {
|
||||||
margin-top: 20px;
|
margin-top: 50px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ function AddCredentialsController (models, $state, strings) {
|
|||||||
omit: ['user', 'team', 'inputs']
|
omit: ['user', 'team', 'inputs']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vm.form.disabled = !credential.isCreatable();
|
||||||
|
|
||||||
vm.form.organization._resource = 'organization';
|
vm.form.organization._resource = 'organization';
|
||||||
vm.form.organization._route = 'credentials.add.organization';
|
vm.form.organization._route = 'credentials.add.organization';
|
||||||
vm.form.organization._model = organization;
|
vm.form.organization._model = organization;
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ function EditCredentialsController (models, $state, $scope, strings) {
|
|||||||
// Only exists for permissions compatibility
|
// Only exists for permissions compatibility
|
||||||
$scope.credential_obj = credential.get();
|
$scope.credential_obj = credential.get();
|
||||||
|
|
||||||
vm.form = credential.createFormSchema('put', {
|
vm.form = credential.createFormSchema({
|
||||||
omit: ['user', 'team', 'inputs']
|
omit: ['user', 'team', 'inputs']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vm.form.disabled = !credential.isEditable();
|
||||||
|
|
||||||
vm.form.organization._resource = 'organization';
|
vm.form.organization._resource = 'organization';
|
||||||
vm.form.organization._model = organization;
|
vm.form.organization._model = organization;
|
||||||
vm.form.organization._route = 'credentials.edit.organization';
|
vm.form.organization._route = 'credentials.edit.organization';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<button class="btn at-Button{{ fill }}--{{ color }}"
|
<button class="btn at-Button{{ fill }}--{{ color }}"
|
||||||
ng-disabled="form.disabled || (type === 'save' && !form.isValid)"
|
ng-disabled="type !== 'cancel' && (form.disabled || (type === 'save' && !form.isValid))"
|
||||||
ng-click="action()">
|
ng-click="action()">
|
||||||
{{::text}}
|
{{::text}}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ function AtFormController (eventService, strings) {
|
|||||||
form = _form_;
|
form = _form_;
|
||||||
modal = scope[scope.ns].modal;
|
modal = scope[scope.ns].modal;
|
||||||
|
|
||||||
|
vm.state.disabled = scope.state.disabled;
|
||||||
|
|
||||||
vm.setListeners();
|
vm.setListeners();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ function AtInputLookupController (baseInputController, $q, $state, $stateParams)
|
|||||||
};
|
};
|
||||||
|
|
||||||
vm.search = () => {
|
vm.search = () => {
|
||||||
|
scope.state._touched = true;
|
||||||
|
|
||||||
return model.search({ [search.key]: scope.state._displayValue }, search.config)
|
return model.search({ [search.key]: scope.state._displayValue }, search.config)
|
||||||
.then(found => {
|
.then(found => {
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|||||||
@@ -217,12 +217,55 @@ function find (method, keys) {
|
|||||||
return value;
|
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) {
|
function normalizePath (resource) {
|
||||||
let version = '/api/v2/';
|
let version = '/api/v2/';
|
||||||
|
|
||||||
return `${version}${resource}/`;
|
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) {
|
function graft (id) {
|
||||||
let item = this.get('results').filter(result => result.id === id);
|
let item = this.get('results').filter(result => result.id === id);
|
||||||
|
|
||||||
@@ -255,6 +298,9 @@ function BaseModel (path) {
|
|||||||
this.find = find;
|
this.find = find;
|
||||||
this.get = get;
|
this.get = get;
|
||||||
this.graft = graft;
|
this.graft = graft;
|
||||||
|
this.has = has;
|
||||||
|
this.isEditable = isEditable;
|
||||||
|
this.isCreatable = isCreatable;
|
||||||
this.match = match;
|
this.match = match;
|
||||||
this.model = {};
|
this.model = {};
|
||||||
this.normalizePath = normalizePath;
|
this.normalizePath = normalizePath;
|
||||||
|
|||||||
@@ -3,18 +3,21 @@ const ENCRYPTED_VALUE = '$encrypted$';
|
|||||||
let BaseModel;
|
let BaseModel;
|
||||||
|
|
||||||
function createFormSchema (method, config) {
|
function createFormSchema (method, config) {
|
||||||
|
if (!config) {
|
||||||
|
config = method;
|
||||||
|
method = 'GET';
|
||||||
|
}
|
||||||
|
|
||||||
let schema = Object.assign({}, this.options(`actions.${method.toUpperCase()}`));
|
let schema = Object.assign({}, this.options(`actions.${method.toUpperCase()}`));
|
||||||
|
|
||||||
if (config && config.omit) {
|
if (config && config.omit) {
|
||||||
config.omit.forEach(key => {
|
config.omit.forEach(key => delete schema[key]);
|
||||||
delete schema[key];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let key in schema) {
|
for (let key in schema) {
|
||||||
schema[key].id = key;
|
schema[key].id = key;
|
||||||
|
|
||||||
if (method === 'put') {
|
if (this.has(key)) {
|
||||||
schema[key]._value = this.get(key);
|
schema[key]._value = this.get(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user