beta 3 (#3780)
* merge master - allow to upload twig invoice templates via UI * support adding existing teams with same name * permissions cannot be set right after role was created - fixes #3777 * allow to deactivate unique customer number validation - fixes #3762 * invalid message when trying to edit locked or exported timesheets in calendar - fixes #3766 * updated icons and manifest - fixes #3761
This commit is contained in:
29
src/Validator/Constraints/Customer.php
Normal file
29
src/Validator/Constraints/Customer.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
final class Customer extends Constraint
|
||||
{
|
||||
public const CUSTOMER_NUMBER_EXISTING = 'kimai-customer-00';
|
||||
|
||||
protected const ERROR_NAMES = [
|
||||
self::CUSTOMER_NUMBER_EXISTING => 'This account number is already used.',
|
||||
];
|
||||
|
||||
public string $message = 'This customer has invalid settings.';
|
||||
|
||||
public function getTargets(): string|array
|
||||
{
|
||||
return self::CLASS_CONSTRAINT;
|
||||
}
|
||||
}
|
||||
50
src/Validator/Constraints/CustomerValidator.php
Normal file
50
src/Validator/Constraints/CustomerValidator.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Validator\Constraints;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Customer as CustomerEntity;
|
||||
use App\Repository\CustomerRepository;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
final class CustomerValidator extends ConstraintValidator
|
||||
{
|
||||
public function __construct(private SystemConfiguration $systemConfiguration, private CustomerRepository $customerRepository)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CustomerEntity|mixed $value
|
||||
* @param Constraint $constraint
|
||||
*/
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
if (!($constraint instanceof Customer)) {
|
||||
throw new UnexpectedTypeException($constraint, Customer::class);
|
||||
}
|
||||
|
||||
if (!($value instanceof CustomerEntity)) {
|
||||
throw new UnexpectedTypeException($value, CustomerEntity::class);
|
||||
}
|
||||
|
||||
if ((bool) $this->systemConfiguration->find('customer.rules.allow_duplicate_number') === false && (($number = $value->getNumber()) !== null)) {
|
||||
$tmp = $this->customerRepository->findOneBy(['number' => $number]);
|
||||
if ($tmp !== null && $tmp->getId() !== $value->getId()) {
|
||||
$this->context->buildViolation(Customer::getErrorName(Customer::CUSTOMER_NUMBER_EXISTING))
|
||||
->atPath('number')
|
||||
->setTranslationDomain('validators')
|
||||
->setCode(Customer::CUSTOMER_NUMBER_EXISTING)
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user