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

Merge branch '31-php-doc' into 'develop'

Resolve "PHP doc"

Closes #31

See merge request !31
parents 1f238981 7fd53168
Pipeline #1401 passed with stages
in 6 minutes and 34 seconds
......@@ -21,6 +21,8 @@ use App\Utils\ActionTrait;
use App\Entity\User;
/**
* Route: /login/activate-account
*
* With this action, the newly registered user be able
* to send the activation code of his new account. (GET)
*
......@@ -73,7 +75,7 @@ final class ActivateAccountAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -110,7 +112,7 @@ final class ActivateAccountAction
$user = $this->em->find('\App\Entity\User', $queryParams['email']);
// Is the activation key is the good one
// Is the activation key is the good one ?
if ($user->getActivationKey() !== $queryParams['activation_key']) {
return $this->dispatchHttpError(
$response,
......@@ -123,7 +125,7 @@ final class ActivateAccountAction
$user->setActivated(true);
$this->em->flush();
// Send a email confirmation for the user and returns user modified
// Send an email confirmation for the user and returns user modified
$this->sendEmail($user->getEmail());
return $response->withJson($user);
}
......
......@@ -20,6 +20,8 @@ use Swift_Message;
use App\Utils\ActionTrait;
/**
* Route: /login/change-password
*
* With this action the anis user can change his password (POST)
*
* @author François Agneray <francois.agneray@lam.fr>
......@@ -69,7 +71,7 @@ final class ChangePasswordAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -106,7 +108,7 @@ final class ChangePasswordAction
$user = $this->em->find('\App\Entity\User', $parsedBody['email']);
// Is the user account is activated
// Is the user account is activated ?
if (!$user->getActivated()) {
return $this->dispatchHttpError(
$response,
......
......@@ -19,6 +19,8 @@ use Swift_Mailer;
use App\Utils\ActionTrait;
/**
* Route: /login/new-password
*
* This action asks for a new password
*
* @author François Agneray <francois.agneray@lam.fr>
......@@ -69,7 +71,7 @@ final class NewPasswordAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -104,7 +106,7 @@ final class NewPasswordAction
$user = $this->em->find('App\Entity\User', $parsedBody['email']);
// Is the user account is activated
// Is the user account is activated ?
if (!$user->getActivated()) {
return $this->dispatchHttpError(
$response,
......
......@@ -21,6 +21,8 @@ use App\Utils\ActionTrait;
use App\Entity\User;
/**
* Route: /login/register
*
* An action to saves a new user Anis (POST)
*
* @author François Agneray <francois.agneray@lam.fr>
......@@ -73,7 +75,7 @@ final class RegisterAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......
......@@ -21,6 +21,8 @@ use Lcobucci\JWT\Token;
use App\Utils\ActionTrait;
/**
* Route: /login/token
*
* Get a valid token (jwt) for a anis user (POST)
*
* @author François Agneray <francois.agneray@lam.fr>
......@@ -85,7 +87,7 @@ final class TokenAction
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param array $args This table contains information transmitted in the URL (see routes.php)
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
......@@ -111,6 +113,7 @@ final class TokenAction
}
}
// Is the user exists ?
if (!$this->isExistUser($parsedBody['email'])) {
return $this->dispatchHttpError(
$response,
......@@ -121,6 +124,7 @@ final class TokenAction
$user = $this->em->find('\App\Entity\User', $parsedBody['email']);
// Is the user activated ?
if (!$user->getActivated()) {
return $this->dispatchHttpError(
$response,
......@@ -129,6 +133,7 @@ final class TokenAction
);
}
// Is the password is ok ?
if (!password_verify($parsedBody['password'], $user->getPassword())) {
return $this->dispatchHttpError(
$response,
......@@ -137,7 +142,7 @@ final class TokenAction
);
}
// JWT generation
// // It's all right. JWT generation
$token = $this->generateToken($user->getEmail());
$data = array('email' => $user->getEmail(), 'token' => (string) $token);
return $response->withJson($data);
......
......@@ -21,19 +21,56 @@ use App\Entity\Attribute;
use App\Entity\CriteriaFamily;
use App\Entity\OutputCategory;
/**
* Route: /metadata/dataset/{name}/attribute/{id}
* {name}: Dataset name
* {id}: Attribute id
*
* This action is used to manage one attribute
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class AttributeAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
/**
* `GET` Returns the attribute found
* `PUT` Full update an attribute and returns the new version
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Attribute list action dispatched');
......@@ -42,11 +79,10 @@ final class AttributeAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, OPTIONS');
}
$attribute = $this->em->getRepository('App\Entity\Attribute')->findOneBy(array(
'dataset' => $args['name'],
'id' => $args['id']
));
// Search the correct attribute with primary key
$attribute = $this->em->getRepository('App\Entity\Attribute')->findOneBy(array('dataset' => $args['name'], 'id' => $args['id']));
// If attribute is not found 404
if (is_null($attribute)) {
return $this->dispatchHttpError(
$response,
......@@ -117,7 +153,10 @@ final class AttributeAction
$attribute->setVoDescription($parsedBody['vo_description']);
$attribute->setVoDatatype($parsedBody['vo_datatype']);
$attribute->setVoSize($parsedBody['vo_size']);
$criteriaFamily = (is_null($parsedBody['id_criteria_family'])) ? null : $this->em->find('App\Entity\CriteriaFamily', $parsedBody['id_criteria_family']);
$attribute->setCriteriaFamily($criteriaFamily);
$outputCategory = (is_null($parsedBody['id_output_category'])) ? null : $this->em->find('App\Entity\OutputCategory', $parsedBody['id_output_category']);
$attribute->setOutputCategory($outputCategory);
$this->em->flush();
}
}
......@@ -21,19 +21,54 @@ use App\Entity\Attribute;
use App\Entity\CriteriaFamily;
use App\Entity\OutputCategory;
/**
* Route: /metadata/dataset/{name}/attribute/
* {name}: Dataset name
*
* This action returns a list of all attributes in a dataset
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class AttributeListAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
/**
* `GET` Returns all attributes in the dataset selected
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Attribute list action dispatched');
......@@ -44,6 +79,7 @@ final class AttributeListAction
$dataset = $this->em->find('App\Entity\Dataset', $args['name']);
// Returns HTTP 404 if the dataset is not found
if (is_null($dataset)) {
return $this->dispatchHttpError(
$response,
......
......@@ -18,14 +18,47 @@ use Psr\Http\Message\ResponseInterface as Response;
use App\Utils\ActionTrait;
use App\Entity\Database;
/**
* Route: /metadata/database/{id}
* {id}: Database id
*
* This action is used to manage one database
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatabaseAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* The key needed to encrypt the password of the database
*
* @var string
*/
private $encryptionKey;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
* @param string $encryptionKey
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, string $encryptionKey)
{
$this->logger = $logger;
......@@ -33,6 +66,17 @@ final class DatabaseAction
$this->encryptionKey = $encryptionKey;
}
/**
* `GET` Returns the database found
* `PUT` Full update the database and returns the new version
* `DELETE` Delete the database found and return a confirmation message
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Database action dispatched');
......@@ -41,8 +85,10 @@ final class DatabaseAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct database with primary key
$database = $this->em->find('App\Entity\Database', $args['id']);
// If database is not found 404
if (is_null($database)) {
return $this->dispatchHttpError(
$response,
......@@ -58,7 +104,7 @@ final class DatabaseAction
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'dbname', 'dbtype', 'dbhost', 'dbport', 'dblogin', 'dbpassword') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -83,6 +129,12 @@ final class DatabaseAction
return $newResponse;
}
/**
* Update database object with setters
*
* @param Database $database The database to update
* @param string[] $parsedBody Contains the new values ​​of the database sent by the user
*/
private function editDatabase(Database $database, array $parsedBody): void
{
$database->setLabel($parsedBody['label']);
......
......@@ -18,14 +18,46 @@ use Psr\Http\Message\ResponseInterface as Response;
use App\Utils\ActionTrait;
use App\Entity\Database;
/**
* Route: /metadata/database
*
* This action returns a list of all databases listed in the metamodel database
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatabaseListAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* The key needed to encrypt the password of the database
*
* @var string
*/
private $encryptionKey;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
* @param string $encryptionKey
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em, string $encryptionKey)
{
$this->logger = $logger;
......@@ -33,6 +65,16 @@ final class DatabaseListAction
$this->encryptionKey = $encryptionKey;
}
/**
* `GET` Returns a list of all databases listed in the metamodel database
* `POST` Add a new database
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Database list action dispatched');
......@@ -49,7 +91,7 @@ final class DatabaseListAction
if ($request->isPost()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'dbname', 'dbtype', 'dbhost', 'dbport', 'dblogin', 'dbpassword') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -67,6 +109,11 @@ final class DatabaseListAction
return $newResponse;
}
/**
* Add a new database into the metamodel
*
* @param string[] $parsedBody Contains the values ​​of the new database sent by the user
*/
private function postDatabase(array $parsedBody): Database
{
$database = new Database();
......
......@@ -19,19 +19,56 @@ use App\Utils\ActionTrait;
use App\Entity\Dataset;
use App\Entity\DatasetFamily;
/**
* Route: /metadata/dataset/{name}
* {name}: Dataset name
*
* This action is used to manage one dataset
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatasetAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Create the classe before call __invoke to execute the action
*
* @param LoggerInterface $logger
* @param EntityManagerInterface $em
*/
public function __construct(LoggerInterface $logger, EntityManagerInterface $em)
{
$this->logger = $logger;
$this->em = $em;
}
/**
* `GET` Returns the dataset found
* `PUT` Full update the dataset and returns the new version
* `DELETE` Delete the dataset found and return a confirmation message
*
* @param ServerRequestInterface $request This object contains the HTTP request
* @param ResponseInterface $response This object represents the HTTP response
* @param string[] $args This table contains information transmitted in the URL (see routes.php)
*
* @return ResponseInterface
*/
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->logger->info('Dataset action dispatched');
......@@ -40,8 +77,10 @@ final class DatasetAction
return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
}
// Search the correct dataset with primary key
$dataset = $this->em->find('App\Entity\Dataset', $args['name']);
// If dataset is not found 404
if (is_null($dataset)) {
return $this->dispatchHttpError(
$response,
......@@ -57,7 +96,7 @@ final class DatasetAction
if ($request->isPut()) {
$parsedBody = $request->getParsedBody();
// Vérification des champs vides
// If mandatories empty fields 400
foreach (array('label', 'description', 'id_dataset_family', 'display', 'count', 'vo', 'data_path') as $a) {
if ($this->isEmptyField($a, $parsedBody)) {
return $this->dispatchHttpError(
......@@ -68,7 +107,10 @@ final class DatasetAction
}
}
// Search the correct dataset family with primary key
$family = $this->em->find('App\Entity\DatasetFamily', $parsedBody['id_dataset_family']);
// Dataset family is mandatory. If is null 404
if (is_null($family)) {
return $this->dispatchHttpError(
$response,
......@@ -91,6 +133,13 @@ final class DatasetAction
return $newResponse;
}
/**
* Update dataset object with setters
*
* @param Dataset $dataset The dataset to update
* @param string[] $parsedBody Contains the new values ​​of the dataset sent by the user
* @param DatasetFamily $family Contains the dataset family doctrine object
*/
private function editDataset(Dataset $dataset, array $parsedBody, DatasetFamily $family): void
{
$dataset->setLabel($parsedBody['label']);
......
......@@ -21,34 +21,75 @@ use App\Entity\Dataset;
use App\Entity\Project;
use App\Entity\DatasetFamily;
/**
* Route: /metadata/dataset
*
* This action is used to:
* - Get all datasets
* - Add a new dataset
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Action\Meta
*/
final class DatasetListAction
{
use ActionTrait;
/**
* The logger interface is the central access point to log anis information
*
* @var LoggerInterface
*/
private $logger;
/**
* The EntityManager is the central access point to Doctrine ORM functionality (metadata database)
*
* @var EntityManagerInterface
*/
private $em;
/**
* Factory that provides a connection to the business database
*
* @var DBALConnectionFactory
*/
private $dcf;
/**
* The encryption key used by anis to encrypt and decrypt sensitive data like passwords
* This key is provided by configuration (see the config file)