Merge pull request #6000 from mabashian/5926-survey-password-minlength

Fixed min/max length survey password bug
This commit is contained in:
Michael Abashian
2017-04-18 14:09:08 -04:00
committed by GitHub
5 changed files with 71 additions and 11 deletions

View File

@@ -29,9 +29,7 @@ class ResourceMixin(models.Model):
''' '''
Use instead of `MyModel.objects` when you want to only consider Use instead of `MyModel.objects` when you want to only consider
resources that a user has specific permissions for. For example: resources that a user has specific permissions for. For example:
MyModel.accessible_objects(user, 'read_role').filter(name__istartswith='bar'); MyModel.accessible_objects(user, 'read_role').filter(name__istartswith='bar');
NOTE: This should only be used for list type things. If you have a 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 specific resource you want to check permissions on, it is more
performant to resolve the resource in question then call 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']], errors.append("Value %s for '%s' expected to be a string." % (data[survey_element['variable']],
survey_element['variable'])) survey_element['variable']))
return errors return errors
if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < int(survey_element['min']): if not data[survey_element['variable']] == '$encrypted$' and not survey_element['type'] == 'password':
errors.append("'%s' value %s is too small (length is %s must be at least %s)." % if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < int(survey_element['min']):
(survey_element['variable'], data[survey_element['variable']], len(data[survey_element['variable']]), survey_element['min'])) errors.append("'%s' value %s is too small (length is %s must be at least %s)." %
if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > int(survey_element['max']): (survey_element['variable'], data[survey_element['variable']], len(data[survey_element['variable']]), survey_element['min']))
errors.append("'%s' value %s is too large (must be no more than %s)." % if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > int(survey_element['max']):
(survey_element['variable'], data[survey_element['variable']], 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': elif survey_element['type'] == 'integer':
if survey_element['variable'] in data: if survey_element['variable'] in data:
if type(data[survey_element['variable']]) != int: if type(data[survey_element['variable']]) != int:

View File

@@ -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;
}
});
}
};
}
];

View File

@@ -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;
}
});
}
};
}
];

View File

@@ -186,10 +186,11 @@
<span class="input-group-btn"> <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> <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> </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>
<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}}.$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>
<div ng-if="question.type === 'integer'"> <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"/> <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"/>

View File

@@ -10,6 +10,8 @@ import GetSurveyQuestions from './job-submission-factories/getsurveyquestions.fa
import submitJob from './job-submission.directive'; import submitJob from './job-submission.directive';
import credentialList from './lists/credential/job-sub-cred-list.directive'; import credentialList from './lists/credential/job-sub-cred-list.directive';
import inventoryList from './lists/inventory/job-sub-inv-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 export default
angular.module('jobSubmission', []) angular.module('jobSubmission', [])
@@ -18,4 +20,6 @@ export default
.factory('GetSurveyQuestions', GetSurveyQuestions) .factory('GetSurveyQuestions', GetSurveyQuestions)
.directive('submitJob', submitJob) .directive('submitJob', submitJob)
.directive('jobSubCredList', credentialList) .directive('jobSubCredList', credentialList)
.directive('jobSubInvList', inventoryList); .directive('jobSubInvList', inventoryList)
.directive('awPasswordMin', awPasswordMin)
.directive('awPasswordMax', awPasswordMax);