diff options
Diffstat (limited to 'app/Validator')
| -rw-r--r-- | app/Validator/ColumnMoveRestrictionValidator.php | 41 | ||||
| -rw-r--r-- | app/Validator/ColumnRestrictionValidator.php | 40 | ||||
| -rw-r--r-- | app/Validator/ProjectRoleValidator.php | 70 | ||||
| -rw-r--r-- | app/Validator/ProjectValidator.php | 12 | ||||
| -rw-r--r-- | app/Validator/TaskValidator.php | 24 | ||||
| -rw-r--r-- | app/Validator/UserValidator.php | 2 |
6 files changed, 160 insertions, 29 deletions
diff --git a/app/Validator/ColumnMoveRestrictionValidator.php b/app/Validator/ColumnMoveRestrictionValidator.php new file mode 100644 index 00000000..99769c6b --- /dev/null +++ b/app/Validator/ColumnMoveRestrictionValidator.php @@ -0,0 +1,41 @@ +<?php + +namespace Kanboard\Validator; + +use SimpleValidator\Validator; +use SimpleValidator\Validators; + +/** + * Class ColumnMoveRestrictionValidator + * + * @package Kanboard\Validator + * @author Frederic Guillot + */ +class ColumnMoveRestrictionValidator extends BaseValidator +{ + /** + * Validate creation + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateCreation(array $values) + { + $v = new Validator($values, array( + new Validators\Required('project_id', t('This field is required')), + new Validators\Integer('project_id', t('This value must be an integer')), + new Validators\Required('role_id', t('This field is required')), + new Validators\Integer('role_id', t('This value must be an integer')), + new Validators\Required('src_column_id', t('This field is required')), + new Validators\Integer('src_column_id', t('This value must be an integer')), + new Validators\Required('dst_column_id', t('This field is required')), + new Validators\Integer('dst_column_id', t('This value must be an integer')), + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } +} diff --git a/app/Validator/ColumnRestrictionValidator.php b/app/Validator/ColumnRestrictionValidator.php new file mode 100644 index 00000000..b1b2e5a0 --- /dev/null +++ b/app/Validator/ColumnRestrictionValidator.php @@ -0,0 +1,40 @@ +<?php + +namespace Kanboard\Validator; + +use SimpleValidator\Validator; +use SimpleValidator\Validators; + +/** + * Class ColumnRestrictionValidator + * + * @package Kanboard\Validator + * @author Frederic Guillot + */ +class ColumnRestrictionValidator extends BaseValidator +{ + /** + * Validate creation + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateCreation(array $values) + { + $v = new Validator($values, array( + new Validators\Required('project_id', t('This field is required')), + new Validators\Integer('project_id', t('This value must be an integer')), + new Validators\Required('role_id', t('This field is required')), + new Validators\Integer('role_id', t('This value must be an integer')), + new Validators\Required('rule', t('This field is required')), + new Validators\Required('column_id', t('This field is required')), + new Validators\Integer('column_id', t('This value must be an integer')), + )); + + return array( + $v->execute(), + $v->getErrors() + ); + } +} diff --git a/app/Validator/ProjectRoleValidator.php b/app/Validator/ProjectRoleValidator.php new file mode 100644 index 00000000..4db630db --- /dev/null +++ b/app/Validator/ProjectRoleValidator.php @@ -0,0 +1,70 @@ +<?php + +namespace Kanboard\Validator; + +use SimpleValidator\Validator; +use SimpleValidator\Validators; + +/** + * Class ProjectRoleValidator + * + * @package Kanboard\Validator + * @author Frederic Guillot + */ +class ProjectRoleValidator extends BaseValidator +{ + /** + * Validate creation + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateCreation(array $values) + { + $v = new Validator($values, $this->commonValidationRules()); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Validate modification + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateModification(array $values) + { + $rules = array( + new Validators\Required('role_id', t('The id is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Common validation rules + * + * @access private + * @return array + */ + private function commonValidationRules() + { + return array( + new Validators\Required('role', t('This field is required')), + new Validators\MaxLength('role', t('The maximum length is %d characters', 100), 100), + new Validators\Required('project_id', t('This field is required')), + new Validators\Integer('project_id', t('This value must be an integer')), + new Validators\Integer('role_id', t('This value must be an integer')), + ); + } +} diff --git a/app/Validator/ProjectValidator.php b/app/Validator/ProjectValidator.php index 8c6117a4..5b10026c 100644 --- a/app/Validator/ProjectValidator.php +++ b/app/Validator/ProjectValidator.php @@ -28,7 +28,6 @@ class ProjectValidator extends BaseValidator new Validators\Integer('priority_start', t('This value must be an integer')), new Validators\Integer('priority_end', t('This value must be an integer')), new Validators\Integer('is_active', t('This value must be an integer')), - new Validators\NotEmpty('name', t('This field cannot be empty')), new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50), new Validators\MaxLength('identifier', t('The maximum length is %d characters', 50), 50), new Validators\MaxLength('start_date', t('The maximum length is %d characters', 10), 10), @@ -47,15 +46,15 @@ class ProjectValidator extends BaseValidator */ public function validateCreation(array $values) { - $rules = array( - new Validators\Required('name', t('The project name is required')), - ); - if (! empty($values['identifier'])) { $values['identifier'] = strtoupper($values['identifier']); } - $v = new Validator($values, array_merge($this->commonValidationRules(), $rules)); + $rules = array( + new Validators\Required('name', t('The project name is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); return array( $v->execute(), @@ -77,6 +76,7 @@ class ProjectValidator extends BaseValidator } $rules = array( + new Validators\NotEmpty('name', t('This field cannot be empty')), new Validators\Required('id', t('This value is required')), ); diff --git a/app/Validator/TaskValidator.php b/app/Validator/TaskValidator.php index 8aa5c440..e824dc05 100644 --- a/app/Validator/TaskValidator.php +++ b/app/Validator/TaskValidator.php @@ -28,6 +28,7 @@ class TaskValidator extends BaseValidator new Validators\Integer('owner_id', t('This value must be an integer')), new Validators\Integer('creator_id', t('This value must be an integer')), new Validators\Integer('score', t('This value must be an integer')), + new Validators\Range('score', t('This value must be in the range %d to %d', -2147483647, 2147483647), -2147483647, 2147483647), new Validators\Integer('category_id', t('This value must be an integer')), new Validators\Integer('swimlane_id', t('This value must be an integer')), new Validators\Integer('recurrence_child', t('This value must be an integer')), @@ -41,7 +42,7 @@ class TaskValidator extends BaseValidator new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200), new Validators\MaxLength('reference', t('The maximum length is %d characters', 50), 50), new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getParserFormats()), - new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getParserFormats()), + new Validators\Date('date_started', t('Invalid date'), array($this->dateParser->getUserDateTimeFormat())), new Validators\Numeric('time_spent', t('This value must be numeric')), new Validators\Numeric('time_estimated', t('This value must be numeric')), ); @@ -96,27 +97,6 @@ class TaskValidator extends BaseValidator } /** - * Validate description creation - * - * @access public - * @param array $values Form values - * @return array $valid, $errors [0] = Success or not, [1] = List of errors - */ - public function validateDescriptionCreation(array $values) - { - $rules = array( - new Validators\Required('id', t('The id is required')), - ); - - $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); - - return array( - $v->execute(), - $v->getErrors() - ); - } - - /** * Validate edit recurrence * * @access public diff --git a/app/Validator/UserValidator.php b/app/Validator/UserValidator.php index 9911de50..fe402c47 100644 --- a/app/Validator/UserValidator.php +++ b/app/Validator/UserValidator.php @@ -25,7 +25,7 @@ class UserValidator extends BaseValidator return array( new Validators\MaxLength('role', t('The maximum length is %d characters', 25), 25), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), - new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), UserModel::TABLE, 'id'), + new Validators\Unique('username', t('This username is already taken'), $this->db->getConnection(), UserModel::TABLE, 'id'), new Validators\Email('email', t('Email address invalid')), new Validators\Integer('is_ldap_user', t('This value must be an integer')), ); |
