diff --git a/awx/main/models/mixins.py b/awx/main/models/mixins.py index b490197adc..f767586eff 100644 --- a/awx/main/models/mixins.py +++ b/awx/main/models/mixins.py @@ -29,9 +29,7 @@ class ResourceMixin(models.Model): ''' Use instead of `MyModel.objects` when you want to only consider resources that a user has specific permissions for. For example: - MyModel.accessible_objects(user, 'read_role').filter(name__istartswith='bar'); - NOTE: This should only be used for list type things. If you have a specific resource you want to check permissions on, it is more performant to resolve the resource in question then call @@ -160,12 +158,13 @@ class SurveyJobTemplateMixin(models.Model): errors.append("Value %s for '%s' expected to be a string." % (data[survey_element['variable']], survey_element['variable'])) return errors - if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < int(survey_element['min']): - errors.append("'%s' value %s is too small (length is %s must be at least %s)." % - (survey_element['variable'], data[survey_element['variable']], len(data[survey_element['variable']]), survey_element['min'])) - if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > int(survey_element['max']): - errors.append("'%s' value %s is too large (must be no more than %s)." % - (survey_element['variable'], data[survey_element['variable']], survey_element['max'])) + if not data[survey_element['variable']] == '$encrypted$' and not survey_element['type'] == 'password': + if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < int(survey_element['min']): + errors.append("'%s' value %s is too small (length is %s must be at least %s)." % + (survey_element['variable'], data[survey_element['variable']], len(data[survey_element['variable']]), survey_element['min'])) + if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > int(survey_element['max']): + errors.append("'%s' value %s is too large (must be no more than %s)." % + (survey_element['variable'], data[survey_element['variable']], survey_element['max'])) elif survey_element['type'] == 'integer': if survey_element['variable'] in data: if type(data[survey_element['variable']]) != int: diff --git a/awx/ui/client/src/job-submission/job-submission-directives/aw-password-max.directive.js b/awx/ui/client/src/job-submission/job-submission-directives/aw-password-max.directive.js new file mode 100644 index 0000000000..6ac96eff0e --- /dev/null +++ b/awx/ui/client/src/job-submission/job-submission-directives/aw-password-max.directive.js @@ -0,0 +1,29 @@ +/************************************************* + * Copyright (c) 2017 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +/* jshint unused: vars */ + +export default + [ 'Empty', + function(Empty) { + return { + restrict: 'A', + require: 'ngModel', + link: function(scope, elem, attr, ctrl) { + ctrl.$parsers.unshift(function(viewValue) { + var max = (attr.awPasswordMax) ? scope.$eval(attr.awPasswordMax) : Infinity; + if (!Empty(max) && !Empty(viewValue) && viewValue.length > max && viewValue !== '$encrypted$') { + ctrl.$setValidity('awPasswordMax', false); + return viewValue; + } else { + ctrl.$setValidity('awPasswordMax', true); + return viewValue; + } + }); + } + }; + } + ]; diff --git a/awx/ui/client/src/job-submission/job-submission-directives/aw-password-min.directive.js b/awx/ui/client/src/job-submission/job-submission-directives/aw-password-min.directive.js new file mode 100644 index 0000000000..1498313177 --- /dev/null +++ b/awx/ui/client/src/job-submission/job-submission-directives/aw-password-min.directive.js @@ -0,0 +1,27 @@ +/************************************************* + * Copyright (c) 2017 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + + export default + [ 'Empty', + function(Empty) { + return { + restrict: 'A', + require: 'ngModel', + link: function(scope, elem, attr, ctrl) { + ctrl.$parsers.unshift(function(viewValue) { + var min = (attr.awPasswordMin) ? scope.$eval(attr.awPasswordMin) : -Infinity; + if (!Empty(min) && !Empty(viewValue) && viewValue.length < min && viewValue !== '$encrypted$') { + ctrl.$setValidity('awPasswordMin', false); + return viewValue; + } else { + ctrl.$setValidity('awPasswordMin', true); + return viewValue; + } + }); + } + }; + } + ]; diff --git a/awx/ui/client/src/job-submission/job-submission.partial.html b/awx/ui/client/src/job-submission/job-submission.partial.html index f05bdd25a8..3f473a71d7 100644 --- a/awx/ui/client/src/job-submission/job-submission.partial.html +++ b/awx/ui/client/src/job-submission/job-submission.partial.html @@ -186,10 +186,11 @@ - + +
Please enter an answer.
-
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
+
Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.
diff --git a/awx/ui/client/src/job-submission/main.js b/awx/ui/client/src/job-submission/main.js index 71c4c5c0de..4d960176fb 100644 --- a/awx/ui/client/src/job-submission/main.js +++ b/awx/ui/client/src/job-submission/main.js @@ -10,6 +10,8 @@ import GetSurveyQuestions from './job-submission-factories/getsurveyquestions.fa import submitJob from './job-submission.directive'; import credentialList from './lists/credential/job-sub-cred-list.directive'; import inventoryList from './lists/inventory/job-sub-inv-list.directive'; +import awPasswordMin from './job-submission-directives/aw-password-min.directive'; +import awPasswordMax from './job-submission-directives/aw-password-max.directive'; export default angular.module('jobSubmission', []) @@ -18,4 +20,6 @@ export default .factory('GetSurveyQuestions', GetSurveyQuestions) .directive('submitJob', submitJob) .directive('jobSubCredList', credentialList) - .directive('jobSubInvList', inventoryList); + .directive('jobSubInvList', inventoryList) + .directive('awPasswordMin', awPasswordMin) + .directive('awPasswordMax', awPasswordMax);