1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* part-db version 0.1 |
6
|
|
|
* Copyright (C) 2005 Christoph Lechner |
7
|
|
|
* http://www.cl-projects.de/ |
8
|
|
|
* |
9
|
|
|
* part-db version 0.2+ |
10
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
11
|
|
|
* http://code.google.com/p/part-db/ |
12
|
|
|
* |
13
|
|
|
* Part-DB Version 0.4+ |
14
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
15
|
|
|
* https://github.com/jbtronics |
16
|
|
|
* |
17
|
|
|
* This program is free software; you can redistribute it and/or |
18
|
|
|
* modify it under the terms of the GNU General Public License |
19
|
|
|
* as published by the Free Software Foundation; either version 2 |
20
|
|
|
* of the License, or (at your option) any later version. |
21
|
|
|
* |
22
|
|
|
* This program is distributed in the hope that it will be useful, |
23
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
24
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25
|
|
|
* GNU General Public License for more details. |
26
|
|
|
* |
27
|
|
|
* You should have received a copy of the GNU General Public License |
28
|
|
|
* along with this program; if not, write to the Free Software |
29
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
namespace App\Entity; |
34
|
|
|
|
35
|
|
|
use App\Entity\Embeddables\PermissionEntity; |
|
|
|
|
36
|
|
|
use App\Security\Interfaces\HasPermissionsInterface; |
37
|
|
|
use Doctrine\ORM\Mapping as ORM; |
38
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
39
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* This entity represents a user, which can log in and have permissions. |
43
|
|
|
* Also this entity is able to save some informations about the user, like the names, email-address and other info. |
44
|
|
|
* |
45
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\UserRepository") |
46
|
|
|
* @ORM\Table("users") |
47
|
|
|
*/ |
48
|
|
|
class User extends NamedDBElement implements UserInterface, HasPermissionsInterface |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* @ORM\Id() |
52
|
|
|
* @ORM\GeneratedValue() |
53
|
|
|
* @ORM\Column(type="integer") |
54
|
|
|
*/ |
55
|
|
|
protected $id; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @ORM\Column(type="string", length=180, unique=true) |
59
|
|
|
* @Assert\NotBlank |
60
|
|
|
*/ |
61
|
|
|
protected $name; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* //@ORM\Column(type="json") |
65
|
|
|
*/ |
66
|
|
|
//protected $roles = []; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var string|null The hashed password |
70
|
|
|
* @ORM\Column(type="string", nullable=true) |
71
|
|
|
*/ |
72
|
|
|
protected $password; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var string|null The first name of the User |
76
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
77
|
|
|
*/ |
78
|
|
|
protected $first_name = ""; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var string|null The last name of the User |
82
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
83
|
|
|
*/ |
84
|
|
|
protected $last_name = ""; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var string|null The department the user is working |
88
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
89
|
|
|
*/ |
90
|
|
|
protected $department = ""; |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var string|null The email address of the user |
95
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
96
|
|
|
* @Assert\Email() |
97
|
|
|
*/ |
98
|
|
|
protected $email = ""; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var string|null The language/locale the user prefers |
102
|
|
|
* @ORM\Column(type="string", name="config_language", nullable=true) |
103
|
|
|
*/ |
104
|
|
|
protected $language = ""; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var string|null The timezone the user prefers |
108
|
|
|
* @ORM\Column(type="string", name="config_timezone", nullable=true) |
109
|
|
|
*/ |
110
|
|
|
protected $timezone = ""; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var string|null The theme |
114
|
|
|
* @ORM\Column(type="string", name="config_theme", nullable=true) |
115
|
|
|
*/ |
116
|
|
|
protected $theme = ""; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @var Group|null The group this user belongs to. |
120
|
|
|
* @ORM\ManyToOne(targetEntity="Group", inversedBy="users", fetch="EAGER") |
121
|
|
|
* @ORM\JoinColumn(name="group_id", referencedColumnName="id") |
122
|
|
|
*/ |
123
|
|
|
protected $group; |
124
|
|
|
|
125
|
|
|
/** @var PermissionsEmbed |
126
|
|
|
* @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_") |
127
|
|
|
*/ |
128
|
|
|
protected $permissions; |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* A visual identifier that represents this user. |
133
|
|
|
* |
134
|
|
|
* @see UserInterface |
135
|
|
|
*/ |
136
|
|
|
public function getUsername(): string |
137
|
|
|
{ |
138
|
|
|
return (string) $this->name; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @see UserInterface |
143
|
|
|
*/ |
144
|
|
|
public function getRoles(): array |
145
|
|
|
{ |
146
|
|
|
$roles = []; |
147
|
|
|
//$roles = $this->roles; |
148
|
|
|
// guarantee every user at least has ROLE_USER |
149
|
|
|
$roles[] = 'ROLE_USER'; |
150
|
|
|
|
151
|
|
|
return array_unique($roles); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setRoles(array $roles): self |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
//$this->roles = $roles; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @see UserInterface |
163
|
|
|
* Gets the password hash for this entity. |
164
|
|
|
*/ |
165
|
|
|
public function getPassword(): string |
166
|
|
|
{ |
167
|
|
|
return (string) $this->password; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Sets the password hash for this user. |
172
|
|
|
* @param string $password |
173
|
|
|
* @return User |
174
|
|
|
*/ |
175
|
|
|
public function setPassword(string $password): self |
176
|
|
|
{ |
177
|
|
|
$this->password = $password; |
178
|
|
|
|
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @see UserInterface |
184
|
|
|
*/ |
185
|
|
|
public function getSalt() |
186
|
|
|
{ |
187
|
|
|
// not needed when using the "bcrypt" algorithm in security.yaml |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @see UserInterface |
192
|
|
|
*/ |
193
|
|
|
public function eraseCredentials() |
194
|
|
|
{ |
195
|
|
|
// If you store any temporary, sensitive data on the user, clear it here |
196
|
|
|
// $this->plainPassword = null; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Returns the ID as an string, defined by the element class. |
201
|
|
|
* This should have a form like P000014, for a part with ID 14. |
202
|
|
|
* @return string The ID as a string; |
203
|
|
|
*/ |
204
|
|
|
public function getIDString(): string |
205
|
|
|
{ |
206
|
|
|
return 'U' . sprintf('%06d', $this->getID()); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function getPermissions() : PermissionsEmbed |
211
|
|
|
{ |
212
|
|
|
return $this->permissions; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/************************************************ |
216
|
|
|
* Getters |
217
|
|
|
************************************************/ |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return string |
221
|
|
|
*/ |
222
|
|
|
public function getFirstName(): ?string |
223
|
|
|
{ |
224
|
|
|
return $this->first_name; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param string $first_name |
229
|
|
|
* @return User |
230
|
|
|
*/ |
231
|
|
|
public function setFirstName(?string $first_name): User |
232
|
|
|
{ |
233
|
|
|
$this->first_name = $first_name; |
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
|
|
public function getLastName(): ?string |
241
|
|
|
{ |
242
|
|
|
return $this->last_name; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param string $last_name |
247
|
|
|
* @return User |
248
|
|
|
*/ |
249
|
|
|
public function setLastName(?string $last_name): User |
250
|
|
|
{ |
251
|
|
|
$this->last_name = $last_name; |
252
|
|
|
return $this; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @return string |
257
|
|
|
*/ |
258
|
|
|
public function getDepartment(): ?string |
259
|
|
|
{ |
260
|
|
|
return $this->department; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @param string $department |
265
|
|
|
* @return User |
266
|
|
|
*/ |
267
|
|
|
public function setDepartment(?string $department): User |
268
|
|
|
{ |
269
|
|
|
$this->department = $department; |
270
|
|
|
return $this; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @return string |
275
|
|
|
*/ |
276
|
|
|
public function getEmail(): ?string |
277
|
|
|
{ |
278
|
|
|
return $this->email; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @param string $email |
283
|
|
|
* @return User |
284
|
|
|
*/ |
285
|
|
|
public function setEmail(?string $email): User |
286
|
|
|
{ |
287
|
|
|
$this->email = $email; |
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @return string |
293
|
|
|
*/ |
294
|
|
|
public function getLanguage(): ?string |
295
|
|
|
{ |
296
|
|
|
return $this->language; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param string $language |
301
|
|
|
* @return User |
302
|
|
|
*/ |
303
|
|
|
public function setLanguage(?string $language): User |
304
|
|
|
{ |
305
|
|
|
$this->language = $language; |
306
|
|
|
return $this; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @return string |
311
|
|
|
*/ |
312
|
|
|
public function getTimezone(): ?string |
313
|
|
|
{ |
314
|
|
|
return $this->timezone; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @param string $timezone |
319
|
|
|
* @return User |
320
|
|
|
*/ |
321
|
|
|
public function setTimezone(?string $timezone): User |
322
|
|
|
{ |
323
|
|
|
$this->timezone = $timezone; |
324
|
|
|
return $this; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @return string |
329
|
|
|
*/ |
330
|
|
|
public function getTheme(): ?string |
331
|
|
|
{ |
332
|
|
|
return $this->theme; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @param string $theme |
337
|
|
|
* @return User |
338
|
|
|
*/ |
339
|
|
|
public function setTheme(?string $theme): User |
340
|
|
|
{ |
341
|
|
|
$this->theme = $theme; |
342
|
|
|
return $this; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
public function getGroup(): ?Group |
346
|
|
|
{ |
347
|
|
|
return $this->group; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
public function setGroup(?Group $group): self |
351
|
|
|
{ |
352
|
|
|
$this->group = $group; |
353
|
|
|
return $this; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
} |
357
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths