2019-03-15 13:18:47 +01:00
|
|
|
<?php
|
2020-02-22 18:14:36 +01:00
|
|
|
/**
|
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
|
|
|
*
|
2022-11-29 22:28:53 +01:00
|
|
|
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
2020-02-22 18:14:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-01-05 15:46:58 +01:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-08-12 15:47:57 +02:00
|
|
|
namespace App\Entity\UserSystem;
|
2019-03-15 13:18:47 +01:00
|
|
|
|
2019-09-24 13:39:49 +02:00
|
|
|
use App\Entity\Attachments\GroupAttachment;
|
2020-02-01 19:48:07 +01:00
|
|
|
use App\Entity\Base\AbstractStructuralDBElement;
|
2020-03-11 21:48:47 +01:00
|
|
|
use App\Entity\Parameters\GroupParameter;
|
2019-03-18 19:05:41 +01:00
|
|
|
use App\Security\Interfaces\HasPermissionsInterface;
|
2019-09-11 18:50:23 +02:00
|
|
|
use App\Validator\Constraints\ValidPermission;
|
2020-05-17 21:52:47 +02:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2019-09-24 13:39:49 +02:00
|
|
|
use Doctrine\Common\Collections\Collection;
|
2019-03-15 13:18:47 +01:00
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2023-03-13 22:16:02 +01:00
|
|
|
use Symfony\Component\Serializer\Annotation\Groups;
|
2020-03-11 21:48:47 +01:00
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
2019-03-15 13:18:47 +01:00
|
|
|
|
|
|
|
/**
|
2023-04-15 23:14:53 +02:00
|
|
|
* This entity represents a user group.
|
2019-03-15 13:18:47 +01:00
|
|
|
*/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Entity]
|
|
|
|
#[ORM\Table('`groups`')]
|
|
|
|
#[ORM\Index(name: 'group_idx_name', columns: ['name'])]
|
|
|
|
#[ORM\Index(name: 'group_idx_parent_name', columns: ['parent_id', 'name'])]
|
2020-02-01 19:48:07 +01:00
|
|
|
class Group extends AbstractStructuralDBElement implements HasPermissionsInterface
|
2019-03-15 13:18:47 +01:00
|
|
|
{
|
|
|
|
/**
|
2023-04-16 23:58:03 +02:00
|
|
|
* @var Collection<int, self>
|
2019-03-15 13:18:47 +01:00
|
|
|
*/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: 'Group', mappedBy: 'parent')]
|
|
|
|
#[ORM\OrderBy(['name' => 'ASC'])]
|
2023-04-15 22:25:03 +02:00
|
|
|
protected Collection $children;
|
2019-03-15 13:18:47 +01:00
|
|
|
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\ManyToOne(targetEntity: 'Group', inversedBy: 'children')]
|
|
|
|
#[ORM\JoinColumn(name: 'parent_id')]
|
2023-04-15 22:05:29 +02:00
|
|
|
protected ?AbstractStructuralDBElement $parent;
|
2019-03-15 13:18:47 +01:00
|
|
|
|
|
|
|
/**
|
2023-04-16 23:58:03 +02:00
|
|
|
* @var Collection<int, User>
|
2019-03-15 13:18:47 +01:00
|
|
|
*/
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: 'User', mappedBy: 'group')]
|
2023-04-15 22:25:03 +02:00
|
|
|
protected Collection $users;
|
2019-03-15 13:18:47 +01:00
|
|
|
|
2019-12-14 16:35:19 +01:00
|
|
|
/**
|
2023-04-15 23:14:53 +02:00
|
|
|
* @var bool If true all users associated with this group must have enabled some kind of two-factor authentication
|
2019-12-14 16:35:19 +01:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Groups(['extended', 'full', 'import'])]
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN, name: 'enforce_2fa')]
|
2023-04-15 22:05:29 +02:00
|
|
|
protected bool $enforce2FA = false;
|
2020-01-05 22:49:00 +01:00
|
|
|
/**
|
2020-03-29 23:13:25 +02:00
|
|
|
* @var Collection<int, GroupAttachment>
|
2020-01-05 22:49:00 +01:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Assert\Valid]
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: 'App\Entity\Attachments\GroupAttachment', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
|
|
|
#[ORM\OrderBy(['name' => 'ASC'])]
|
2023-04-15 22:25:03 +02:00
|
|
|
protected Collection $attachments;
|
2020-01-05 22:49:00 +01:00
|
|
|
|
2022-10-30 21:51:24 +01:00
|
|
|
/**
|
2022-11-28 00:03:42 +01:00
|
|
|
* @var PermissionData|null
|
2022-10-31 21:12:01 +01:00
|
|
|
* @ValidPermission()
|
2022-10-30 21:51:24 +01:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Groups(['full'])]
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\Embedded(class: 'PermissionData', columnPrefix: 'permissions_')]
|
2022-11-28 00:03:42 +01:00
|
|
|
protected ?PermissionData $permissions = null;
|
2022-10-30 21:51:24 +01:00
|
|
|
|
2020-03-29 23:13:25 +02:00
|
|
|
/** @var Collection<int, GroupParameter>
|
2020-03-11 21:48:47 +01:00
|
|
|
*/
|
2023-05-28 01:21:05 +02:00
|
|
|
#[Assert\Valid]
|
2023-05-28 01:33:45 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: 'App\Entity\Parameters\GroupParameter', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
|
|
|
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
2023-04-15 22:25:03 +02:00
|
|
|
protected Collection $parameters;
|
2020-03-11 21:48:47 +01:00
|
|
|
|
2019-09-10 17:12:56 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
2023-05-28 01:33:45 +02:00
|
|
|
$this->attachments = new \Doctrine\Common\Collections\ArrayCollection();
|
|
|
|
$this->parameters = new \Doctrine\Common\Collections\ArrayCollection();
|
2019-09-10 17:12:56 +02:00
|
|
|
parent::__construct();
|
2022-10-30 21:51:24 +01:00
|
|
|
$this->permissions = new PermissionData();
|
2020-05-17 21:52:47 +02:00
|
|
|
$this->users = new ArrayCollection();
|
2023-04-16 01:46:44 +02:00
|
|
|
$this->children = new ArrayCollection();
|
2019-09-10 17:12:56 +02:00
|
|
|
}
|
|
|
|
|
2019-12-14 16:35:19 +01:00
|
|
|
/**
|
|
|
|
* Check if the users of this group are enforced to have two factor authentification (2FA) enabled.
|
|
|
|
*/
|
|
|
|
public function isEnforce2FA(): bool
|
|
|
|
{
|
|
|
|
return $this->enforce2FA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if the user of this group are enforced to have two factor authentification enabled.
|
2020-01-04 20:24:09 +01:00
|
|
|
*
|
2020-08-21 21:36:22 +02:00
|
|
|
* @param bool $enforce2FA true, if the users of this group are enforced to have 2FA enabled
|
2020-01-04 20:24:09 +01:00
|
|
|
*
|
2019-12-14 16:35:19 +01:00
|
|
|
* @return $this
|
|
|
|
*/
|
2020-01-04 20:24:09 +01:00
|
|
|
public function setEnforce2FA(bool $enforce2FA): self
|
2019-12-14 16:35:19 +01:00
|
|
|
{
|
|
|
|
$this->enforce2FA = $enforce2FA;
|
2020-01-04 20:24:09 +01:00
|
|
|
|
2019-12-14 16:35:19 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-10-30 21:51:24 +01:00
|
|
|
public function getPermissions(): PermissionData
|
2019-03-18 19:05:41 +01:00
|
|
|
{
|
2022-11-28 00:03:42 +01:00
|
|
|
if ($this->permissions === null) {
|
|
|
|
$this->permissions = new PermissionData();
|
|
|
|
}
|
|
|
|
|
2019-03-18 19:05:41 +01:00
|
|
|
return $this->permissions;
|
|
|
|
}
|
2020-05-17 21:52:47 +02:00
|
|
|
|
|
|
|
public function getUsers(): Collection
|
|
|
|
{
|
|
|
|
return $this->users;
|
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|