mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-07 17:04:30 +02:00
Add proper length constraint validations to all string mapped ORM fields, so they show a nice validation error, instead of a 500 error
Fixes issue #544
This commit is contained in:
parent
113e5b3bcd
commit
dc7c13479c
17 changed files with 43 additions and 0 deletions
|
@ -36,6 +36,7 @@ use Doctrine\DBAL\Types\Types;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ApiTokenRepository::class)]
|
||||
|
@ -64,6 +65,7 @@ class ApiToken implements TimeStampableInterface
|
|||
protected int $id;
|
||||
|
||||
#[ORM\Column(type: Types::STRING)]
|
||||
#[Length(max: 255)]
|
||||
#[NotBlank]
|
||||
#[Groups('token:read')]
|
||||
protected string $name = '';
|
||||
|
|
|
@ -27,6 +27,7 @@ use Doctrine\DBAL\Types\Types;
|
|||
use App\Entity\Base\TimestampTrait;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Jbtronics\TFAWebauthn\Model\LegacyU2FKeyInterface;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
|
@ -44,6 +45,7 @@ class U2FKey implements LegacyU2FKeyInterface, TimeStampableInterface
|
|||
* @var string
|
||||
**/
|
||||
#[ORM\Column(type: Types::STRING, length: 128)]
|
||||
#[Length(max: 128)]
|
||||
public string $keyHandle = '';
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,6 +50,7 @@ use Jbtronics\TFAWebauthn\Model\LegacyU2FKeyInterface;
|
|||
use Nbgrp\OneloginSamlBundle\Security\User\SamlUserInterface;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Webauthn\PublicKeyCredentialUserEntity;
|
||||
use function count;
|
||||
use DateTime;
|
||||
|
@ -204,6 +205,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
#[Assert\Email]
|
||||
#[Groups(['simple', 'extended', 'full', 'import', 'user:read'])]
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||
#[Length(max: 255)]
|
||||
protected ?string $email = '';
|
||||
|
||||
/**
|
||||
|
@ -218,6 +220,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*/
|
||||
#[Groups(['simple', 'extended', 'full', 'import', 'user:read'])]
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||
#[Length(max: 255)]
|
||||
protected ?string $department = '';
|
||||
|
||||
/**
|
||||
|
@ -225,6 +228,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*/
|
||||
#[Groups(['simple', 'extended', 'full', 'import', 'user:read'])]
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||
#[Length(max: 255)]
|
||||
protected ?string $last_name = '';
|
||||
|
||||
/**
|
||||
|
@ -232,6 +236,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*/
|
||||
#[Groups(['simple', 'extended', 'full', 'import', 'user:read'])]
|
||||
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
|
||||
#[Length(max: 255)]
|
||||
protected ?string $first_name = '';
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ use App\Entity\Contracts\TimeStampableInterface;
|
|||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Base\TimestampTrait;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Webauthn\PublicKeyCredentialSource as BasePublicKeyCredentialSource;
|
||||
|
||||
|
@ -43,6 +44,7 @@ class WebauthnKey extends BasePublicKeyCredentialSource implements TimeStampable
|
|||
|
||||
#[ORM\Column(type: Types::STRING)]
|
||||
#[NotBlank]
|
||||
#[Length(max: 255)]
|
||||
protected string $name = '';
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'webauthn_keys')]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue