Commit d03c2f4c authored by François Agneray's avatar François Agneray

Add users, groups and datasets privileges

parent b745ea20
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Entity;
/**
* @Entity
* @Table(name="dataset_privileges")
*/
class DatasetPrivileges
{
/**
* @var Anis\Entity\Dataset
*
* @Id
* @ManyToOne(targetEntity="Dataset")
* @JoinColumn(name="dataset_name", referencedColumnName="name", nullable=false)
*/
protected $dataset;
/**
* @var Anis\Entity\Group
*
* @Id
* @ManyToOne(targetEntity="Group", inversedBy="datasetPrivileges")
* @JoinColumn(name="group_id", referencedColumnName="id", nullable=false)
*/
protected $group;
public function __construct(Dataset $dataset, Group $group)
{
$this->dataset = $dataset;
$this->group = $group;
}
public function getDataset()
{
return $this->dataset;
}
public function getGroup()
{
return $this->group;
}
}
......@@ -12,6 +12,9 @@ declare(strict_types=1);
namespace App\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="anis_group")
......@@ -35,11 +38,30 @@ class Group implements \JsonSerializable
protected $label;
/**
* @var Anis\Entity\DatasetPrivileges
* Many Groups have Many Users.
* @var Collection
*
* @OneToMany(targetEntity="DatasetPrivileges", mappedBy="group")
* @ManyToMany(targetEntity="User", mappedBy="groups")
*/
protected $datasetPrivileges;
protected $users;
/**
* Many Groups have Many Datasets privileges.
*
* @ManyToMany(targetEntity="Dataset")
* @JoinTable(
* name="groups_datasets",
* joinColumns={@JoinColumn(name="group_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="dataset_name", referencedColumnName="name")}
* )
*/
protected $datasets;
public function __construct()
{
$this->users = new ArrayCollection();
$this->datasets = new ArrayCollection();
}
public function getId()
{
......@@ -56,16 +78,33 @@ class Group implements \JsonSerializable
$this->label = $label;
}
public function getDatasetPrivileges()
public function getUsers()
{
return $this->users;
}
public function getDatasets()
{
return $this->datasetPrivileges;
return $this->datasets;
}
public function jsonSerialize()
{
$users = array();
foreach ($this->getUsers() as $user) {
$users[] = $user->getEmail();
}
$datasets = array();
foreach ($this->datasets() as $dataset) {
$datasets[] = $dataset->getName();
}
return [
'id' => $this->getId(),
'label' => $this->getLabel()
'label' => $this->getLabel(),
'users' => $users,
'datasets' => $datasets
];
}
}
......@@ -12,6 +12,9 @@ declare(strict_types=1);
namespace App\Entity;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="anis_user")
......@@ -34,16 +37,22 @@ class User implements \JsonSerializable
protected $role;
/**
* @var Anis\Entity\Group
* Many Users have Many Groups.
* @var Collection
*
* @ManyToOne(targetEntity="Group")
* @JoinColumn(name="group_id", referencedColumnName="id", nullable=true)
* @ManyToMany(targetEntity="Group", inversedBy="users")
* @JoinTable(
* name="users_groups",
* joinColumns={@JoinColumn(name="email", referencedColumnName="email")},
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
protected $group;
protected $groups;
public function __construct(string $email)
public function __construct($email)
{
return $this->email = $email;
$this->email = $email;
$this->groups = new ArrayCollection();
}
public function getEmail()
......@@ -61,22 +70,22 @@ class User implements \JsonSerializable
$this->role = $role;
}
public function getGroup()
public function getGroups()
{
return $this->group;
}
public function setGroup($group)
{
$this->group = $group;
return $this->groups;
}
public function jsonSerialize()
{
$groups = array();
foreach ($this->getGroups() as $group) {
$groups[] = $group->getId();
}
return [
'email' => $this->getEmail(),
'role' => $this->getRole(),
'id_group' => $this->getGroup()->getId()
'groups' => $groups
];
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment