Update user to have avatars and specify their type

This commit is contained in:
2025-02-24 14:33:03 +01:00
parent 723f2d3180
commit 87beb08723
3 changed files with 78 additions and 11 deletions
+25 -11
View File
@@ -7,6 +7,7 @@ use ApiPlatform\Metadata as API;
use App\ApiResource\Accounting\AccountingApiResource;
use App\Dto\UserSignupDto;
use App\Entity\User\User;
use App\Entity\User\UserType;
use App\Filter\OrderedLikeFilter;
use App\Filter\UserQueryFilter;
use App\State\ApiResourceStateProcessor;
@@ -47,6 +48,29 @@ class UserApiResource
#[Assert\Regex('/^[a-z0-9_]+$/')]
public string $handle;
/**
* URL to the avatar image of this User.
*/
#[Assert\Url()]
public string $avatar;
/**
* Is this User for an individual acting on their own or a group of individuals?
*/
#[API\ApiProperty(securityPostDenormalize: 'is_granted("USER_EDIT")')]
public UserType $type;
/**
* A list of the roles assigned to this User. Admin scoped property.
*
* @var array<int, string>
*/
#[API\ApiProperty(
security: 'is_granted("ROLE_ADMIN")',
securityPostDenormalize: 'is_granted("ROLE_ADMIN")'
)]
public array $roles;
/**
* The Accounting for this User monetary movements.
*/
@@ -61,17 +85,6 @@ class UserApiResource
#[API\ApiProperty(writable: false)]
public array $projects;
/**
* A list of the roles assigned to this User. Admin scoped property.
*
* @var array<int, string>
*/
#[API\ApiProperty(
security: 'is_granted("ROLE_ADMIN")',
securityPostDenormalize: 'is_granted("ROLE_ADMIN")'
)]
public array $roles;
/**
* Has this User confirmed their email address?
*/
@@ -81,5 +94,6 @@ class UserApiResource
/**
* A flag determined by the platform for Users who are known to be active.
*/
#[API\ApiProperty(writable: false)]
public bool $active;
}
+37
View File
@@ -13,6 +13,7 @@ use App\Repository\User\UserRepository;
use AutoMapper\Attribute\MapProvider;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@@ -95,6 +96,18 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Account
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?UserPersonal $personalData = null;
/**
* Is this user for an individual acting on their own or a larger group of individuals?
*/
#[ORM\Column(enumType: UserType::class)]
private ?UserType $type = null;
/**
* URL to the avatar image of this User.
*/
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $avatar = null;
public function __construct()
{
$this->accounting = Accounting::of($this);
@@ -306,4 +319,28 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Account
return $this;
}
public function getType(): ?UserType
{
return $this->type;
}
public function setType(UserType $type): static
{
$this->type = $type;
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): static
{
$this->avatar = $avatar;
return $this;
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Entity\User;
enum UserType: string
{
/**
* People who sign-up on their own and do not represent any other legal or natural person.
*/
case Individual = 'individual';
/**
* Sometimes organizations want to sign-up and represent themselves.
*/
case Organization = 'organization';
}