Move task link validator methods
This commit is contained in:
@@ -69,7 +69,7 @@ class Tasklink extends Base
|
||||
$values = $this->request->getValues();
|
||||
$ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax');
|
||||
|
||||
list($valid, $errors) = $this->taskLink->validateCreation($values);
|
||||
list($valid, $errors) = $this->taskLinkValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->taskLink->create($values['task_id'], $values['opposite_task_id'], $values['link_id'])) {
|
||||
@@ -125,7 +125,7 @@ class Tasklink extends Base
|
||||
$task = $this->getTask();
|
||||
$values = $this->request->getValues();
|
||||
|
||||
list($valid, $errors) = $this->taskLink->validateModification($values);
|
||||
list($valid, $errors) = $this->taskLinkValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
if ($this->taskLink->update($values['id'], $values['task_id'], $values['opposite_task_id'], $values['link_id'])) {
|
||||
|
||||
@@ -100,7 +100,6 @@ use Pimple\Container;
|
||||
* @property \Kanboard\Model\TaskPermission $taskPermission
|
||||
* @property \Kanboard\Model\TaskPosition $taskPosition
|
||||
* @property \Kanboard\Model\TaskStatus $taskStatus
|
||||
* @property \Kanboard\Model\TaskValidator $taskValidator
|
||||
* @property \Kanboard\Model\TaskMetadata $taskMetadata
|
||||
* @property \Kanboard\Model\Transition $transition
|
||||
* @property \Kanboard\Model\User $user
|
||||
@@ -114,6 +113,9 @@ use Pimple\Container;
|
||||
* @property \Kanboard\Model\UserMetadata $userMetadata
|
||||
* @property \Kanboard\Model\Webhook $webhook
|
||||
* @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator
|
||||
* @property \Kanboard\Validator\TaskLinkValidator $taskLinkValidator
|
||||
* @property \Kanboard\Validator\TaskValidator $taskValidator
|
||||
* @property \Kanboard\Validator\UserValidator $userValidator
|
||||
* @property \Psr\Log\LoggerInterface $logger
|
||||
* @property \PicoDb\Database $db
|
||||
* @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Kanboard\Event\TaskLinkEvent;
|
||||
|
||||
/**
|
||||
@@ -261,59 +259,4 @@ class TaskLink extends Base
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Required('task_id', t('Field required')),
|
||||
new Validators\Required('opposite_task_id', t('Field required')),
|
||||
new Validators\Required('link_id', t('Field required')),
|
||||
new Validators\NotEquals('opposite_task_id', 'task_id', t('A task cannot be linked to itself')),
|
||||
new Validators\Exists('opposite_task_id', t('This linked task id doesn\'t exists'), $this->db->getConnection(), Task::TABLE, 'id')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('id', t('Field required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
namespace Kanboard\Model;
|
||||
|
||||
use PicoDb\Database;
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Kanboard\Core\Session\SessionManager;
|
||||
use Kanboard\Core\Security\Token;
|
||||
use Kanboard\Core\Security\Role;
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ class ClassProvider implements ServiceProviderInterface
|
||||
'Validator' => array(
|
||||
'PasswordResetValidator',
|
||||
'TaskValidator',
|
||||
'TaskLinkValidator',
|
||||
'UserValidator',
|
||||
),
|
||||
'Core' => array(
|
||||
|
||||
71
app/Validator/TaskLinkValidator.php
Normal file
71
app/Validator/TaskLinkValidator.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Validator;
|
||||
|
||||
use SimpleValidator\Validator;
|
||||
use SimpleValidator\Validators;
|
||||
use Kanboard\Model\Task;
|
||||
|
||||
/**
|
||||
* TaskLink Validator
|
||||
*
|
||||
* @package validator
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class TaskLinkValidator extends Base
|
||||
{
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Required('task_id', t('Field required')),
|
||||
new Validators\Required('opposite_task_id', t('Field required')),
|
||||
new Validators\Required('link_id', t('Field required')),
|
||||
new Validators\NotEquals('opposite_task_id', 'task_id', t('A task cannot be linked to itself')),
|
||||
new Validators\Exists('opposite_task_id', t('This linked task id doesn\'t exists'), $this->db->getConnection(), Task::TABLE, 'id')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('id', t('Field required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user