Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #271 | Créer une nouvelle expédition (étape 1) | ## Description de la PR ## Modification du .env ## Check list [x ] Pas de régression TU/TI/TF rédigée [x ] TU/TI/TF OK [x ] CHANGELOG modifié Co-authored-by: kevin <kevin@yuno.malio.fr> Reviewed-on: #12 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: Matteo <matteo@yuno.malio.fr> Co-committed-by: Matteo <matteo@yuno.malio.fr>
133 lines
3.5 KiB
PHP
133 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
use ApiPlatform\Metadata\Get;
|
|
use ApiPlatform\Metadata\GetCollection;
|
|
use ApiPlatform\Metadata\Patch;
|
|
use ApiPlatform\Metadata\Post;
|
|
use App\State\MeProvider;
|
|
use App\State\UserPasswordProcessor;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'user', schema: 'public')]
|
|
#[ApiResource(
|
|
operations: [
|
|
new Get(
|
|
uriTemplate: '/me',
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
security: "is_granted('ROLE_USER')",
|
|
provider: MeProvider::class
|
|
),
|
|
new Get(
|
|
requirements: ['id' => '\d+'],
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
security: "is_granted('ROLE_USER')"
|
|
),
|
|
new Post(
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
denormalizationContext: ['groups' => ['user:write']],
|
|
security: "is_granted('ROLE_ADMIN')",
|
|
processor: UserPasswordProcessor::class
|
|
),
|
|
new Patch(
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
denormalizationContext: ['groups' => ['user:write']],
|
|
security: "is_granted('ROLE_ADMIN')",
|
|
processor: UserPasswordProcessor::class
|
|
),
|
|
new GetCollection(
|
|
normalizationContext: ['groups' => ['user-login:read']],
|
|
security: "is_granted('PUBLIC_ACCESS')"
|
|
),
|
|
new GetCollection(
|
|
uriTemplate: '/admin/users',
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
security: "is_granted('ROLE_ADMIN')"
|
|
),
|
|
],
|
|
normalizationContext: ['groups' => ['user:read']],
|
|
paginationEnabled: false
|
|
)]
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: 'integer')]
|
|
#[Groups(['user:read', 'user-login:read', 'reception:read', 'shipment:read'])]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 180, unique: true)]
|
|
#[Groups(['user:read', 'user:write', 'user-login:read', 'reception:read', 'shipment:read'])]
|
|
private string $username = '';
|
|
|
|
#[ORM\Column(type: 'json')]
|
|
#[Groups(['user:write', 'user:read'])]
|
|
private array $roles = [];
|
|
|
|
#[ORM\Column]
|
|
#[Groups(['user:write'])]
|
|
private string $password = '';
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUsername(): string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function setUsername(string $username): self
|
|
{
|
|
$this->username = $username;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUserIdentifier(): string
|
|
{
|
|
return $this->username;
|
|
}
|
|
|
|
public function getRoles(): array
|
|
{
|
|
$roles = $this->roles;
|
|
$roles[] = 'ROLE_USER';
|
|
|
|
return array_unique($roles);
|
|
}
|
|
|
|
public function setRoles(array $roles): self
|
|
{
|
|
$this->roles = $roles;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPassword(): string
|
|
{
|
|
return $this->password;
|
|
}
|
|
|
|
public function setPassword(string $password): self
|
|
{
|
|
$this->password = $password;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function eraseCredentials(): void
|
|
{
|
|
// No-op: we don't store temporary sensitive data on the entity.
|
|
}
|
|
}
|