Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-server
Commits
d03c2f4c
Commit
d03c2f4c
authored
Oct 30, 2020
by
François Agneray
Browse files
Add users, groups and datasets privileges
parent
b745ea20
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Entity/DatasetPrivileges.php
deleted
100644 → 0
View file @
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
;
}
}
src/Entity/Group.php
View file @
d03c2f4c
...
...
@@ -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
*
* @
One
ToMany(targetEntity="
DatasetPrivileges
", mappedBy="group")
* @
Many
ToMany(targetEntity="
User
", mappedBy="group
s
")
*/
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
->
dataset
Privilege
s
;
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
];
}
}
src/Entity/User.php
View file @
d03c2f4c
...
...
@@ -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
$group
s
;
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
getGroup
s
()
{
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
()
'group
s
'
=>
$
groups
];
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment