mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Merge pull request #6000 from mabashian/5926-survey-password-minlength
Fixed min/max length survey password bug
This commit is contained in:
commit
58cc33481e
@ -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:
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
];
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
];
|
||||
@ -186,10 +186,11 @@
|
||||
<span class="input-group-btn">
|
||||
<button type="button" class="btn btn-default show_input_button JobSubmission-passwordButton" id="survey_question_{{$index}}_show_input_button" aw-tool-tip="Toggle the display of plaintext." aw-tip-placement="top" ng-click="togglePassword('#survey_question_' + $index)" data-original-title="" title="">Show</button>
|
||||
</span>
|
||||
<input id="survey_question_{{$index}}" type="password" ng-model="question.model" name="survey_question_{{$index}}" ng-required="question.required" ng-minlength="question.minlength" ng-maxlength="question.maxlength" class="form-control Form-textInput" autocomplete="false">
|
||||
<input id="survey_question_{{$index}}" ng-if="!question.default" type="password" ng-model="question.model" name="survey_question_{{$index}}" ng-required="question.required" ng-minlength="question.minlength" ng-maxlength="question.maxlength" class="form-control Form-textInput" autocomplete="false">
|
||||
<input id="survey_question_{{$index}}" ng-if="question.default" type="password" ng-model="question.model" name="survey_question_{{$index}}" ng-required="question.required" aw-password-min="question.minlength" aw-password-max="question.maxlength" class="form-control Form-textInput" autocomplete="false">
|
||||
</div>
|
||||
<div class="error survey_error" ng-show="forms.survey.survey_question_{{$index}}.$dirty && forms.survey.survey_question_{{$index}}.$error.required">Please enter an answer.</div>
|
||||
<div class="error survey_error" ng-show="forms.survey.survey_question_{{$index}}.$error.minlength || forms.survey.survey_question_{{$index}}.$error.maxlength">Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.</div>
|
||||
<div class="error survey_error" ng-show="forms.survey.survey_question_{{$index}}.$error.awPasswordMin || forms.survey.survey_question_{{$index}}.$error.awPasswordMax || forms.survey.survey_question_{{$index}}.$error.minlength || forms.survey.survey_question_{{$index}}.$error.maxlength">Please enter an answer between {{question.minlength}} to {{question.maxlength}} characters long.</div>
|
||||
</div>
|
||||
<div ng-if="question.type === 'integer'">
|
||||
<input type="number" id="survey_question_{{$index}}" ng-model="question.model" class="form-control Form-textInput" name="survey_question_{{$index}}" ng-required="question.required" integer aw-min="question.minValue" aw-max="question.maxValue"/>
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user