2019-03-15 13:18:47 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2019-11-09 00:47:20 +01:00
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
2019-08-12 15:47:57 +02:00
|
|
|
*
|
2019-11-01 13:40:30 +01:00
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
2019-03-15 13:18:47 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
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;
|
2019-08-12 15:47:57 +02:00
|
|
|
use App\Entity\Base\StructuralDBElement;
|
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;
|
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;
|
|
|
|
|
|
|
|
/**
|
2019-03-20 23:16:07 +01:00
|
|
|
* This entity represents an user group.
|
2019-03-15 13:18:47 +01:00
|
|
|
*
|
|
|
|
* @ORM\Entity()
|
2019-03-25 22:03:52 +01:00
|
|
|
* @ORM\Table("`groups`")
|
2019-03-15 13:18:47 +01:00
|
|
|
*/
|
2019-03-18 19:05:41 +01:00
|
|
|
class Group extends StructuralDBElement implements HasPermissionsInterface
|
2019-03-15 13:18:47 +01:00
|
|
|
{
|
2019-09-24 13:39:49 +02:00
|
|
|
/**
|
|
|
|
* @var Collection|GroupAttachment[]
|
2019-09-24 18:28:35 +02:00
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\ManufacturerAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
|
2019-09-24 13:39:49 +02:00
|
|
|
*/
|
|
|
|
protected $attachments;
|
|
|
|
|
2019-03-15 13:18:47 +01:00
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="Group", mappedBy="parent")
|
|
|
|
*/
|
|
|
|
protected $children;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\ManyToOne(targetEntity="Group", inversedBy="children")
|
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
protected $parent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\OneToMany(targetEntity="User", mappedBy="group")
|
|
|
|
*/
|
|
|
|
protected $users;
|
|
|
|
|
2019-03-18 19:05:41 +01:00
|
|
|
/** @var PermissionsEmbed
|
|
|
|
* @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_")
|
2019-09-11 18:50:23 +02:00
|
|
|
* @ValidPermission()
|
2019-03-18 19:05:41 +01:00
|
|
|
*/
|
|
|
|
protected $permissions;
|
|
|
|
|
2019-12-14 16:35:19 +01:00
|
|
|
/**
|
|
|
|
* @var bool If true all users associated with this group must have enabled some kind of 2 factor authentication
|
|
|
|
* @ORM\Column(type="boolean", name="enforce_2fa")
|
|
|
|
*/
|
2019-12-24 15:20:26 +01:00
|
|
|
protected $enforce2FA = false;
|
2019-12-14 16:35:19 +01:00
|
|
|
|
2019-09-10 17:12:56 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->permissions = new PermissionsEmbed();
|
|
|
|
}
|
|
|
|
|
2019-12-14 16:35:19 +01:00
|
|
|
/**
|
|
|
|
* Check if the users of this group are enforced to have two factor authentification (2FA) enabled.
|
2020-01-04 20:24:09 +01:00
|
|
|
*
|
2019-12-14 16:35:19 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
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
|
|
|
*
|
2019-12-14 16:35:19 +01: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;
|
|
|
|
}
|
|
|
|
|
2019-03-15 13:18:47 +01:00
|
|
|
/**
|
|
|
|
* Returns the ID as an string, defined by the element class.
|
|
|
|
* This should have a form like P000014, for a part with ID 14.
|
2019-03-20 23:16:07 +01:00
|
|
|
*
|
2019-03-15 13:18:47 +01:00
|
|
|
* @return string The ID as a string;
|
|
|
|
*/
|
|
|
|
public function getIDString(): string
|
|
|
|
{
|
2019-03-20 23:16:07 +01:00
|
|
|
return 'G'.sprintf('%06d', $this->getID());
|
2019-03-15 13:18:47 +01:00
|
|
|
}
|
2019-03-18 19:05:41 +01:00
|
|
|
|
|
|
|
public function getPermissions(): PermissionsEmbed
|
|
|
|
{
|
|
|
|
return $this->permissions;
|
|
|
|
}
|
2019-03-20 23:16:07 +01:00
|
|
|
}
|