From ac895bc49f30b5e7b4d767d715a61d52ae6ea0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Fri, 30 Oct 2020 11:38:09 +0100 Subject: [PATCH 01/11] Add property public to the entity dataset --- VERSION | 2 +- src/Action/DatasetAction.php | 2 ++ src/Action/DatasetListAction.php | 2 ++ src/Entity/Dataset.php | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index fbcbf73..e5b8203 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.4.0 \ No newline at end of file +3.5.0 \ No newline at end of file diff --git a/src/Action/DatasetAction.php b/src/Action/DatasetAction.php index 052fb8b..ae6c2b6 100644 --- a/src/Action/DatasetAction.php +++ b/src/Action/DatasetAction.php @@ -65,6 +65,7 @@ final class DatasetAction extends AbstractAction 'vo', 'data_path', 'config', + 'public', 'id_dataset_family' ); foreach ($fields as $a) { @@ -117,6 +118,7 @@ final class DatasetAction extends AbstractAction $dataset->setVo($parsedBody['vo']); $dataset->setDataPath($parsedBody['data_path']); $dataset->setConfig($parsedBody['config']); + $dataset->setPublic($parsedBody['public']); $this->em->flush(); } } diff --git a/src/Action/DatasetListAction.php b/src/Action/DatasetListAction.php index 7d72101..071def9 100644 --- a/src/Action/DatasetListAction.php +++ b/src/Action/DatasetListAction.php @@ -84,6 +84,7 @@ final class DatasetListAction extends AbstractAction 'vo', 'data_path', 'config', + 'public', 'project_name' ); foreach ($fields as $a) { @@ -136,6 +137,7 @@ final class DatasetListAction extends AbstractAction $dataset->setVo($parsedBody['vo']); $dataset->setDataPath($parsedBody['data_path']); $dataset->setConfig($parsedBody['config']); + $dataset->setPublic($parsedBody['public']); $dataset->setProject($project); $dataset->setDatasetFamily($datasetFamily); diff --git a/src/Entity/Dataset.php b/src/Entity/Dataset.php index c926142..9ed9b42 100644 --- a/src/Entity/Dataset.php +++ b/src/Entity/Dataset.php @@ -83,6 +83,13 @@ class Dataset implements \JsonSerializable * @Column(type="json", nullable=true) */ protected $config; + + /** + * @var bool + * + * @Column(type="boolean", nullable=false) + */ + protected $public; /** * @var Anis\Entity\Project @@ -198,6 +205,16 @@ class Dataset implements \JsonSerializable $this->config = $config; } + public function getPublic() + { + return $this->public; + } + + public function setPublic($public) + { + $this->public = $public; + } + public function getProject() { return $this->project; @@ -235,6 +252,7 @@ class Dataset implements \JsonSerializable 'vo' => $this->getVo(), 'data_path' => $this->getDataPath(), 'config' => $this->getConfig(), + 'public' => $this->getPublic(), 'project_name' => $this->getProject()->getName(), 'id_dataset_family' => $this->getDatasetFamily()->getId() ]; -- GitLab From b745ea20e83ae7b6efd1d0ec24143edb80dbb1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Fri, 30 Oct 2020 11:39:28 +0100 Subject: [PATCH 02/11] Add property role to the entity user --- src/Entity/User.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Entity/User.php b/src/Entity/User.php index f130bbf..badc0bf 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -26,6 +26,13 @@ class User implements \JsonSerializable */ protected $email; + /** + * @var string + * + * @Column(type="string", nullable=false) + */ + protected $role; + /** * @var Anis\Entity\Group * @@ -44,6 +51,16 @@ class User implements \JsonSerializable return $this->email; } + public function getRole() + { + return $this->role; + } + + public function setRole($role) + { + $this->role = $role; + } + public function getGroup() { return $this->group; @@ -58,6 +75,7 @@ class User implements \JsonSerializable { return [ 'email' => $this->getEmail(), + 'role' => $this->getRole(), 'id_group' => $this->getGroup()->getId() ]; } -- GitLab From d03c2f4c10cf1afaf89b802fdba8ba6e3ee29557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Fri, 30 Oct 2020 12:39:49 +0100 Subject: [PATCH 03/11] Add users, groups and datasets privileges --- src/Entity/DatasetPrivileges.php | 54 -------------------------------- src/Entity/Group.php | 51 ++++++++++++++++++++++++++---- src/Entity/User.php | 37 +++++++++++++--------- 3 files changed, 68 insertions(+), 74 deletions(-) delete mode 100644 src/Entity/DatasetPrivileges.php diff --git a/src/Entity/DatasetPrivileges.php b/src/Entity/DatasetPrivileges.php deleted file mode 100644 index 8fbc8d0..0000000 --- a/src/Entity/DatasetPrivileges.php +++ /dev/null @@ -1,54 +0,0 @@ -dataset = $dataset; - $this->group = $group; - } - - public function getDataset() - { - return $this->dataset; - } - - public function getGroup() - { - return $this->group; - } -} diff --git a/src/Entity/Group.php b/src/Entity/Group.php index 4391206..2a41941 100644 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -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 ]; } } diff --git a/src/Entity/User.php b/src/Entity/User.php index badc0bf..5e9d2cc 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -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 ]; } } -- GitLab From 5087fdd88e15b281aa8fdb54ad549d063c2aeb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Mon, 2 Nov 2020 11:12:25 +0100 Subject: [PATCH 04/11] Update create database script (dataset public) --- conf-dev/create-db.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/conf-dev/create-db.sh b/conf-dev/create-db.sh index 46ac523..b0b7a99 100644 --- a/conf-dev/create-db.sh +++ b/conf-dev/create-db.sh @@ -17,10 +17,10 @@ curl -d '{"name":"colibri","label":"Colibri Project Test","description":"Project # Add default dataset family and ANIS datasets curl -d '{"label":"Default dataset family","display":10}' -H "Content-Type: application/json" -X POST http://localhost/instance/default/dataset-family -curl -d '{"name":"obs_cat","table_ref":"obs_cat","label":"ObsCat dataset","description":"ObsCat","display":10,"count":10000,"vo":false,"data_path":"/mnt/mount","config":{"cone_search":{"enabled":true,"column_ra":2,"column_dec":3},"selectable_row":true},"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset -curl -d '{"name":"observations","table_ref":"observations_info","label":"Observations dataset","description":"Observations","display":20,"count":177454,"vo":false,"data_path":"/mnt/mount","config":{"selectable_row":false},"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset -curl -d '{"name":"vipers_dr2_w1","table_ref":"aspic_vipers_dr2_w1","label":"VIPERS-W1 (DR2)","description":"VIPERS W1 dataset","display":30,"count":1000,"vo":false,"data_path":"/mnt/mount","config":{"selectable_row":false},"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset -curl -d '{"name":"gama_g02_dr3","table_ref":"aspic_gama_g02","label":"GAMA G02 (DR3)","description":"GAMA G02 dataset","display":40,"count":8,"vo":false,"data_path":"/mnt/mount","config":{"selectable_row":false},"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset +curl -d '{"name":"obs_cat","table_ref":"obs_cat","label":"ObsCat dataset","description":"ObsCat","display":10,"count":10000,"vo":false,"data_path":"/mnt/mount","config":{"cone_search":{"enabled":true,"column_ra":2,"column_dec":3},"selectable_row":true},"public":true,"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset +curl -d '{"name":"observations","table_ref":"observations_info","label":"Observations dataset","description":"Observations","display":20,"count":177454,"vo":false,"data_path":"/mnt/mount","config":{"selectable_row":false},"public":true,"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset +curl -d '{"name":"vipers_dr2_w1","table_ref":"aspic_vipers_dr2_w1","label":"VIPERS-W1 (DR2)","description":"VIPERS W1 dataset","display":30,"count":1000,"vo":false,"data_path":"/mnt/mount","config":{"selectable_row":false},"public":true,"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset +curl -d '{"name":"gama_g02_dr3","table_ref":"aspic_gama_g02","label":"GAMA G02 (DR3)","description":"GAMA G02 dataset","display":40,"count":8,"vo":false,"data_path":"/mnt/mount","config":{"selectable_row":false},"public":true,"project_name":"anis_project"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/1/dataset # Add ANIS obs_cat default criteria family, default output family and default output category curl -d '{"label":"Default criteria family","display":10}' -H "Content-Type: application/json" -X POST http://localhost/dataset/obs_cat/criteria-family @@ -29,9 +29,9 @@ curl -d '{"label":"Default output category","display":10}' -H "Content-Type: app # Add SVOM dataset family and SVOM datasets curl -d '{"label":"Svom dataset family","display":20}' -H "Content-Type: application/json" -X POST http://localhost/instance/default/dataset-family -curl -d '{"name":"l1","table_ref":"public.v_rawproducts","label":"L0 & L1","description":"L0 & L1 products list","display":10,"count":0,"vo":false,"data_path":"/mnt/mount","config":{"results_server_link":{"enabled":true},"selectable_row":false},"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset -curl -d '{"name":"products","table_ref":"public.v_products","label":"Scientific Products","description":"SR3 & SR4 products list","display":20,"count":0,"vo":false,"data_path":"/mnt/mount","config":{"results_server_link":{"enabled":true},"selectable_row":false},"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset -curl -d '{"name":"sp_cards","table_ref":"sp_cards","label":"SP Metadata","description":"Contains metadata of scientific products (Core Program & General Program)","display":30,"count":100,"vo":false,"data_path":"/mnt/mount","config":{"results_server_link":{"enabled":true},"selectable_row":false},"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset +curl -d '{"name":"l1","table_ref":"public.v_rawproducts","label":"L0 & L1","description":"L0 & L1 products list","display":10,"count":0,"vo":false,"data_path":"/mnt/mount","config":{"results_server_link":{"enabled":true},"selectable_row":false},"public":true,"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset +curl -d '{"name":"products","table_ref":"public.v_products","label":"Scientific Products","description":"SR3 & SR4 products list","display":20,"count":0,"vo":false,"data_path":"/mnt/mount","config":{"results_server_link":{"enabled":true},"selectable_row":false},"public":true,"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset +curl -d '{"name":"sp_cards","table_ref":"sp_cards","label":"SP Metadata","description":"Contains metadata of scientific products (Core Program & General Program)","display":30,"count":100,"vo":false,"data_path":"/mnt/mount","config":{"results_server_link":{"enabled":true},"selectable_row":false},"public":true,"project_name":"svom"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/2/dataset # Add SVOM l1 criteria families, default output family and default output category curl -d '{"label":"Obs","display":10}' -H "Content-Type: application/json" -X POST http://localhost/dataset/l1/criteria-family @@ -100,7 +100,7 @@ curl -d '{"id":9,"name":"json_schema_uploaded","table_name":"sp_cards","label":" # Add COLIBRI dataset family and COLIBRI dataset curl -d '{"label":"Colibri dataset family","display":30}' -H "Content-Type: application/json" -X POST http://localhost/instance/default/dataset-family -curl -d '{"name":"anis_observation","table_ref":"anis_observation","label":"COLIBRI OBS","description":"colibri observations","display":10,"count":0,"vo":true,"data_path":"/mnt/mount","config":{"cone_search":{"enabled":true,"column_ra":2,"column_dec":3},"selectable_row":true},"project_name":"colibri"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/3/dataset +curl -d '{"name":"anis_observation","table_ref":"anis_observation","label":"COLIBRI OBS","description":"colibri observations","display":10,"count":0,"vo":true,"data_path":"/mnt/mount","config":{"cone_search":{"enabled":true,"column_ra":2,"column_dec":3},"selectable_row":true},"public":true,"project_name":"colibri"}' -H "Content-Type: application/json" -X POST http://localhost/dataset-family/3/dataset # Add COLIBRI anis_observation default criteria family, output families and output categories curl -d '{"label":"Default criteria family","display":10}' -H "Content-Type: application/json" -X POST http://localhost/dataset/anis_observation/criteria-family -- GitLab From 75d13d2367cb19c97f9b5dd8b4b403a0131b28f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Mon, 2 Nov 2020 11:32:36 +0100 Subject: [PATCH 05/11] Add and update groups => done --- app/dependencies.php | 8 +++ app/routes.php | 2 + conf-dev/create-db.sh | 4 ++ src/Action/GroupAction.php | 94 ++++++++++++++++++++++++++++++++++ src/Action/GroupListAction.php | 81 +++++++++++++++++++++++++++++ src/Entity/Group.php | 2 +- 6 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 src/Action/GroupAction.php create mode 100644 src/Action/GroupListAction.php diff --git a/app/dependencies.php b/app/dependencies.php index 35494ad..aadc9f4 100644 --- a/app/dependencies.php +++ b/app/dependencies.php @@ -76,6 +76,14 @@ $container->set('App\Action\ProjectAction', function (ContainerInterface $c) { return new App\Action\ProjectAction($c->get('em')); }); +$container->set('App\Action\GroupListAction', function (ContainerInterface $c) { + return new App\Action\GroupListAction($c->get('em')); +}); + +$container->set('App\Action\GroupAction', function (ContainerInterface $c) { + return new App\Action\GroupAction($c->get('em')); +}); + $container->set('App\Action\FamilyListAction', function (ContainerInterface $c) { return new App\Action\FamilyListAction($c->get('em')); }); diff --git a/app/routes.php b/app/routes.php index c0e3b18..bcd424a 100644 --- a/app/routes.php +++ b/app/routes.php @@ -18,6 +18,8 @@ $app->map([OPTIONS, GET, PUT, DELETE], '/database/{id}', App\Action\DatabaseActi $app->map([OPTIONS, GET], '/database/{id}/table', App\Action\TableListAction::class); $app->map([OPTIONS, GET, POST], '/project', App\Action\ProjectListAction::class); $app->map([OPTIONS, GET, PUT, DELETE], '/project/{name}', App\Action\ProjectAction::class); +$app->map([OPTIONS, GET, POST], '/group', App\Action\GroupListAction::class); +$app->map([OPTIONS, GET, POST], '/group/{id}', App\Action\GroupAction::class); $app->map([OPTIONS, GET, POST], '/instance', App\Action\InstanceListAction::class); $app->map([OPTIONS, GET, PUT, DELETE], '/instance/{name}', App\Action\InstanceAction::class); $app->map([OPTIONS, GET, POST], '/instance/{name}/dataset-family', App\Action\DatasetFamilyListAction::class); diff --git a/conf-dev/create-db.sh b/conf-dev/create-db.sh index b0b7a99..765fc17 100644 --- a/conf-dev/create-db.sh +++ b/conf-dev/create-db.sh @@ -140,3 +140,7 @@ curl -d '{"id":9,"name":"zflg","table_name":"aspic_vipers_dr2_w1","label":"zflg" curl -d '{"id":56,"name":"spec1d","table_name":"aspic_vipers_dr2_w1","label":"spec1d","form_label":"spec1d","description":null,"output_display":560,"criteria_display":560,"search_flag":"SPECTRUM_1D","search_type":null,"type":"text","operator":null,"min":null,"max":null,"placeholder_min":null,"placeholder_max":null,"renderer":"download","renderer_config":{"display":"icon-button","text":"DOWNLOAD","icon":"fas fa-download"},"display_detail":560,"selected":true,"order_by":false,"order_display":560,"detail":true,"renderer_detail":"spectra_graph","options":null,"vo_utype":null,"vo_ucd":null,"vo_unit":null,"vo_description":null,"vo_datatype":null,"vo_size":null,"id_criteria_family":null,"id_output_category":8}' -H "Content-Type: application/json" -X PUT http://localhost/dataset/vipers_dr2_w1/attribute/56 curl -d '{"id":57,"name":"spec1dnoise","table_name":"aspic_vipers_dr2_w1","label":"spec1dnoise","form_label":"spec1dnoise","description":null,"output_display":570,"criteria_display":570,"search_flag":null,"search_type":null,"type":"text","operator":null,"min":null,"max":null,"placeholder_min":null,"placeholder_max":null,"renderer":"download","renderer_config":{"display":"icon-button","text":"DOWNLOAD","icon":"fas fa-download"},"display_detail":570,"selected":true,"order_by":false,"order_display":570,"detail":true,"renderer_detail":null,"options":null,"vo_utype":null,"vo_ucd":null,"vo_unit":null,"vo_description":null,"vo_datatype":null,"vo_size":null,"id_criteria_family":null,"id_output_category":8}' -H "Content-Type: application/json" -X PUT http://localhost/dataset/vipers_dr2_w1/attribute/57 curl -d '{"id":58,"name":"spec1dsky","table_name":"aspic_vipers_dr2_w1","label":"spec1dsky","form_label":"spec1dsky","description":null,"output_display":580,"criteria_display":580,"search_flag":null,"search_type":null,"type":"text","operator":null,"min":null,"max":null,"placeholder_min":null,"placeholder_max":null,"renderer":"download","renderer_config":{"display":"icon-button","text":"DOWNLOAD","icon":"fas fa-download"},"display_detail":580,"selected":true,"order_by":false,"order_display":580,"detail":true,"renderer_detail":null,"options":null,"vo_utype":null,"vo_ucd":null,"vo_unit":null,"vo_description":null,"vo_datatype":null,"vo_size":null,"id_criteria_family":null,"id_output_category":8}' -H "Content-Type: application/json" -X PUT http://localhost/dataset/vipers_dr2_w1/attribute/58 + +# Add groups +curl -d '{"label":"SVOM"}' -H "Content-Type: application/json" -X POST http://localhost/group +curl -d '{"label":"ASPIC"}' -H "Content-Type: application/json" -X POST http://localhost/group diff --git a/src/Action/GroupAction.php b/src/Action/GroupAction.php new file mode 100644 index 0000000..d97aea4 --- /dev/null +++ b/src/Action/GroupAction.php @@ -0,0 +1,94 @@ +getMethod() === OPTIONS) { + return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS'); + } + + // Search the correct group with primary key + $group = $this->em->find('App\Entity\Group', $args['id']); + + // If group is not found 404 + if (is_null($group)) { + throw new HttpNotFoundException( + $request, + 'Group with id ' . $args['id'] . ' is not found' + ); + } + + if ($request->getMethod() === GET) { + $payload = json_encode($group); + } + + if ($request->getMethod() === PUT) { + $parsedBody = $request->getParsedBody(); + + // If mandatories empty fields 400 + foreach (array('label') as $a) { + if ($this->isEmptyField($a, $parsedBody)) { + throw new HttpBadRequestException( + $request, + 'Param ' . $a . ' needed to edit the group' + ); + } + } + + $this->editGroup($group, $parsedBody); + $payload = json_encode($group); + } + + if ($request->getMethod() === DELETE) { + $id = $group->getId(); + $this->em->remove($group); + $this->em->flush(); + $payload = json_encode(array('message' => 'Group with id ' . $id . ' is removed!')); + } + + $response->getBody()->write($payload); + return $response; + } + + /** + * Update group object with setters + * + * @param Group $group The group to update + * @param array $parsedBody Contains the new values ​​of the group sent by the user + */ + private function editGroup(Group $group, array $parsedBody): void + { + $group->setLabel($parsedBody['label']); + $this->em->flush(); + } +} diff --git a/src/Action/GroupListAction.php b/src/Action/GroupListAction.php new file mode 100644 index 0000000..c53298c --- /dev/null +++ b/src/Action/GroupListAction.php @@ -0,0 +1,81 @@ +getMethod() === OPTIONS) { + return $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); + } + + if ($request->getMethod() === GET) { + // Retrieve group with id + $groups = $this->em->getRepository('App\Entity\Group')->findAll(); + $payload = json_encode($groups); + } + + if ($request->getMethod() === POST) { + $parsedBody = $request->getParsedBody(); + + // To work this action needs group information + foreach (array('label') as $a) { + if ($this->isEmptyField($a, $parsedBody)) { + throw new HttpBadRequestException( + $request, + 'Param ' . $a . ' needed to add a new group' + ); + } + } + + $group = $this->postDatabase($parsedBody); + $payload = json_encode($group); + $response = $response->withStatus(201); + } + + $response->getBody()->write($payload); + return $response; + } + + /** + * Add a new group into the metamodel + * + * @param array $parsedBody Contains the values ​​of the new group sent by the user + */ + private function postDatabase(array $parsedBody): Group + { + $group = new Group(); + $group->setLabel($parsedBody['label']); + + $this->em->persist($group); + $this->em->flush(); + + return $group; + } +} diff --git a/src/Entity/Group.php b/src/Entity/Group.php index 2a41941..27ec0ba 100644 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -96,7 +96,7 @@ class Group implements \JsonSerializable } $datasets = array(); - foreach ($this->datasets() as $dataset) { + foreach ($this->getDatasets() as $dataset) { $datasets[] = $dataset->getName(); } -- GitLab From 5a904643668a52fae08883fd4bfd65bac1e2957c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Mon, 2 Nov 2020 21:26:14 +0100 Subject: [PATCH 06/11] Add user list endpoint (list all users) --- app/dependencies.php | 4 ++++ app/routes.php | 1 + src/Action/UserListAction.php | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/Action/UserListAction.php diff --git a/app/dependencies.php b/app/dependencies.php index aadc9f4..e9fbe42 100644 --- a/app/dependencies.php +++ b/app/dependencies.php @@ -76,6 +76,10 @@ $container->set('App\Action\ProjectAction', function (ContainerInterface $c) { return new App\Action\ProjectAction($c->get('em')); }); +$container->set('App\Action\UserListAction', function (ContainerInterface $c) { + return new App\Action\UserListAction($c->get('em')); +}); + $container->set('App\Action\GroupListAction', function (ContainerInterface $c) { return new App\Action\GroupListAction($c->get('em')); }); diff --git a/app/routes.php b/app/routes.php index bcd424a..a7035e6 100644 --- a/app/routes.php +++ b/app/routes.php @@ -18,6 +18,7 @@ $app->map([OPTIONS, GET, PUT, DELETE], '/database/{id}', App\Action\DatabaseActi $app->map([OPTIONS, GET], '/database/{id}/table', App\Action\TableListAction::class); $app->map([OPTIONS, GET, POST], '/project', App\Action\ProjectListAction::class); $app->map([OPTIONS, GET, PUT, DELETE], '/project/{name}', App\Action\ProjectAction::class); +$app->map([OPTIONS, GET], '/user', App\Action\UserListAction::class); $app->map([OPTIONS, GET, POST], '/group', App\Action\GroupListAction::class); $app->map([OPTIONS, GET, POST], '/group/{id}', App\Action\GroupAction::class); $app->map([OPTIONS, GET, POST], '/instance', App\Action\InstanceListAction::class); diff --git a/src/Action/UserListAction.php b/src/Action/UserListAction.php new file mode 100644 index 0000000..6437010 --- /dev/null +++ b/src/Action/UserListAction.php @@ -0,0 +1,45 @@ +getMethod() === OPTIONS) { + return $response->withHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); + } + + if ($request->getMethod() === GET) { + $users = $this->em->getRepository('App\Entity\User')->findAll(); + $payload = json_encode($users); + } + + $response->getBody()->write($payload); + return $response; + } +} -- GitLab From fc89ad894b2aaf99ade47d47e61628674ddf8c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Mon, 2 Nov 2020 22:22:53 +0100 Subject: [PATCH 07/11] Add user endpoint (get one user by email) --- app/dependencies.php | 4 +++ app/routes.php | 1 + src/Action/UserAction.php | 56 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/Action/UserAction.php diff --git a/app/dependencies.php b/app/dependencies.php index e9fbe42..2d7634e 100644 --- a/app/dependencies.php +++ b/app/dependencies.php @@ -80,6 +80,10 @@ $container->set('App\Action\UserListAction', function (ContainerInterface $c) { return new App\Action\UserListAction($c->get('em')); }); +$container->set('App\Action\UserAction', function (ContainerInterface $c) { + return new App\Action\UserAction($c->get('em')); +}); + $container->set('App\Action\GroupListAction', function (ContainerInterface $c) { return new App\Action\GroupListAction($c->get('em')); }); diff --git a/app/routes.php b/app/routes.php index a7035e6..709cf81 100644 --- a/app/routes.php +++ b/app/routes.php @@ -19,6 +19,7 @@ $app->map([OPTIONS, GET], '/database/{id}/table', App\Action\TableListAction::cl $app->map([OPTIONS, GET, POST], '/project', App\Action\ProjectListAction::class); $app->map([OPTIONS, GET, PUT, DELETE], '/project/{name}', App\Action\ProjectAction::class); $app->map([OPTIONS, GET], '/user', App\Action\UserListAction::class); +$app->map([OPTIONS, GET], '/user/{email}', App\Action\UserAction::class); $app->map([OPTIONS, GET, POST], '/group', App\Action\GroupListAction::class); $app->map([OPTIONS, GET, POST], '/group/{id}', App\Action\GroupAction::class); $app->map([OPTIONS, GET, POST], '/instance', App\Action\InstanceListAction::class); diff --git a/src/Action/UserAction.php b/src/Action/UserAction.php new file mode 100644 index 0000000..73d8210 --- /dev/null +++ b/src/Action/UserAction.php @@ -0,0 +1,56 @@ +getMethod() === OPTIONS) { + return $response->withHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); + } + + // Search the correct user with primary key + $user = $this->em->find('App\Entity\User', $args['email']); + + // If user is not found 404 + if (is_null($user)) { + throw new HttpNotFoundException( + $request, + 'User with email ' . $args['email'] . ' is not found' + ); + } + + if ($request->getMethod() === GET) { + $payload = json_encode($user); + } + + $response->getBody()->write($payload); + return $response; + } +} -- GitLab From 2794b6f3f5d68ff14a99fa0832fd304870e96556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Tue, 3 Nov 2020 21:37:03 +0100 Subject: [PATCH 08/11] Add users and groups features => done --- app/routes.php | 4 ++-- conf-dev/create-db.sh | 8 +++++-- src/Action/GroupAction.php | 28 +++++++++++++++++++++++ src/Action/GroupListAction.php | 39 ++++++++++++++++++++++++++++--- src/Action/UserAction.php | 42 ++++++++++++++++++++++++++++++++-- src/Action/UserListAction.php | 37 +++++++++++++++++++++++++++++- src/Entity/Group.php | 24 +++++++++++++++---- src/Entity/User.php | 8 +------ 8 files changed, 168 insertions(+), 22 deletions(-) diff --git a/app/routes.php b/app/routes.php index 709cf81..6cb95d0 100644 --- a/app/routes.php +++ b/app/routes.php @@ -18,8 +18,8 @@ $app->map([OPTIONS, GET, PUT, DELETE], '/database/{id}', App\Action\DatabaseActi $app->map([OPTIONS, GET], '/database/{id}/table', App\Action\TableListAction::class); $app->map([OPTIONS, GET, POST], '/project', App\Action\ProjectListAction::class); $app->map([OPTIONS, GET, PUT, DELETE], '/project/{name}', App\Action\ProjectAction::class); -$app->map([OPTIONS, GET], '/user', App\Action\UserListAction::class); -$app->map([OPTIONS, GET], '/user/{email}', App\Action\UserAction::class); +$app->map([OPTIONS, GET, POST], '/user', App\Action\UserListAction::class); +$app->map([OPTIONS, GET, PUT, DELETE], '/user/{email}', App\Action\UserAction::class); $app->map([OPTIONS, GET, POST], '/group', App\Action\GroupListAction::class); $app->map([OPTIONS, GET, POST], '/group/{id}', App\Action\GroupAction::class); $app->map([OPTIONS, GET, POST], '/instance', App\Action\InstanceListAction::class); diff --git a/conf-dev/create-db.sh b/conf-dev/create-db.sh index 765fc17..3bb8a50 100644 --- a/conf-dev/create-db.sh +++ b/conf-dev/create-db.sh @@ -141,6 +141,10 @@ curl -d '{"id":56,"name":"spec1d","table_name":"aspic_vipers_dr2_w1","label":"sp curl -d '{"id":57,"name":"spec1dnoise","table_name":"aspic_vipers_dr2_w1","label":"spec1dnoise","form_label":"spec1dnoise","description":null,"output_display":570,"criteria_display":570,"search_flag":null,"search_type":null,"type":"text","operator":null,"min":null,"max":null,"placeholder_min":null,"placeholder_max":null,"renderer":"download","renderer_config":{"display":"icon-button","text":"DOWNLOAD","icon":"fas fa-download"},"display_detail":570,"selected":true,"order_by":false,"order_display":570,"detail":true,"renderer_detail":null,"options":null,"vo_utype":null,"vo_ucd":null,"vo_unit":null,"vo_description":null,"vo_datatype":null,"vo_size":null,"id_criteria_family":null,"id_output_category":8}' -H "Content-Type: application/json" -X PUT http://localhost/dataset/vipers_dr2_w1/attribute/57 curl -d '{"id":58,"name":"spec1dsky","table_name":"aspic_vipers_dr2_w1","label":"spec1dsky","form_label":"spec1dsky","description":null,"output_display":580,"criteria_display":580,"search_flag":null,"search_type":null,"type":"text","operator":null,"min":null,"max":null,"placeholder_min":null,"placeholder_max":null,"renderer":"download","renderer_config":{"display":"icon-button","text":"DOWNLOAD","icon":"fas fa-download"},"display_detail":580,"selected":true,"order_by":false,"order_display":580,"detail":true,"renderer_detail":null,"options":null,"vo_utype":null,"vo_ucd":null,"vo_unit":null,"vo_description":null,"vo_datatype":null,"vo_size":null,"id_criteria_family":null,"id_output_category":8}' -H "Content-Type: application/json" -X PUT http://localhost/dataset/vipers_dr2_w1/attribute/58 +# Add users +curl -d '{"email":"charles.degaulle@lam.fr"}' -H "Content-Type: application/json" -X POST http://localhost/user +curl -d '{"email":"georges.pompidou@lam.fr"}' -H "Content-Type: application/json" -X POST http://localhost/user + # Add groups -curl -d '{"label":"SVOM"}' -H "Content-Type: application/json" -X POST http://localhost/group -curl -d '{"label":"ASPIC"}' -H "Content-Type: application/json" -X POST http://localhost/group +curl -d '{"label":"SVOM","users":["charles.degaulle@lam.fr"],"datasets":["obs_cat","observations"]}' -H "Content-Type: application/json" -X POST http://localhost/group +curl -d '{"label":"ASPIC","users":[],"datasets":[]}' -H "Content-Type: application/json" -X POST http://localhost/group diff --git a/src/Action/GroupAction.php b/src/Action/GroupAction.php index d97aea4..63d7e14 100644 --- a/src/Action/GroupAction.php +++ b/src/Action/GroupAction.php @@ -89,6 +89,34 @@ final class GroupAction extends AbstractAction private function editGroup(Group $group, array $parsedBody): void { $group->setLabel($parsedBody['label']); + $group->setUsers($this->getUsers($parsedBody['users'])); + $group->setDatasets($this->getDatasets($parsedBody['datasets'])); $this->em->flush(); } + + private function getUsers(array $listOfUsersIds) + { + if (count($listOfUsersIds) < 1) { + return array(); + } + + $dql = 'SELECT u FROM App\Entity\User u WHERE u.id IN (' . implode(',', $listOfUsersIds) . ')'; + $query = $this->em->createQuery($dql); + return $query->getResult(); + } + + private function getDatasets(array $listOfDatasetsNames) + { + if (count($listOfDatasetsNames) < 1) { + return array(); + } + + $in = implode(',', array_map(function ($d) { + return "'" . $d . "'"; + }, $listOfDatasetsNames)); + + $dql = 'SELECT d FROM App\Entity\Dataset d WHERE d.name IN (' . $in . ')'; + $query = $this->em->createQuery($dql); + return $query->getResult(); + } } diff --git a/src/Action/GroupListAction.php b/src/Action/GroupListAction.php index c53298c..1de869d 100644 --- a/src/Action/GroupListAction.php +++ b/src/Action/GroupListAction.php @@ -54,7 +54,7 @@ final class GroupListAction extends AbstractAction } } - $group = $this->postDatabase($parsedBody); + $group = $this->postGroup($parsedBody); $payload = json_encode($group); $response = $response->withStatus(201); } @@ -68,9 +68,12 @@ final class GroupListAction extends AbstractAction * * @param array $parsedBody Contains the values ​​of the new group sent by the user */ - private function postDatabase(array $parsedBody): Group + private function postGroup(array $parsedBody): Group { - $group = new Group(); + $group = new Group( + $this->getUsers($parsedBody['users']), + $this->getDatasets($parsedBody['datasets']) + ); $group->setLabel($parsedBody['label']); $this->em->persist($group); @@ -78,4 +81,34 @@ final class GroupListAction extends AbstractAction return $group; } + + private function getUsers(array $listOfUsersEmails) + { + if (count($listOfUsersEmails) < 1) { + return array(); + } + + $in = implode(',', array_map(function ($u) { + return "'" . $u . "'"; + }, $listOfUsersEmails)); + + $dql = 'SELECT u FROM App\Entity\User u WHERE u.email IN (' . $in . ')'; + $query = $this->em->createQuery($dql); + return $query->getResult(); + } + + private function getDatasets(array $listOfDatasetsNames) + { + if (count($listOfDatasetsNames) < 1) { + return array(); + } + + $in = implode(',', array_map(function ($d) { + return "'" . $d . "'"; + }, $listOfDatasetsNames)); + + $dql = 'SELECT d FROM App\Entity\Dataset d WHERE d.name IN (' . $in . ')'; + $query = $this->em->createQuery($dql); + return $query->getResult(); + } } diff --git a/src/Action/UserAction.php b/src/Action/UserAction.php index 73d8210..0d7cb8c 100644 --- a/src/Action/UserAction.php +++ b/src/Action/UserAction.php @@ -21,7 +21,9 @@ use App\Entity\User; final class UserAction extends AbstractAction { /** - * `GET` Returns the user found + * `GET` Returns the user found + * `PUT` Full update the user and returns the new version + * `DELETE` Delete the user found and return a confirmation message * * @param ServerRequestInterface $request PSR-7 This object represents the HTTP request * @param ResponseInterface $response PSR-7 This object represents the HTTP response @@ -32,7 +34,7 @@ final class UserAction extends AbstractAction public function __invoke(Request $request, Response $response, array $args): Response { if ($request->getMethod() === OPTIONS) { - return $response->withHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); + return $response->withHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS'); } // Search the correct user with primary key @@ -50,7 +52,43 @@ final class UserAction extends AbstractAction $payload = json_encode($user); } + if ($request->getMethod() === PUT) { + $parsedBody = $request->getParsedBody(); + + // If mandatories empty fields 400 + foreach (array('role') as $a) { + if ($this->isEmptyField($a, $parsedBody)) { + throw new HttpBadRequestException( + $request, + 'Param ' . $a . ' needed to edit the user' + ); + } + } + + $this->editUser($user, $parsedBody); + $payload = json_encode($user); + } + + if ($request->getMethod() === DELETE) { + $email = $user->getEmail(); + $this->em->remove($user); + $this->em->flush(); + $payload = json_encode(array('message' => 'User with email ' . $email . ' is removed!')); + } + $response->getBody()->write($payload); return $response; } + + /** + * Update user object with setters + * + * @param User $user The user to update + * @param array $parsedBody Contains the new values ​​of the user + */ + private function editUser(User $user, array $parsedBody): void + { + $user->setRole($parsedBody['role']); + $this->em->flush(); + } } diff --git a/src/Action/UserListAction.php b/src/Action/UserListAction.php index 6437010..d5c921a 100644 --- a/src/Action/UserListAction.php +++ b/src/Action/UserListAction.php @@ -21,6 +21,7 @@ final class UserListAction extends AbstractAction { /** * `GET` Returns a list of all users listed in the metamodel + * `POST` Add a new user * * @param ServerRequestInterface $request PSR-7 This object represents the HTTP request * @param ResponseInterface $response PSR-7 This object represents the HTTP response @@ -31,7 +32,7 @@ final class UserListAction extends AbstractAction public function __invoke(Request $request, Response $response, array $args): Response { if ($request->getMethod() === OPTIONS) { - return $response->withHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); + return $response->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); } if ($request->getMethod() === GET) { @@ -39,7 +40,41 @@ final class UserListAction extends AbstractAction $payload = json_encode($users); } + if ($request->getMethod() === POST) { + $parsedBody = $request->getParsedBody(); + + // To work this action needs user information + foreach (array('email') as $a) { + if ($this->isEmptyField($a, $parsedBody)) { + throw new HttpBadRequestException( + $request, + 'Param ' . $a . ' needed to add a new user' + ); + } + } + + $user = $this->postUser($parsedBody); + $payload = json_encode($user); + $response = $response->withStatus(201); + } + $response->getBody()->write($payload); return $response; } + + /** + * Add a new user into the metamodel + * + * @param array $parsedBody Contains the values ​​of the new user + */ + private function postUser(array $parsedBody): User + { + $user = new User($parsedBody['email']); + $user->setRole('user'); + + $this->em->persist($user); + $this->em->flush(); + + return $user; + } } diff --git a/src/Entity/Group.php b/src/Entity/Group.php index 27ec0ba..c3b48aa 100644 --- a/src/Entity/Group.php +++ b/src/Entity/Group.php @@ -39,9 +39,13 @@ class Group implements \JsonSerializable /** * Many Groups have Many Users. - * @var Collection * - * @ManyToMany(targetEntity="User", mappedBy="groups") + * @ManyToMany(targetEntity="User", inversedBy="groups") + * @JoinTable( + * name="groups_users", + * joinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}, + * inverseJoinColumns={@JoinColumn(name="user_email", referencedColumnName="email")} + * ) */ protected $users; @@ -57,10 +61,10 @@ class Group implements \JsonSerializable */ protected $datasets; - public function __construct() + public function __construct(array $users, array $datasets) { - $this->users = new ArrayCollection(); - $this->datasets = new ArrayCollection(); + $this->users = new ArrayCollection($users); + $this->datasets = new ArrayCollection($datasets); } public function getId() @@ -83,11 +87,21 @@ class Group implements \JsonSerializable return $this->users; } + public function setUsers($users) + { + $this->users = $users; + } + public function getDatasets() { return $this->datasets; } + public function setDatasets($datasets) + { + $this->datasets = $datasets; + } + public function jsonSerialize() { $users = array(); diff --git a/src/Entity/User.php b/src/Entity/User.php index 5e9d2cc..5a867a8 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -38,14 +38,8 @@ class User implements \JsonSerializable /** * Many Users have Many Groups. - * @var Collection * - * @ManyToMany(targetEntity="Group", inversedBy="users") - * @JoinTable( - * name="users_groups", - * joinColumns={@JoinColumn(name="email", referencedColumnName="email")}, - * inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")} - * ) + * @ManyToMany(targetEntity="Group", mappedBy="users") */ protected $groups; -- GitLab From 0f40f1b555577bc9ecfa26fb46bb707c7dd6d4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Tue, 3 Nov 2020 21:45:20 +0100 Subject: [PATCH 09/11] Fixed phpcs issues --- src/Action/DatasetAction.php | 4 +-- src/Action/GroupAction.php | 2 +- src/Action/GroupListAction.php | 4 +-- src/Action/ProjectAction.php | 2 +- src/Action/SearchAction.php | 2 +- src/Entity/Attribute.php | 2 +- src/Entity/CriteriaFamily.php | 6 ++-- src/Entity/Dataset.php | 46 ++++++++++++------------- src/Entity/DatasetFamily.php | 2 +- src/Entity/OutputCategory.php | 4 +-- src/Entity/OutputFamily.php | 6 ++-- src/Utils/Operator/JsonPostgres.php | 2 +- src/Utils/Operator/OperatorFactory.php | 2 +- tests/Action/AttributeActionTest.php | 2 +- tests/Middleware/CorsMiddlewareTest.php | 2 +- 15 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Action/DatasetAction.php b/src/Action/DatasetAction.php index ae6c2b6..466a3d5 100644 --- a/src/Action/DatasetAction.php +++ b/src/Action/DatasetAction.php @@ -48,7 +48,7 @@ final class DatasetAction extends AbstractAction 'Dataset with name ' . $args['name'] . ' is not found' ); } - + if ($request->getMethod() === GET) { $payload = json_encode($dataset, JSON_UNESCAPED_SLASHES); } @@ -85,7 +85,7 @@ final class DatasetAction extends AbstractAction 'Dataset family with id ' . $parsedBody['id_dataset_family'] . ' is not found' ); } - + $this->editDataset($dataset, $parsedBody, $family); $payload = json_encode($dataset, JSON_UNESCAPED_SLASHES); } diff --git a/src/Action/GroupAction.php b/src/Action/GroupAction.php index 63d7e14..0d9f21f 100644 --- a/src/Action/GroupAction.php +++ b/src/Action/GroupAction.php @@ -99,7 +99,7 @@ final class GroupAction extends AbstractAction if (count($listOfUsersIds) < 1) { return array(); } - + $dql = 'SELECT u FROM App\Entity\User u WHERE u.id IN (' . implode(',', $listOfUsersIds) . ')'; $query = $this->em->createQuery($dql); return $query->getResult(); diff --git a/src/Action/GroupListAction.php b/src/Action/GroupListAction.php index 1de869d..3acf867 100644 --- a/src/Action/GroupListAction.php +++ b/src/Action/GroupListAction.php @@ -91,7 +91,7 @@ final class GroupListAction extends AbstractAction $in = implode(',', array_map(function ($u) { return "'" . $u . "'"; }, $listOfUsersEmails)); - + $dql = 'SELECT u FROM App\Entity\User u WHERE u.email IN (' . $in . ')'; $query = $this->em->createQuery($dql); return $query->getResult(); @@ -102,7 +102,7 @@ final class GroupListAction extends AbstractAction if (count($listOfDatasetsNames) < 1) { return array(); } - + $in = implode(',', array_map(function ($d) { return "'" . $d . "'"; }, $listOfDatasetsNames)); diff --git a/src/Action/ProjectAction.php b/src/Action/ProjectAction.php index 138b1cd..6c55379 100644 --- a/src/Action/ProjectAction.php +++ b/src/Action/ProjectAction.php @@ -55,7 +55,7 @@ final class ProjectAction extends AbstractAction if ($request->getMethod() === PUT) { $parsedBody = $request->getParsedBody(); - + // If mandatories empty fields 400 foreach (array('label', 'description', 'link', 'manager', 'id_database') as $a) { if ($this->isEmptyField($a, $parsedBody)) { diff --git a/src/Action/SearchAction.php b/src/Action/SearchAction.php index b15d43c..35ed1b4 100644 --- a/src/Action/SearchAction.php +++ b/src/Action/SearchAction.php @@ -83,7 +83,7 @@ final class SearchAction extends AbstractAction $connection = $this->connectionFactory->create($dataset->getProject()->getDatabase()); $queryBuilder = $connection->createQueryBuilder(); $queryBuilder->from($dataset->getTableRef()); - + $queryParams = $request->getQueryParams(); // The parameter "a" is mandatory diff --git a/src/Entity/Attribute.php b/src/Entity/Attribute.php index 8eddc35..cec28a2 100644 --- a/src/Entity/Attribute.php +++ b/src/Entity/Attribute.php @@ -134,7 +134,7 @@ class Attribute implements \JsonSerializable * @Column(type="string", name="placeholder_min", nullable=true) */ protected $placeholderMin; - + /** * @var string * diff --git a/src/Entity/CriteriaFamily.php b/src/Entity/CriteriaFamily.php index 3317abc..00fda78 100644 --- a/src/Entity/CriteriaFamily.php +++ b/src/Entity/CriteriaFamily.php @@ -26,7 +26,7 @@ class CriteriaFamily implements \JsonSerializable * @GeneratedValue */ protected $id; - + /** * @var string * @@ -58,12 +58,12 @@ class CriteriaFamily implements \JsonSerializable { return $this->id; } - + public function getLabel() { return $this->label; } - + public function setLabel($label) { $this->label = $label; diff --git a/src/Entity/Dataset.php b/src/Entity/Dataset.php index 9ed9b42..4038240 100644 --- a/src/Entity/Dataset.php +++ b/src/Entity/Dataset.php @@ -27,42 +27,42 @@ class Dataset implements \JsonSerializable * @Column(type="string", nullable=false) */ protected $name; - + /** * @var string * * @Column(type="string", name="table_ref", nullable=false) */ protected $tableRef; - + /** * @var string * * @Column(type="string", nullable=false) */ protected $label; - + /** * @var string * * @Column(type="text", nullable=true) */ protected $description; - + /** * @var int * * @Column(type="integer", nullable=false) */ protected $display; - + /** * @var int * * @Column(type="integer", nullable=true) */ protected $count; - + /** * @var bool * @@ -90,7 +90,7 @@ class Dataset implements \JsonSerializable * @Column(type="boolean", nullable=false) */ protected $public; - + /** * @var Anis\Entity\Project * @@ -106,7 +106,7 @@ class Dataset implements \JsonSerializable * @JoinColumn(name="id_dataset_family", referencedColumnName="id", nullable=false) */ protected $datasetFamily; - + /** * @var Anis\Entity\Attribute[] * @@ -119,72 +119,72 @@ class Dataset implements \JsonSerializable $this->name = $name; $this->attributes = new ArrayCollection(); } - + public function getName() { return $this->name; } - + public function getTableRef() { return $this->tableRef; } - + public function setTableRef($tableRef) { $this->tableRef = $tableRef; } - + public function getLabel() { return $this->label; } - + public function setLabel($label) { $this->label = $label; } - + public function getDescription() { return $this->description; } - + public function setDescription($description) { $this->description = $description; } - + public function getDisplay() { return $this->display; } - + public function setDisplay($display) { $this->display = $display; } - + public function getCount() { return $this->count; } - + public function setCount($count) { $this->count = $count; } - + public function getVo() { return $this->vo; } - + public function setVo($vo) { $this->vo = $vo; } - + public function getDataPath() { return $this->dataPath; @@ -219,7 +219,7 @@ class Dataset implements \JsonSerializable { return $this->project; } - + public function setProject($project) { $this->project = $project; diff --git a/src/Entity/DatasetFamily.php b/src/Entity/DatasetFamily.php index d0da25d..a053578 100644 --- a/src/Entity/DatasetFamily.php +++ b/src/Entity/DatasetFamily.php @@ -28,7 +28,7 @@ class DatasetFamily implements \JsonSerializable * @GeneratedValue */ protected $id; - + /** * @var string * diff --git a/src/Entity/OutputCategory.php b/src/Entity/OutputCategory.php index 877bd4d..0fddfd5 100644 --- a/src/Entity/OutputCategory.php +++ b/src/Entity/OutputCategory.php @@ -48,7 +48,7 @@ class OutputCategory implements \JsonSerializable * @JoinColumn(name="output_family", referencedColumnName="id", nullable=false) */ protected $outputFamily; - + public function getId() { return $this->id; @@ -78,7 +78,7 @@ class OutputCategory implements \JsonSerializable { $this->outputFamily = $outputFamily; } - + public function getOutputFamily() { return $this->outputFamily; diff --git a/src/Entity/OutputFamily.php b/src/Entity/OutputFamily.php index ee5ef98..740c19b 100644 --- a/src/Entity/OutputFamily.php +++ b/src/Entity/OutputFamily.php @@ -26,7 +26,7 @@ class OutputFamily implements \JsonSerializable * @GeneratedValue */ protected $id; - + /** * @var string * @@ -58,12 +58,12 @@ class OutputFamily implements \JsonSerializable { return $this->id; } - + public function getLabel() { return $this->label; } - + public function setLabel($label) { $this->label = $label; diff --git a/src/Utils/Operator/JsonPostgres.php b/src/Utils/Operator/JsonPostgres.php index 94adbb0..c5dbe7d 100644 --- a/src/Utils/Operator/JsonPostgres.php +++ b/src/Utils/Operator/JsonPostgres.php @@ -72,7 +72,7 @@ class JsonPostgres extends Operator } else { $newValue = $this->value; } - + return $this->getSqlValue(json_encode($newValue)); } } diff --git a/src/Utils/Operator/OperatorFactory.php b/src/Utils/Operator/OperatorFactory.php index 7a80e69..c854a8f 100644 --- a/src/Utils/Operator/OperatorFactory.php +++ b/src/Utils/Operator/OperatorFactory.php @@ -100,7 +100,7 @@ class OperatorFactory implements IOperatorFactory throw OperatorException::operatorBadNumberOfParameters($type, 1); } return new NotLike($expr, $column, $columnType, $parameters[0]); - + case 'in': if (count($parameters) < 1) { throw OperatorException::inBadNumberOfParameters($type); diff --git a/tests/Action/AttributeActionTest.php b/tests/Action/AttributeActionTest.php index 55e33f1..56aa8d7 100644 --- a/tests/Action/AttributeActionTest.php +++ b/tests/Action/AttributeActionTest.php @@ -256,7 +256,7 @@ final class AttributeActionTest extends TestCase $attribute->setSelected(true); $this->entityManager->persist($attribute); $this->entityManager->flush(); - + return $attribute; } } diff --git a/tests/Middleware/CorsMiddlewareTest.php b/tests/Middleware/CorsMiddlewareTest.php index 7e76f23..4264918 100644 --- a/tests/Middleware/CorsMiddlewareTest.php +++ b/tests/Middleware/CorsMiddlewareTest.php @@ -40,7 +40,7 @@ final class CorsMiddlewareTest extends TestCase (string) $response->getHeaderLine('Access-Control-Allow-Headers') ); } - + public function testCorsHeadersForGetMethod() { $request = new ServerRequest('GET', '/'); -- GitLab From ae0c3c1378d55c1d82b1270270ea76acf494dc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Tue, 3 Nov 2020 22:05:03 +0100 Subject: [PATCH 10/11] Fixed unit tests for dataset property public --- tests/Action/AttributeActionTest.php | 1 + tests/Action/AttributeListActionTest.php | 1 + tests/Action/CriteriaFamilyActionTest.php | 1 + tests/Action/CriteriaFamilyListActionTest.php | 1 + tests/Action/DatasetActionTest.php | 2 ++ tests/Action/DatasetListActionTest.php | 3 +++ tests/Action/DatasetListByInstanceActionTest.php | 2 ++ tests/Action/OutputCategoryActionTest.php | 1 + tests/Action/OutputCategoryListActionTest.php | 1 + tests/Action/OutputCategoryListByDatasetActionTest.php | 1 + tests/Action/OutputFamilyActionTest.php | 1 + tests/Action/OutputFamilyListActionTest.php | 1 + 12 files changed, 16 insertions(+) diff --git a/tests/Action/AttributeActionTest.php b/tests/Action/AttributeActionTest.php index 56aa8d7..5ba5971 100644 --- a/tests/Action/AttributeActionTest.php +++ b/tests/Action/AttributeActionTest.php @@ -228,6 +228,7 @@ final class AttributeActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/AttributeListActionTest.php b/tests/Action/AttributeListActionTest.php index 15decb8..0cda65f 100644 --- a/tests/Action/AttributeListActionTest.php +++ b/tests/Action/AttributeListActionTest.php @@ -132,6 +132,7 @@ final class AttributeListActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/CriteriaFamilyActionTest.php b/tests/Action/CriteriaFamilyActionTest.php index b179416..87cf07a 100644 --- a/tests/Action/CriteriaFamilyActionTest.php +++ b/tests/Action/CriteriaFamilyActionTest.php @@ -178,6 +178,7 @@ final class CriteriaFamilyActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/CriteriaFamilyListActionTest.php b/tests/Action/CriteriaFamilyListActionTest.php index d5ffdd1..f749e01 100644 --- a/tests/Action/CriteriaFamilyListActionTest.php +++ b/tests/Action/CriteriaFamilyListActionTest.php @@ -179,6 +179,7 @@ final class CriteriaFamilyListActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/DatasetActionTest.php b/tests/Action/DatasetActionTest.php index ff6e15f..45dd902 100644 --- a/tests/Action/DatasetActionTest.php +++ b/tests/Action/DatasetActionTest.php @@ -135,6 +135,7 @@ final class DatasetActionTest extends TestCase 'vo' => false, 'data_path' => '/mnt/dataset1', 'config' => '{}', + 'public' => true, 'id_dataset_family' => 1 ); } @@ -198,6 +199,7 @@ final class DatasetActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/DatasetListActionTest.php b/tests/Action/DatasetListActionTest.php index 5629542..acd4122 100644 --- a/tests/Action/DatasetListActionTest.php +++ b/tests/Action/DatasetListActionTest.php @@ -126,6 +126,7 @@ final class DatasetListActionTest extends TestCase 'vo' => false, 'data_path' => '/mnt/dataset1', 'config' => '{}', + 'public' => true, 'project_name' => 'anis_project', 'id_dataset_family' => 1 ); @@ -190,6 +191,7 @@ final class DatasetListActionTest extends TestCase $dataset1->setCount(10000); $dataset1->setVo(false); $dataset1->setDataPath('/mnt/dataset1'); + $dataset1->setPublic(true); $dataset1->setProject($project); $dataset1->setDatasetFamily($family); $this->entityManager->persist($dataset1); @@ -202,6 +204,7 @@ final class DatasetListActionTest extends TestCase $dataset2->setCount(5000); $dataset2->setVo(false); $dataset2->setDataPath('/mnt/dataset2'); + $dataset2->setPublic(true); $dataset2->setProject($project); $dataset2->setDatasetFamily($family); $this->entityManager->persist($dataset2); diff --git a/tests/Action/DatasetListByInstanceActionTest.php b/tests/Action/DatasetListByInstanceActionTest.php index 48a498a..9594892 100644 --- a/tests/Action/DatasetListByInstanceActionTest.php +++ b/tests/Action/DatasetListByInstanceActionTest.php @@ -130,6 +130,7 @@ final class DatasetListByInstanceActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); @@ -142,6 +143,7 @@ final class DatasetListByInstanceActionTest extends TestCase $dataset2->setCount(5000); $dataset2->setVo(false); $dataset2->setDataPath('/mnt/observations'); + $dataset2->setPublic(true); $dataset2->setProject($project); $dataset2->setDatasetFamily($family); $this->entityManager->persist($dataset2); diff --git a/tests/Action/OutputCategoryActionTest.php b/tests/Action/OutputCategoryActionTest.php index 4d6777e..fc4d8db 100644 --- a/tests/Action/OutputCategoryActionTest.php +++ b/tests/Action/OutputCategoryActionTest.php @@ -197,6 +197,7 @@ final class OutputCategoryActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/OutputCategoryListActionTest.php b/tests/Action/OutputCategoryListActionTest.php index 07903d1..1d2f976 100644 --- a/tests/Action/OutputCategoryListActionTest.php +++ b/tests/Action/OutputCategoryListActionTest.php @@ -173,6 +173,7 @@ final class OutputCategoryListActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/OutputCategoryListByDatasetActionTest.php b/tests/Action/OutputCategoryListByDatasetActionTest.php index cbb719f..990ebf0 100644 --- a/tests/Action/OutputCategoryListByDatasetActionTest.php +++ b/tests/Action/OutputCategoryListByDatasetActionTest.php @@ -147,6 +147,7 @@ final class OutputCategoryListByDatasetActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/OutputFamilyActionTest.php b/tests/Action/OutputFamilyActionTest.php index aa1874d..90bfcab 100644 --- a/tests/Action/OutputFamilyActionTest.php +++ b/tests/Action/OutputFamilyActionTest.php @@ -178,6 +178,7 @@ final class OutputFamilyActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); diff --git a/tests/Action/OutputFamilyListActionTest.php b/tests/Action/OutputFamilyListActionTest.php index 2da33a6..b7e20c2 100644 --- a/tests/Action/OutputFamilyListActionTest.php +++ b/tests/Action/OutputFamilyListActionTest.php @@ -179,6 +179,7 @@ final class OutputFamilyListActionTest extends TestCase $dataset->setCount(10000); $dataset->setVo(false); $dataset->setDataPath('/mnt/obs_cat'); + $dataset->setPublic(true); $dataset->setProject($project); $dataset->setDatasetFamily($family); $this->entityManager->persist($dataset); -- GitLab From e060333fbd2f8bdc5ae2ccc70b87ab189cd4149d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Agneray?= Date: Tue, 3 Nov 2020 22:12:43 +0100 Subject: [PATCH 11/11] Methods put and delete added for GroupAction --- app/routes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes.php b/app/routes.php index 6cb95d0..5b255b7 100644 --- a/app/routes.php +++ b/app/routes.php @@ -21,7 +21,7 @@ $app->map([OPTIONS, GET, PUT, DELETE], '/project/{name}', App\Action\ProjectActi $app->map([OPTIONS, GET, POST], '/user', App\Action\UserListAction::class); $app->map([OPTIONS, GET, PUT, DELETE], '/user/{email}', App\Action\UserAction::class); $app->map([OPTIONS, GET, POST], '/group', App\Action\GroupListAction::class); -$app->map([OPTIONS, GET, POST], '/group/{id}', App\Action\GroupAction::class); +$app->map([OPTIONS, GET, PUT, DELETE], '/group/{id}', App\Action\GroupAction::class); $app->map([OPTIONS, GET, POST], '/instance', App\Action\InstanceListAction::class); $app->map([OPTIONS, GET, PUT, DELETE], '/instance/{name}', App\Action\InstanceAction::class); $app->map([OPTIONS, GET, POST], '/instance/{name}/dataset-family', App\Action\DatasetFamilyListAction::class); -- GitLab