mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
Compare commits
3 Commits
0f8d981c94
...
fd28433dd8
Author | SHA1 | Date | |
---|---|---|---|
fd28433dd8 | |||
18d251270b | |||
28ccc52dd6 |
@ -46,6 +46,7 @@
|
||||
"doctrine/doctrine-migrations-bundle": "^3.1",
|
||||
"doctrine/orm": "^2.8",
|
||||
"friendsofsymfony/rest-bundle": "^3.0",
|
||||
"gedmo/doctrine-extensions": "^3.0",
|
||||
"jms/serializer-bundle": "^3.9",
|
||||
"nelmio/cors-bundle": "^2.1",
|
||||
"sensio/framework-extra-bundle": "^6.1",
|
||||
|
149
composer.lock
generated
149
composer.lock
generated
@ -4,8 +4,57 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "104b8c116015bbc6f7f3efa3d0618a90",
|
||||
"content-hash": "9f35ffaf799b2f21e80284cb4800a791",
|
||||
"packages": [
|
||||
{
|
||||
"name": "behat/transliterator",
|
||||
"version": "v1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Behat/Transliterator.git",
|
||||
"reference": "3c4ec1d77c3d05caa1f0bf8fb3aae4845005c7fc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Behat/Transliterator/zipball/3c4ec1d77c3d05caa1f0bf8fb3aae4845005c7fc",
|
||||
"reference": "3c4ec1d77c3d05caa1f0bf8fb3aae4845005c7fc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"chuyskywalker/rolling-curl": "^3.1",
|
||||
"php-yaoi/php-yaoi": "^1.0",
|
||||
"phpunit/phpunit": "^4.8.36|^6.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.2-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Behat\\Transliterator\\": "src/Behat/Transliterator"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Artistic-1.0"
|
||||
],
|
||||
"description": "String transliterator",
|
||||
"keywords": [
|
||||
"i18n",
|
||||
"slug",
|
||||
"transliterator"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Behat/Transliterator/issues",
|
||||
"source": "https://github.com/Behat/Transliterator/tree/v1.3.0"
|
||||
},
|
||||
"time": "2020-01-14T16:39:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/package-versions-deprecated",
|
||||
"version": "1.11.99.1",
|
||||
@ -1682,6 +1731,104 @@
|
||||
},
|
||||
"time": "2021-01-02T11:26:24+00:00"
|
||||
},
|
||||
{
|
||||
"name": "gedmo/doctrine-extensions",
|
||||
"version": "v3.0.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/doctrine-extensions/DoctrineExtensions.git",
|
||||
"reference": "f956c3c4d0c0ffdc5dd879288073772e439b6c1a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/f956c3c4d0c0ffdc5dd879288073772e439b6c1a",
|
||||
"reference": "f956c3c4d0c0ffdc5dd879288073772e439b6c1a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"behat/transliterator": "~1.2",
|
||||
"doctrine/annotations": "^1.2",
|
||||
"doctrine/cache": "^1.0",
|
||||
"doctrine/collections": "^1.0",
|
||||
"doctrine/common": "^2.13 || ^3.0",
|
||||
"doctrine/event-manager": "^1.0",
|
||||
"php": "^7.2 || ^8.0"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/mongodb": "<1.3",
|
||||
"doctrine/mongodb-odm": "<2.0",
|
||||
"sebastian/comparator": "<2.0"
|
||||
},
|
||||
"provide": {
|
||||
"ext-mongo": "1.6.12"
|
||||
},
|
||||
"require-dev": {
|
||||
"alcaeus/mongo-php-adapter": "^1.1",
|
||||
"doctrine/doctrine-bundle": "^2.3",
|
||||
"doctrine/mongodb-odm": "^2.0",
|
||||
"doctrine/orm": "^2.6.3",
|
||||
"friendsofphp/php-cs-fixer": "^2.16",
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"symfony/yaml": "^4.1"
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/mongodb-odm": "to use the extensions with the MongoDB ODM",
|
||||
"doctrine/orm": "to use the extensions with the ORM"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Gedmo\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gediminas Morkevicius",
|
||||
"email": "gediminas.morkevicius@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Gustavo Falco",
|
||||
"email": "comfortablynumb84@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "David Buchmann",
|
||||
"email": "david@liip.ch"
|
||||
}
|
||||
],
|
||||
"description": "Doctrine2 behavioral extensions",
|
||||
"homepage": "http://gediminasm.org/",
|
||||
"keywords": [
|
||||
"Blameable",
|
||||
"behaviors",
|
||||
"doctrine2",
|
||||
"extensions",
|
||||
"gedmo",
|
||||
"loggable",
|
||||
"nestedset",
|
||||
"sluggable",
|
||||
"sortable",
|
||||
"timestampable",
|
||||
"translatable",
|
||||
"tree",
|
||||
"uploadable"
|
||||
],
|
||||
"support": {
|
||||
"email": "gediminas.morkevicius@gmail.com",
|
||||
"issues": "https://github.com/doctrine-extensions/DoctrineExtensions/issues",
|
||||
"source": "https://github.com/doctrine-extensions/DoctrineExtensions/tree/v3.0.5",
|
||||
"wiki": "https://github.com/Atlantic18/DoctrineExtensions/tree/main/doc"
|
||||
},
|
||||
"time": "2021-04-23T09:16:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jms/metadata",
|
||||
"version": "2.5.0",
|
||||
|
@ -1,3 +1,5 @@
|
||||
sensio_framework_extra:
|
||||
request:
|
||||
converters: true
|
||||
router:
|
||||
annotations: false
|
||||
|
@ -72,6 +72,10 @@ server {
|
||||
include fastcgi.conf;
|
||||
fastcgi_intercept_errors on;
|
||||
fastcgi_pass php-handler;
|
||||
|
||||
proxy_busy_buffers_size 512k;
|
||||
proxy_buffers 4 512k;
|
||||
proxy_buffer_size 256k;
|
||||
# When you are using symlinks to link the document root to the
|
||||
# current version of your application, you should pass the real
|
||||
# application path instead of the path to the symlink to PHP
|
||||
@ -92,4 +96,5 @@ server {
|
||||
location ~ \.php$ {
|
||||
return 404;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace App\Controller;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
use JMS\Serializer\Type\Exception\Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Swift_Mailer;
|
||||
use Swift_Message;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@ -59,6 +58,25 @@ class EmailsController extends AbstractController {
|
||||
if ( ! isset( $config[ 'poll' ] ) ) {
|
||||
$config[ 'poll' ] = new Poll();
|
||||
}
|
||||
if ( $config[ 'email_template' ] === 'owner_list' ) {
|
||||
|
||||
// refuse to send all its poll list to an owner by email if it were asked less than 10 seconds ago
|
||||
|
||||
$requested = $config[ 'owner' ]->getRequestedPollsDate(); //from database
|
||||
|
||||
$today_time = strtotime( date( "Y-m-d" ) );
|
||||
$expire_time = strtotime( $requested );
|
||||
if ( $expire_time - $today_time < 10 ) {
|
||||
throw new \HttpException( "you asked for this email less than 10 seconds ago. wait a little.", 403 );
|
||||
}
|
||||
|
||||
$config[ 'owner' ]->setRequestedPollsDate( new \DateTime() );
|
||||
}
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist( $config[ 'owner' ] );
|
||||
$em->flush();
|
||||
|
||||
|
||||
$emailChoicesTemplates = [
|
||||
'creation_poll' => 'creation-mail.html.twig',
|
||||
'edit_poll' => 'modification-notification-mail.html.twig',
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Controller\api\v1;
|
||||
|
||||
use App\Controller\EmailsController;
|
||||
use App\Entity\Choice;
|
||||
use App\Entity\Comment;
|
||||
use App\Entity\Owner;
|
||||
use App\Entity\Poll;
|
||||
@ -13,6 +14,7 @@ use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Patch;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@ -46,7 +48,7 @@ class VoteController extends EmailsController {
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
$poll_custom_url = $data['poll_custom_url'];
|
||||
$poll_custom_url = $data[ 'poll_custom_url' ];
|
||||
|
||||
/***
|
||||
* checks before persisting
|
||||
@ -125,7 +127,7 @@ class VoteController extends EmailsController {
|
||||
$this->sendVoteNotificationAction( $newStack->getOwner(), $newStack );
|
||||
}
|
||||
|
||||
return $this->json( $newStack->displayForAdmin() );
|
||||
return $this->json( $newStack->displayForAdmin() );
|
||||
|
||||
}
|
||||
|
||||
@ -136,6 +138,7 @@ class VoteController extends EmailsController {
|
||||
* name = "update_vote_stack",
|
||||
* methods={"PATCH","OPTIONS"}
|
||||
* )
|
||||
*
|
||||
* @param SerializerInterface $serializer
|
||||
* @param StackOfVotes $id
|
||||
* @param $modifierToken
|
||||
@ -154,36 +157,99 @@ class VoteController extends EmailsController {
|
||||
if ( ! $voteStack ) {
|
||||
return $this->json( [ 'message' => 'vote stack not found' ], 404 );
|
||||
}
|
||||
$poll = $voteStack->getPoll();
|
||||
$poll = $voteStack->getPoll();
|
||||
$whocanchangeanswers = $poll->getModificationPolicy();
|
||||
|
||||
$data = $request->getContent();
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
$table_votes_by_choice_id = [];
|
||||
|
||||
if ( $whocanchangeanswers == 'everybody' ) {
|
||||
$table_votes_by_choice_id = $this->patchVotes( $voteStack, $data[ 'votes' ] );
|
||||
} else if ( $whocanchangeanswers == 'self' ) {
|
||||
// someone with the right token of this vote stack only can change this
|
||||
if ( ! $modifierToken || $voteStack->getOwner()->getModifierToken() !== $modifierToken ) {
|
||||
return $this->json( [ 'message' => 'your token does not allow you to modify this vote ' ],
|
||||
403 );
|
||||
}
|
||||
$this->patchVotes( $voteStack, $data[ 'votes' ] );
|
||||
// everything is ok, we can update all the votes of the vote stack
|
||||
} else if ( $whocanchangeanswers == 'nobody' ) {
|
||||
// only the poll admin with the poll modifier token can change this
|
||||
if ( ! $modifierToken || $poll->getOwner()->getModifierToken() !== $modifierToken ) {
|
||||
return $this->json( [ 'message' => 'your token does not allow you to modify this vote ' ],
|
||||
403 );
|
||||
}
|
||||
$this->patchVotes( $voteStack, $data[ 'votes' ] );
|
||||
}
|
||||
|
||||
|
||||
// if only self users are allowed to modify a vote, check it
|
||||
if ( ! $modifierToken || $voteStack->getOwner()->getModifierToken() !== $modifierToken ) {
|
||||
return $this->json( [ 'message' => 'your token does not allow you to modify this vote ' ],
|
||||
403 );
|
||||
}
|
||||
// everything is ok, we can update all the votes of the vote stack
|
||||
|
||||
//TODO
|
||||
// match votes and choices
|
||||
// update answers
|
||||
// save evrything
|
||||
// save everything
|
||||
|
||||
|
||||
$jsonResponse = $serializer->serialize( [
|
||||
'message' => 'ok',
|
||||
'modifier_token' => $voteStack->getOwner()->getModifierToken(),
|
||||
'vote_stack' => $voteStack,
|
||||
],
|
||||
'json' );
|
||||
$jsonResponse = $voteStack->displayForAdmin();
|
||||
|
||||
$response = new Response( $jsonResponse );
|
||||
$response->headers->set( 'Content-Type', 'application/json' );
|
||||
$response->setStatusCode( 200 );
|
||||
|
||||
return $response;
|
||||
return $this->json( $jsonResponse, 200 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function patchVotes( $stackOfVotes, $data ) {
|
||||
$table_votes_by_choice_id = [];
|
||||
$votes = $stackOfVotes->getVotes();
|
||||
$choices = $stackOfVotes->getPoll()->getChoices();
|
||||
$table_choices_by_id = [];
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
foreach ( $choices as $c ) {
|
||||
$table_choices_by_id[ $c->getId() ] = $c;
|
||||
}
|
||||
foreach ( $votes as $stack_vote ) {
|
||||
$table_votes_by_choice_id[ $stack_vote->getChoice()->getId() ] = $stack_vote;
|
||||
}
|
||||
foreach ( $data as $vote ) {
|
||||
|
||||
$newValue = $vote[ 'value' ];
|
||||
$choice_id = $vote[ 'choice_id' ];
|
||||
// if the new value is null, remove the vote
|
||||
if ( isset( $table_choices_by_id[ $choice_id ] ) ) {
|
||||
if ( isset( $table_votes_by_choice_id[ $choice_id ] ) ) {
|
||||
$voteFound = $table_votes_by_choice_id[ $choice_id ];
|
||||
if ( $newValue ) {
|
||||
$voteFound->setValue( $newValue );
|
||||
$em->persist( $voteFound );
|
||||
} else {
|
||||
$stackOfVotes->removeVote( $voteFound );
|
||||
$em->remove( $voteFound );
|
||||
}
|
||||
} else if ( $newValue ) {
|
||||
// create vote for this stack
|
||||
$newVote = new Vote();
|
||||
$newVote->setChoice( $em->find( Choice::class, $choice_id ) )
|
||||
->setValue( $newValue );
|
||||
$em->persist( $newVote );
|
||||
|
||||
$stackOfVotes->addVote( $newVote );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$em->persist( $stackOfVotes );
|
||||
$em->flush();
|
||||
|
||||
return $table_votes_by_choice_id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* path = "/{id}/token/{modifierToken}",
|
||||
@ -193,10 +259,10 @@ class VoteController extends EmailsController {
|
||||
* )
|
||||
* @param StackOfVotes $stack_of_votes
|
||||
*/
|
||||
public function deleteVoteStackAction(StackOfVotes $stack_of_votes,$modifierToken){
|
||||
public function deleteVoteStackAction( StackOfVotes $stack_of_votes, $modifierToken ) {
|
||||
if ( $modifierToken == $stack_of_votes->getOwner()->getModifierToken() ) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$id = $stack_of_votes->getId() ;
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$id = $stack_of_votes->getId();
|
||||
$em->remove( $stack_of_votes );
|
||||
$em->flush();
|
||||
|
||||
|
@ -98,6 +98,7 @@ class Owner {
|
||||
public function displayForAdmin() {
|
||||
return [
|
||||
'pseudo' => $this->getPseudo(),
|
||||
'email' => $this->getEmail(),
|
||||
'modifier_token' => $this->getModifierToken(),
|
||||
'created_at' => $this->getCreatedAtAsString(),
|
||||
];
|
||||
|
@ -26,7 +26,7 @@ class StackOfVotes {
|
||||
*/
|
||||
public $pseudo;
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", cascade={"persist","remove"})
|
||||
* @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="stacksOfVotes", orphanRemoval=true, cascade={"persist","remove"})
|
||||
* @Serializer\Expose()
|
||||
*/
|
||||
public $votes;
|
||||
@ -66,7 +66,7 @@ class StackOfVotes {
|
||||
'votes' => [],
|
||||
];
|
||||
foreach ( $this->getVotes() as $vote ) {
|
||||
$tab[ 'votes' ][ ] = $vote->display();
|
||||
$tab[ 'votes' ][] = $vote->display();
|
||||
}
|
||||
$tab[ 'owner' ] = $this->getOwner()->display();
|
||||
|
||||
@ -160,4 +160,5 @@ class StackOfVotes {
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
{
|
||||
"behat/transliterator": {
|
||||
"version": "v1.3.0"
|
||||
},
|
||||
"composer/package-versions-deprecated": {
|
||||
"version": "1.11.99.1"
|
||||
},
|
||||
@ -115,6 +118,9 @@
|
||||
"config/packages/fos_rest.yaml"
|
||||
]
|
||||
},
|
||||
"gedmo/doctrine-extensions": {
|
||||
"version": "v3.0.5"
|
||||
},
|
||||
"jms/metadata": {
|
||||
"version": "2.5.0"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user