1 | <?php |
||
2 | /** |
||
3 | * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
||
4 | * |
||
5 | * Copyright (C) 2019 - 2022 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 | namespace App\Entity\UserSystem; |
||
24 | |||
25 | use App\Entity\Attachments\GroupAttachment; |
||
26 | use App\Entity\Base\AbstractStructuralDBElement; |
||
27 | use App\Entity\Parameters\GroupParameter; |
||
28 | use App\Security\Interfaces\HasPermissionsInterface; |
||
29 | use App\Validator\Constraints\ValidPermission; |
||
30 | use Doctrine\Common\Collections\ArrayCollection; |
||
31 | use Doctrine\Common\Collections\Collection; |
||
32 | use Doctrine\ORM\Mapping as ORM; |
||
33 | use Symfony\Component\Validator\Constraints as Assert; |
||
34 | |||
35 | /** |
||
36 | * This entity represents an user group. |
||
37 | * |
||
38 | * @ORM\Entity() |
||
39 | * @ORM\Table("`groups`", indexes={ |
||
40 | * @ORM\Index(name="group_idx_name", columns={"name"}), |
||
41 | * @ORM\Index(name="group_idx_parent_name", columns={"parent_id", "name"}), |
||
42 | * }) |
||
43 | */ |
||
44 | class Group extends AbstractStructuralDBElement implements HasPermissionsInterface |
||
45 | { |
||
46 | /** |
||
47 | * @ORM\OneToMany(targetEntity="Group", mappedBy="parent") |
||
48 | * @ORM\OrderBy({"name" = "ASC"}) |
||
49 | * @var Collection |
||
50 | */ |
||
51 | protected $children; |
||
52 | |||
53 | /** |
||
54 | * @ORM\ManyToOne(targetEntity="Group", inversedBy="children") |
||
55 | * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
||
56 | */ |
||
57 | protected $parent; |
||
58 | |||
59 | /** |
||
60 | * @ORM\OneToMany(targetEntity="User", mappedBy="group") |
||
61 | * @var Collection<User> |
||
62 | */ |
||
63 | protected $users; |
||
64 | |||
65 | /** |
||
66 | * @var bool If true all users associated with this group must have enabled some kind of 2 factor authentication |
||
67 | * @ORM\Column(type="boolean", name="enforce_2fa") |
||
68 | */ |
||
69 | protected $enforce2FA = false; |
||
70 | /** |
||
71 | * @var Collection<int, GroupAttachment> |
||
72 | * @ORM\OneToMany(targetEntity="App\Entity\Attachments\GroupAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
||
73 | * @ORM\OrderBy({"name" = "ASC"}) |
||
74 | * @Assert\Valid() |
||
75 | */ |
||
76 | protected $attachments; |
||
77 | |||
78 | /** |
||
79 | * @var PermissionData|null |
||
80 | * @ValidPermission() |
||
81 | * @ORM\Embedded(class="PermissionData", columnPrefix="permissions_") |
||
82 | */ |
||
83 | protected ?PermissionData $permissions = null; |
||
84 | |||
85 | /** @var Collection<int, GroupParameter> |
||
86 | * @ORM\OneToMany(targetEntity="App\Entity\Parameters\GroupParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
||
87 | * @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"}) |
||
88 | * @Assert\Valid() |
||
89 | */ |
||
90 | protected $parameters; |
||
91 | |||
92 | public function __construct() |
||
93 | { |
||
94 | parent::__construct(); |
||
95 | $this->permissions = new PermissionData(); |
||
96 | $this->users = new ArrayCollection(); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Check if the users of this group are enforced to have two factor authentification (2FA) enabled. |
||
101 | */ |
||
102 | public function isEnforce2FA(): bool |
||
103 | { |
||
104 | return $this->enforce2FA; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Sets if the user of this group are enforced to have two factor authentification enabled. |
||
109 | * |
||
110 | * @param bool $enforce2FA true, if the users of this group are enforced to have 2FA enabled |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function setEnforce2FA(bool $enforce2FA): self |
||
115 | { |
||
116 | $this->enforce2FA = $enforce2FA; |
||
117 | |||
118 | return $this; |
||
119 | } |
||
120 | |||
121 | public function getPermissions(): PermissionData |
||
122 | { |
||
123 | if ($this->permissions === null) { |
||
124 | $this->permissions = new PermissionData(); |
||
125 | } |
||
126 | |||
127 | return $this->permissions; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
128 | } |
||
129 | |||
130 | public function getUsers(): Collection |
||
131 | { |
||
132 | return $this->users; |
||
133 | } |
||
134 | } |
||
135 |