From cdba14027f4159a5538a4ba27758f04acd8afb6c Mon Sep 17 00:00:00 2001 From: tykayn Date: Fri, 29 Nov 2019 10:38:43 +0100 Subject: [PATCH 1/5] :zap: hop --- .env | 3 +-- .env.production | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .env.production diff --git a/.env b/.env index 2e3809f..b914756 100644 --- a/.env +++ b/.env @@ -25,6 +25,5 @@ APP_SECRET=597b0529ac702d27dcb9089f7e69c362 # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11" # IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml -DATABASE_URL=mysql://root:plopplop01@127.0.0.1:3306/tykayn - +DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name ###< doctrine/doctrine-bundle ### diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..2e3809f --- /dev/null +++ b/.env.production @@ -0,0 +1,30 @@ +# In all environments, the following files are loaded if they exist, +# the latter taking precedence over the former: +# +# * .env contains default values for the environment variables needed by the app +# * .env.local uncommitted file with local overrides +# * .env.$APP_ENV committed environment-specific defaults +# * .env.$APP_ENV.local uncommitted environment-specific overrides +# +# Real environment variables win over .env files. +# +# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. +# +# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). +# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration + +###> symfony/framework-bundle ### +APP_ENV=dev +APP_SECRET=597b0529ac702d27dcb9089f7e69c362 +#TRUSTED_PROXIES=127.0.0.1,127.0.0.2 +#TRUSTED_HOSTS='^localhost|example\.com$' +###< symfony/framework-bundle ### + +###> doctrine/doctrine-bundle ### +# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url +# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" +# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11" +# IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml +DATABASE_URL=mysql://root:plopplop01@127.0.0.1:3306/tykayn + +###< doctrine/doctrine-bundle ### From a3cc53126f475b8cf6d00fae7d294afe33827794 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Sun, 1 Dec 2019 15:20:07 +0100 Subject: [PATCH 2/5] add expose annotations --- src/Entity/Choice.php | 1 + src/Entity/Poll.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index cd838e4..8db1eba 100644 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -10,6 +10,7 @@ use JMS\Serializer\Annotation as Serializer; /** * one poll choice, could be a text or a date * @ORM\Entity(repositoryClass="App\Repository\ChoiceRepository") + * @Serializer\ExclusionPolicy("all") */ class Choice { /** diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index 442f450..01521c8 100644 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -10,7 +10,7 @@ use JMS\Serializer\Annotation as Serializer; /** * @ORM\Entity(repositoryClass="App\Repository\PollRepository") - * @Serializer\ExclusionPolicy("ALL") + * @Serializer\ExclusionPolicy("all") */ class Poll { /** @@ -86,44 +86,52 @@ class Poll { * send a mail on a new comment * @ORM\Column(type="boolean", nullable=true) * @Serializer\Type("boolean") + * @Serializer\Expose() */ public $mailOnComment; /** * send a mail on a new vote * @ORM\Column(type="boolean", nullable=true) * @Serializer\Type("boolean") + * @Serializer\Expose() */ public $mailOnVote; /** * hide publicly results * @ORM\Column(type="boolean", nullable=true) * @Serializer\Type("boolean") + * @Serializer\Expose() */ public $hideResults; /** * show publicly results even if there is a password to access the vote * @ORM\Column(type="boolean", nullable=true) * @Serializer\Type("boolean") + * @Serializer\Expose() */ public $showResultEvenIfPasswords; /** * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) * @Serializer\Type("App\Entity\Vote") + * @Serializer\Expose() */ public $votes; /** * @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) * @Serializer\Type("App\Entity\StackOfVotes") + * @Serializer\Expose() */ public $stacksOfVotes; /** * @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) * @Serializer\Type("App\Entity\Choice") + * @Serializer\Expose() */ public $choices; /** * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) * @Serializer\Type("App\Entity\Comment") + * @Serializer\Expose() */ public $comments; /** @@ -141,6 +149,7 @@ class Poll { /** * number of days from now for default expiracy date * @var int + * @Serializer\Expose() */ public $defaultExpiracyDaysFromNow = 60; private $maxChoicesLimit = 25; From 0ce0e4f427d85c3be7d4b39b2ece449f9d7abca1 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Sun, 1 Dec 2019 15:36:31 +0100 Subject: [PATCH 3/5] :zap: ugly way to retrieve poll properties because of jsmserializer config not working as expected --- src/Controller/DefaultController.php | 39 +++++++++++++++++++--------- src/Entity/Choice.php | 2 +- src/Entity/Poll.php | 4 --- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 9dd06dc..d81bd40 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -173,18 +173,36 @@ class DefaultController extends AbstractController { $pass = $poll->getPassword(); $data = $request->getContent(); $data = json_decode( $data, true ); + + $comments = []; + $stacks = []; + $choices = []; + foreach ( $poll->getComments() as $c ) { + $comments[] = $c; + } + foreach ( $poll->getStacksOfVotes() as $c ) { + $stacks[] = $c; + } + foreach ( $poll->getChoices() as $c ) { + $choices[] = $c; + } + $returnedPoll = [ + 'message' => 'your poll config', + 'data' => $poll, + 'stacks_count' => count( $stacks ), + 'stacks' => $stacks, + 'choices_count' => count( $choices ), + 'choices' => $choices, + 'comments' => $comments, + ]; /** * password protected content */ if ( $pass ) { if ( $pass == md5( $data[ 'password_input' ] ) ) { - return $this->json( [ - 'message' => 'your poll config', - 'data' => $poll, - 'stacks' => $poll->getStacksOfVotes(), - 'comments' => $poll->getComments(), - ], + return $this->json( + $returnedPoll, 200 ); } else { return $this->json( [ @@ -194,12 +212,9 @@ class DefaultController extends AbstractController { 403 ); } } else { - return $this->json( [ - 'message' => 'your poll config', - 'data' => $poll, - 'stacks' => $poll->getStacksOfVotes(), - 'comments' => $poll->getComments(), - ], + return $this->json( + $returnedPoll + , 200 ); } diff --git a/src/Entity/Choice.php b/src/Entity/Choice.php index 8db1eba..fa29519 100644 --- a/src/Entity/Choice.php +++ b/src/Entity/Choice.php @@ -19,7 +19,7 @@ class Choice { * @ORM\Column(type="integer") * @Serializer\Expose() */ - private $id; + public $id; /** * @ORM\Column(type="string", length=255, nullable=true) diff --git a/src/Entity/Poll.php b/src/Entity/Poll.php index 01521c8..b85501b 100644 --- a/src/Entity/Poll.php +++ b/src/Entity/Poll.php @@ -112,25 +112,21 @@ class Poll { public $showResultEvenIfPasswords; /** * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("App\Entity\Vote") * @Serializer\Expose() */ public $votes; /** * @ORM\OneToMany(targetEntity="App\Entity\StackOfVotes", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("App\Entity\StackOfVotes") * @Serializer\Expose() */ public $stacksOfVotes; /** * @ORM\OneToMany(targetEntity="App\Entity\Choice", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("App\Entity\Choice") * @Serializer\Expose() */ public $choices; /** * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="poll", orphanRemoval=true, cascade={"persist", "remove"}) - * @Serializer\Type("App\Entity\Comment") * @Serializer\Expose() */ public $comments; From e2071395104962d89597d88df9ec1a858d1d8a94 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Wed, 11 Dec 2019 11:31:21 +0100 Subject: [PATCH 4/5] :zap: update ignore --- .env.production | 2 +- .gitignore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.production b/.env.production index 2e3809f..4ed00b3 100644 --- a/.env.production +++ b/.env.production @@ -25,6 +25,6 @@ APP_SECRET=597b0529ac702d27dcb9089f7e69c362 # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11" # IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml -DATABASE_URL=mysql://root:plopplop01@127.0.0.1:3306/tykayn +DATABASE_URL=mysql://root:DB_PASS@127.0.0.1:3306/DB_USER ###< doctrine/doctrine-bundle ### diff --git a/.gitignore b/.gitignore index 2965966..616410a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ ###> symfony/framework-bundle ### -/.env.local +.env.local /.env.local.php /.env.*.local /public/bundles/ From 9edece55bb7b8133f5d6dc46aa7d331760e03772 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Wed, 11 Dec 2019 11:38:21 +0100 Subject: [PATCH 5/5] :book: doc --- .env.production | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.production b/.env.production index 4ed00b3..130ce74 100644 --- a/.env.production +++ b/.env.production @@ -25,6 +25,7 @@ APP_SECRET=597b0529ac702d27dcb9089f7e69c362 # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11" # IMPORTANT: You MUST also configure your db driver and server_version in config/packages/doctrine.yaml -DATABASE_URL=mysql://root:DB_PASS@127.0.0.1:3306/DB_USER +# CHANGE THIS TO SUIT YOUR PRODUCTION ENV +DATABASE_URL=mysql://db_user:db_password@127.0.0.1:5432/db_name ###< doctrine/doctrine-bundle ###