adding three fixes:

1. adding a watcher for the basePath to use for lookups that might
have dynamic lookups. Ex: The groups form -> cred depends on "source.type"

2. adding a fix for RBAC based autopopulation. Basically, if you don't have
permission to "use" something, then you shouldn't be able to see it auto-fill

3. adding a fix for the promptable fields on the job template form. The inventory
and credential are both promptable, and therefore should not auto populate
This commit is contained in:
jaredevantabor 2017-01-19 15:53:16 -08:00
parent 61ad4e3793
commit fc45603c3b
5 changed files with 53 additions and 18 deletions

View File

@ -86,7 +86,8 @@ export default
reqExpression: "cloudCredentialRequired",
init: "false"
},
ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)'
ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)',
watchBasePath: "credentialBasePath"
},
source_regions: {
label: 'Regions',

View File

@ -76,6 +76,7 @@ export default
list: 'InventoryList',
sourceModel: 'inventory',
sourceField: 'name',
autopopulateLookup: false,
awRequiredWhen: {
reqExpression: '!ask_inventory_on_launch',
alwaysShowAsterisk: true
@ -138,6 +139,7 @@ export default
type: 'lookup',
list: 'CredentialList',
basePath: 'credentials',
autopopulateLookup: false,
search: {
kind: 'ssh'
},

View File

@ -112,6 +112,13 @@ export default ['$state', '$stateParams', '$scope', 'GroupForm', 'CredentialList
};
$scope.sourceChange = function(source) {
source = source.value;
if (source === 'custom'){
$scope.credentialBasePath = GetBasePath('inventory_script');
}
// equal to case 'ec2' || 'rax' || 'azure' || 'azure_rm' || 'vmware' || 'satellite6' || 'cloudforms' || 'openstack'
else{
$scope.credentialBasePath = (source === 'ec2') ? GetBasePath('credentials') + '?kind=aws' : GetBasePath('credentials') + (source === '' ? '' : '?kind=' + (source));
}
if (source === 'ec2' || source === 'custom' || source === 'vmware' || source === 'openstack') {
ParseTypeChange({
scope: $scope,
@ -120,6 +127,7 @@ export default ['$state', '$stateParams', '$scope', 'GroupForm', 'CredentialList
parse_variable: 'envParseType'
});
}
// reset fields
$scope.group_by_choices = source === 'ec2' ? $scope.ec2_group_by : null;
// azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint

View File

@ -469,34 +469,59 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'JobsHelper'])
autopopulateLookup,
modelKey = attrs.ngModel,
modelName = attrs.source,
watcher = attrs.awRequiredWhen || undefined;
watcher = attrs.awRequiredWhen || undefined,
watchBasePath;
if (attrs.autopopulateLookup !== undefined) {
autopopulateLookup = attrs.autopopulateLookup;
if (attrs.autopopulatelookup !== undefined) {
autopopulateLookup = JSON.parse(attrs.autopopulatelookup);
} else {
autopopulateLookup = true;
}
// The following block of code is for instances where the
// lookup field is reused by varying sub-forms. Example: The groups
// form will change it's credential lookup based on the
// source type. The basepath the lookup should utilize is dynamic
// in this case. You'd configure the "watchBasePath" key on the
// field's configuration in the form configuration field.
if (attrs.watchbasepath !== undefined) {
watchBasePath = attrs.watchbasepath;
scope.$watch(watchBasePath, (newValue) => {
if(newValue !== undefined && fieldIsAutopopulatable()){
_doAutoPopulate();
}
});
}
function _doAutoPopulate() {
let query = '';
basePath = GetBasePath(elm.attr('data-basePath')) || elm.attr('data-basePath');
if (attrs.watchbasepath !== undefined && scope[attrs.watchbasepath] !== undefined) {
basePath = scope[attrs.watchbasepath];
}
else {
basePath = GetBasePath(elm.attr('data-basePath')) || elm.attr('data-basePath');
switch(modelName) {
case 'credential':
query = '?kind=ssh';
break;
case 'network_credential':
query = '?kind=net';
break;
}
switch(modelName) {
case 'credential':
query = '?kind=ssh';
break;
case 'network_credential':
query = '?kind=net';
break;
}
Rest.setUrl(`${basePath}` + query);
Rest.get()
.success(function (data) {
if (data.count === 1) {
scope[modelKey] = data.results[0].name;
scope[modelName] = data.results[0].id;
if(data.results[0].summary_fields.user_capabilities.edit === true){
scope[modelKey] = data.results[0].name;
scope[modelName] = data.results[0].id;
}
}
});
}
@ -518,9 +543,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'JobsHelper'])
}
if (scope.mode === "add") {
if(watcher){
scope.$watch(watcher, (newValue, oldValue, scope2) => {
console.log('success', watcher, newValue , oldValue, scope2);
scope.$watch(watcher, () => {
if(Boolean(scope.$eval(watcher)) === true){
// if we get here then the field is required

View File

@ -1368,7 +1368,8 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += `data-basePath="${field.basePath}"`;
html += `data-source="${field.sourceModel}"`;
html += `data-query="?${field.sourceField}__iexact=:value"`;
html += (field.autopopulateLookup) ? `autopopulateLookup=${field.autopopulateLookup}` : "";
html += (field.autopopulateLookup !== undefined) ? ` autopopulateLookup=${field.autopopulateLookup} ` : "";
html += (field.watchBasePath !== undefined) ? ` watchBasePath=${field.watchBasePath} ` : "";
html += `ng-model-options="{ updateOn: 'default blur', debounce: { 'default': 300, 'blur': 0 } }"`;
html += " awlookup >\n";
html += "</div>\n";