-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCreateAdministratorRequest.php
More file actions
102 lines (93 loc) · 3.17 KB
/
CreateAdministratorRequest.php
File metadata and controls
102 lines (93 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
namespace PhpList\RestBundle\Identity\Request;
use OpenApi\Attributes as OA;
use PhpList\Core\Domain\Identity\Model\Administrator;
use PhpList\Core\Domain\Identity\Model\Dto\CreateAdministratorDto;
use PhpList\RestBundle\Common\Request\RequestInterface;
use PhpList\RestBundle\Identity\Validator\Constraint\UniqueEmail;
use PhpList\RestBundle\Identity\Validator\Constraint\UniqueLoginName;
use Symfony\Component\Validator\Constraints as Assert;
#[OA\Schema(
schema: 'CreateAdministratorRequest',
required: ['login_name', 'password', 'email', 'super_user'],
properties: [
new OA\Property(
property: 'login_name',
type: 'string',
maxLength: 255,
minLength: 3,
example: 'admin'
),
new OA\Property(
property: 'password',
type: 'string',
format: 'password',
maxLength: 255,
minLength: 6,
example: 'StrongP@ssw0rd'
),
new OA\Property(
property: 'email',
type: 'string',
format: 'email',
example: 'admin@example.com'
),
new OA\Property(
property: 'super_user',
type: 'boolean',
example: false
),
new OA\Property(
property: 'privileges',
description: 'Array of privileges where keys are privilege names and values are booleans',
properties: [
new OA\Property(property: 'subscribers', type: 'boolean', example: true),
new OA\Property(property: 'campaigns', type: 'boolean', example: false),
new OA\Property(property: 'statistics', type: 'boolean', example: true),
new OA\Property(property: 'settings', type: 'boolean', example: false),
],
type: 'object',
example: ['subscribers' => true, 'campaigns' => false, 'statistics' => true, 'settings' => false]
),
],
type: 'object'
)]
class CreateAdministratorRequest implements RequestInterface
{
#[Assert\NotBlank]
#[Assert\Length(min: 3, max: 255)]
#[UniqueLoginName]
public string $loginName;
#[Assert\NotBlank]
#[Assert\Length(min: 6, max: 255)]
public string $password;
#[Assert\NotBlank]
#[Assert\Email]
#[UniqueEmail(Administrator::class)]
public string $email;
#[Assert\NotNull]
#[Assert\Type('bool')]
public bool $superUser = false;
/**
* Array of privileges where keys are privilege names (from PrivilegeFlag enum) and values are booleans.
* Example: ['subscribers' => true, 'campaigns' => false, 'statistics' => true, 'settings' => false]
*/
#[Assert\Type('array')]
#[Assert\All([
'constraints' => [
new Assert\Type(['type' => 'bool']),
],
])]
public array $privileges = [];
public function getDto(): CreateAdministratorDto
{
return new CreateAdministratorDto(
loginName: $this->loginName,
password: $this->password,
email: $this->email,
isSuperUser: $this->superUser,
privileges: $this->privileges
);
}
}