Commit b80f36c9 authored by François Agneray's avatar François Agneray
Browse files

Tests + code coverage

parent bfefedb4
......@@ -32,7 +32,7 @@ class Attribute implements \JsonSerializable
* @var App\Entity\Dataset
*
* @Id
* @ManyToOne(targetEntity="Dataset", inversedBy="attributes")
* @ManyToOne(targetEntity="Dataset")
* @JoinColumn(name="dataset_name", referencedColumnName="name", nullable=false)
*/
protected $dataset;
......@@ -250,7 +250,7 @@ class Attribute implements \JsonSerializable
/**
* @var App\Entity\CriteriaFamily
*
* @ManyToOne(targetEntity="CriteriaFamily", inversedBy="attributes")
* @ManyToOne(targetEntity="CriteriaFamily")
* @JoinColumn(name="criteria_family", referencedColumnName="id", nullable=true)
*/
protected $criteriaFamily;
......@@ -258,7 +258,7 @@ class Attribute implements \JsonSerializable
/**
* @var App\Entity\OutputCategory
*
* @ManyToOne(targetEntity="OutputCategory", inversedBy="attributes")
* @ManyToOne(targetEntity="OutputCategory")
* @JoinColumn(name="output_category", referencedColumnName="id", nullable=true)
*/
protected $outputCategory;
......@@ -574,11 +574,6 @@ class Attribute implements \JsonSerializable
$this->options = $options;
}
public function getDataset()
{
return $this->dataset;
}
public function getCriteriaFamily()
{
return $this->criteriaFamily;
......
......@@ -41,13 +41,6 @@ class CriteriaFamily implements \JsonSerializable
*/
protected $display;
/**
* @var Anis\Entity\Attribute[]
*
* @OneToMany(targetEntity="Attribute", mappedBy="criteriaFamily")
*/
protected $attributes;
public function getId()
{
return $this->id;
......@@ -73,11 +66,6 @@ class CriteriaFamily implements \JsonSerializable
$this->display = $display;
}
public function getAttributes()
{
return $this->attributes;
}
public function jsonSerialize()
{
return [
......
......@@ -87,7 +87,7 @@ class Dataset implements \JsonSerializable
/**
* @var Anis\Entity\Project
*
* @ManyToOne(targetEntity="Project", inversedBy="datasets")
* @ManyToOne(targetEntity="Project")
* @JoinColumn(name="project_name", referencedColumnName="name", nullable=false)
*/
protected $project;
......@@ -103,31 +103,10 @@ class Dataset implements \JsonSerializable
/**
* @var Anis\Entity\Project
*
* @ManyToOne(targetEntity="DatasetFamily", inversedBy="datasets")
* @ManyToOne(targetEntity="DatasetFamily")
* @JoinColumn(name="id_dataset_family", referencedColumnName="id", nullable=true)
*/
protected $datasetFamily;
/**
* @var Anis\Entity\Attribute[]
*
* @OneToMany(targetEntity="Attribute", mappedBy="dataset", cascade={"remove"})
*/
protected $attributes;
/**
* @var Anis\Entity\File[]
*
* @OneToMany(targetEntity="File", mappedBy="dataset", cascade={"remove"})
*/
protected $files;
/**
* @var Anis\Entity\DatasetPrivileges
*
* @OneToMany(targetEntity="DatasetPrivileges", mappedBy="dataset")
*/
protected $datasetPrivileges;
public function __construct($name)
{
......@@ -249,26 +228,6 @@ class Dataset implements \JsonSerializable
{
$this->datasetFamily = $datasetFamily;
}
public function getAttributes()
{
return $this->attributes;
}
public function getFiles()
{
return $this->files;
}
public function getJoins()
{
return $this->joins;
}
public function getDatasetPrivileges()
{
return $this->datasetPrivileges;
}
public function jsonSerialize()
{
......
......@@ -43,13 +43,6 @@ class DatasetFamily implements \JsonSerializable
*/
protected $display;
/**
* @var Anis\Entity\Dataset[]
*
* @OneToMany(targetEntity="Dataset", mappedBy="datasetFamily")
*/
protected $datasets;
public function __construct()
{
$this->datasets = new ArrayCollection();
......@@ -80,23 +73,13 @@ class DatasetFamily implements \JsonSerializable
$this->display = (int) $display;
}
public function getDatasets()
{
return $this->datasets;
}
public function jsonSerialize()
{
$datasets = array();
foreach ($this->getDatasets() as $dataset) {
$datasets[] = $dataset->getName();
}
return [
'id' => $this->getId(),
'label' => $this->getLabel(),
'display' => $this->getDisplay(),
'type' => 'dataset',
'datasets' => $datasets
'type' => 'dataset'
];
}
}
......@@ -22,7 +22,7 @@ class DatasetPrivileges
* @var Anis\Entity\Dataset
*
* @Id
* @ManyToOne(targetEntity="Dataset", inversedBy="datasetPrivileges")
* @ManyToOne(targetEntity="Dataset")
* @JoinColumn(name="dataset_name", referencedColumnName="name", nullable=false)
*/
protected $dataset;
......@@ -36,17 +36,10 @@ class DatasetPrivileges
*/
protected $group;
/**
* @var bool
*
* @Column(type="boolean", nullable=false)
*/
protected $visible;
public function __construct(Dataset $dataset, Group $group)
{
$this->dataset = $dataset;
$this->group = $group;
$this->group = $group;
}
public function getDataset()
......@@ -58,14 +51,4 @@ class DatasetPrivileges
{
return $this->group;
}
public function getVisible()
{
return $this->visible;
}
public function setVisible($visible)
{
$this->visible = (bool) $visible;
}
}
<?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="file")
*/
class File implements \JsonSerializable
{
/**
* @var integer
*
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue
*/
protected $id;
/**
* @var string
*
* @Column(type="string", nullable=false)
*/
protected $label;
/**
* @var string
*
* @Column(type="string", name="file_loc", nullable=true)
*/
protected $fileLoc;
/**
* @var string
*
* @Column(type="string", nullable=false)
*/
protected $type;
/**
* @var integer
*
* @Column(type="integer", nullable=false)
*/
protected $display;
/**
* @var bool
*
* @Column(type="boolean", nullable=false)
*/
protected $visible;
/**
* @var Anis\Entity\Dataset
*
* @ManyToOne(targetEntity="Dataset", inversedBy="files")
* @JoinColumn(name="dataset_name", referencedColumnName="name", nullable=false)
*/
protected $dataset;
public function __construct(Dataset $dataset)
{
$this->dataset = $dataset;
}
public function getId()
{
return $this->id;
}
public function getLabel()
{
return $this->label;
}
public function setLabel($label)
{
$this->label = $label;
}
public function getFileLoc()
{
return $this->fileLoc;
}
public function setFileLoc($fileLoc)
{
$this->fileLoc = $fileLoc;
}
public function getType()
{
return $this->type;
}
public function setType($type)
{
$this->type = $type;
}
public function getDisplay()
{
return $this->display;
}
public function setDisplay($display)
{
$this->display = (int) $display;
}
public function getVisible()
{
return $this->visible;
}
public function setVisible($visible)
{
$this->visible = $visible;
}
public function getDataset()
{
return $this->dataset;
}
public function jsonSerialize()
{
return [
'id' => $this->getId(),
'label' => $this->getLabel(),
'file_loc' => $this->getFileLoc(),
'type' => $this->getType(),
'display' => $this->getDisplay(),
'visible' => $this->getVisible()
];
}
}
......@@ -34,13 +34,6 @@ class Group implements \JsonSerializable
*/
protected $label;
/**
* @var Anis\Entity\User[]
*
* @OneToMany(targetEntity="User", mappedBy="group")
*/
protected $users;
/**
* @var Anis\Entity\DatasetPrivileges
*
......@@ -63,11 +56,6 @@ class Group implements \JsonSerializable
$this->label = $label;
}
public function getUsers()
{
return $this->users;
}
public function getDatasetPrivileges()
{
return $this->datasetPrivileges;
......
......@@ -44,17 +44,10 @@ class OutputCategory implements \JsonSerializable
/**
* @var Anis\Entity\OutputFamily
*
* @ManyToOne(targetEntity="OutputFamily", inversedBy="outputCategories")
* @ManyToOne(targetEntity="OutputFamily")
* @JoinColumn(name="output_family", referencedColumnName="id", nullable=false)
*/
protected $outputFamily;
/**
* @var Anis\Entity\Attribute[]
*
* @OneToMany(targetEntity="Attribute", mappedBy="outputCategory")
*/
protected $attributes;
public function getId()
{
......@@ -91,11 +84,6 @@ class OutputCategory implements \JsonSerializable
return $this->outputFamily;
}
public function getAttributes()
{
return $this->attributes;
}
public function jsonSerialize()
{
return [
......
......@@ -41,13 +41,6 @@ class OutputFamily implements \JsonSerializable
*/
protected $display;
/**
* @var Anis\Entity\OutputCategory[]
*
* @OneToMany(targetEntity="OutputCategory", mappedBy="outputFamily", cascade={"remove"})
*/
protected $outputCategories;
public function getId()
{
return $this->id;
......@@ -73,11 +66,6 @@ class OutputFamily implements \JsonSerializable
return $this->display;
}
public function getOutputCategories()
{
return $this->outputCategories;
}
public function jsonSerialize()
{
return [
......
......@@ -62,13 +62,6 @@ class Project implements \JsonSerializable
*/
protected $database;
/**
* @var Anis\Entity\Dataset[]
*
* @OneToMany(targetEntity="Dataset", mappedBy="project", cascade={"remove"})
*/
protected $datasets;
public function __construct($name)
{
$this->name = $name;
......@@ -129,11 +122,6 @@ class Project implements \JsonSerializable
return $this->database;
}
public function getDatasets()
{
return $this->datasets;
}
public function jsonSerialize()
{
return [
......
......@@ -26,45 +26,10 @@ class User implements \JsonSerializable
*/
protected $email;
/**
* @var string
*
* @Column(type="string", nullable=false)
*/
protected $password;
/**
* @var string
*
* @Column(type="string", name="activation_key", nullable=false)
*/
protected $activationKey;
/**
* @var bool
*
* @Column(type="boolean", nullable=false)
*/
protected $activated;
/**
* @var bool
*
* @Column(type="boolean", nullable=false)
*/
protected $adminsi;
/**
* @var bool
*
* @Column(type="boolean", nullable=false)
*/
protected $superuser;
/**
* @var Anis\Entity\Group
*
* @ManyToOne(targetEntity="Group", inversedBy="users")
* @ManyToOne(targetEntity="Group")
* @JoinColumn(name="group_id", referencedColumnName="id", nullable=true)
*/
protected $group;
......@@ -79,56 +44,6 @@ class User implements \JsonSerializable
return $this->email;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getActivationKey()
{
return $this->activationKey;
}
public function setActivationKey($activationKey)
{
$this->activationKey = $activationKey;
}
public function getActivated()
{
return $this->activated;
}
public function setActivated($activated)
{
$this->activated = $activated;
}
public function getAdminsi()
{
return $this->adminsi;
}
public function setAdminsi($adminsi)
{
$this->adminsi = $adminsi;
}
public function getSuperuser()
{
return $this->superuser;
}
public function setSuperuser($superuser)
{
$this->superuser = $superuser;
}
public function getGroup()
{
return $this->group;
......@@ -143,9 +58,6 @@ class User implements \JsonSerializable
{
return [
'email' => $this->getEmail(),
'activated' => $this->getActivated(),
'adminsi' => $this->getAdminsi(),
'superuser' => $this->getSuperuser(),
'id_group' => $this->getGroup()->getId()
];
}
......
<?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\Middleware;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Psr\Http\Server\MiddlewareInterface;
use Slim\Exception\HttpBadRequestException;
use Slim\Exception\HttpUnauthorizedException;
use Doctrine\ORM\EntityManagerInterface;
use Lcobucci\JWT\ValidationData;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Signer\Hmac\Sha256;
/**
* Middleware to handle authentication jwt
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Middleware
*/
final class AuthorizationMiddleware implements MiddlewareInterface
{
/**
* The EntityManager is the central access point to Doctrine ORM functionality
*
* @var EntityManagerInterface
*/
protected $em;
/**
* This object contains token options from settings file
*
* @var array
*/
private $tokenOptions;
/**
* Create the classe before call process to execute the middleware
*
* @param array $tokenOptions Options to create the token
*/
public function __construct(EntityManagerInterface $em, array $tokenOptions)
{
$this->em = $em;
$this->tokenOptions = $tokenOptions;