|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
|
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
declare(strict_types=1); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
25
|
|
|
* |
|
26
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
|
27
|
|
|
* |
|
28
|
|
|
* This program is free software; you can redistribute it and/or |
|
29
|
|
|
* modify it under the terms of the GNU General Public License |
|
30
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
31
|
|
|
* of the License, or (at your option) any later version. |
|
32
|
|
|
* |
|
33
|
|
|
* This program is distributed in the hope that it will be useful, |
|
34
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
35
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
36
|
|
|
* GNU General Public License for more details. |
|
37
|
|
|
* |
|
38
|
|
|
* You should have received a copy of the GNU General Public License |
|
39
|
|
|
* along with this program; if not, write to the Free Software |
|
40
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
41
|
|
|
*/ |
|
42
|
|
|
|
|
43
|
|
|
namespace App\Entity\UserSystem; |
|
44
|
|
|
|
|
45
|
|
|
use App\Entity\Attachments\GroupAttachment; |
|
46
|
|
|
use App\Entity\Base\AbstractStructuralDBElement; |
|
47
|
|
|
use App\Entity\Parameters\GroupParameter; |
|
48
|
|
|
use App\Security\Interfaces\HasPermissionsInterface; |
|
49
|
|
|
use App\Validator\Constraints\ValidPermission; |
|
50
|
|
|
use Doctrine\Common\Collections\Collection; |
|
51
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
52
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* This entity represents an user group. |
|
56
|
|
|
* |
|
57
|
|
|
* @ORM\Entity() |
|
58
|
|
|
* @ORM\Table("`groups`") |
|
59
|
|
|
*/ |
|
60
|
|
|
class Group extends AbstractStructuralDBElement implements HasPermissionsInterface |
|
61
|
|
|
{ |
|
62
|
|
|
/** |
|
63
|
|
|
* @ORM\OneToMany(targetEntity="Group", mappedBy="parent") |
|
64
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
|
65
|
|
|
*/ |
|
66
|
|
|
protected $children; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @ORM\ManyToOne(targetEntity="Group", inversedBy="children") |
|
70
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $parent; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @ORM\OneToMany(targetEntity="User", mappedBy="group") |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $users; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var bool If true all users associated with this group must have enabled some kind of 2 factor authentication |
|
81
|
|
|
* @ORM\Column(type="boolean", name="enforce_2fa") |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $enforce2FA = false; |
|
84
|
|
|
/** |
|
85
|
|
|
* @var Collection<int, GroupAttachment> |
|
86
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
|
87
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
|
88
|
|
|
* @Assert\Valid() |
|
89
|
|
|
*/ |
|
90
|
|
|
protected $attachments; |
|
91
|
|
|
|
|
92
|
|
|
/** @var PermissionsEmbed |
|
93
|
|
|
* @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_") |
|
94
|
|
|
* @ValidPermission() |
|
95
|
|
|
*/ |
|
96
|
|
|
protected $permissions; |
|
97
|
|
|
|
|
98
|
|
|
/** @var Collection<int, GroupParameter> |
|
99
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\GroupParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
|
100
|
|
|
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"}) |
|
101
|
|
|
* @Assert\Valid() |
|
102
|
|
|
*/ |
|
103
|
|
|
protected $parameters; |
|
104
|
|
|
|
|
105
|
|
|
public function __construct() |
|
106
|
|
|
{ |
|
107
|
|
|
parent::__construct(); |
|
108
|
|
|
$this->permissions = new PermissionsEmbed(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Check if the users of this group are enforced to have two factor authentification (2FA) enabled. |
|
113
|
|
|
* |
|
114
|
|
|
* @return bool |
|
115
|
|
|
*/ |
|
116
|
|
|
public function isEnforce2FA(): bool |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->enforce2FA; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Sets if the user of this group are enforced to have two factor authentification enabled. |
|
123
|
|
|
* |
|
124
|
|
|
* @param bool $enforce2FA True, if the users of this group are enforced to have 2FA enabled. |
|
125
|
|
|
* |
|
126
|
|
|
* @return $this |
|
127
|
|
|
*/ |
|
128
|
|
|
public function setEnforce2FA(bool $enforce2FA): self |
|
129
|
|
|
{ |
|
130
|
|
|
$this->enforce2FA = $enforce2FA; |
|
131
|
|
|
|
|
132
|
|
|
return $this; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function getPermissions(): PermissionsEmbed |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->permissions; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|