Compare commits
5 Commits
9414951370
...
9cfb974c27
Author | SHA1 | Date |
---|---|---|
Tykayn | 9cfb974c27 | |
Tykayn | e488b76a2d | |
Tykayn | 110ef9fc7a | |
Tykayn | 38fdbf8e85 | |
Tykayn | 46d6d21c6b |
|
@ -40,4 +40,5 @@ public/*
|
|||
###< symfony/phpunit-bridge ###
|
||||
|
||||
node_modules
|
||||
funky-framadate-front/*
|
||||
funky-framadate-front
|
|
@ -28,20 +28,22 @@ https://framagit.org/framasoft/framadate/funky-framadate-front
|
|||
user_homepageget_default GET ANY ANY /user/
|
||||
user_homepage_polls_send_by_email GET ANY ANY /user/{email}/polls/send-by-email
|
||||
poll_index GET ANY ANY /poll/
|
||||
poll_new GET|POST ANY ANY /poll/new
|
||||
poll_show GET ANY ANY /poll/{id}
|
||||
poll_new POST ANY ANY /poll/new
|
||||
poll_show GET ANY ANY /poll/id/{id}
|
||||
poll_edit GET|POST ANY ANY /poll/{id}/edit
|
||||
poll_delete DELETE ANY ANY /poll/{id}
|
||||
api_get_poll_comment GET ANY ANY /api/v1/comment/poll/{id}/comments
|
||||
api_new_comment POST ANY ANY /api/v1/comment/poll/{id}/comment
|
||||
api_poll_comments_delete DELETE ANY ANY /api/v1/comment/poll/{id}/comments
|
||||
api_essai GET ANY ANY /api/v1/poll/essai
|
||||
api_get_all_polls GET ANY ANY /api/v1/poll/
|
||||
api_get_poll GET ANY ANY /api/v1/poll/{customUrl}
|
||||
api_get_owner_poll GET ANY ANY /api/v1/poll/owner/{owner_email}/
|
||||
api_get_protected_poll GET ANY ANY /api/v1/poll/{customUrl}/pass/{md5}
|
||||
api_get_admin_poll GET ANY ANY /api/v1/polladmin/{admin_key}
|
||||
api_update_poll PUT ANY ANY /api/v1/poll/{customUrl}/update/{token}
|
||||
api_new_poll POST ANY ANY /api/v1/poll/
|
||||
api_app_api_v1_poll_newpoll POST ANY ANY /api/v1/poll/
|
||||
api_app_api_v1_poll_newpoll.1 POST ANY ANY /api/v1/poll_new_poll
|
||||
api_test-mail-poll GET ANY ANY /api/v1/poll/mail/test-mail-poll/{emailChoice}
|
||||
api_poll_delete DELETE ANY ANY /api/v1/poll/{admin_key}
|
||||
api_check_slug_is_unique GET ANY ANY /api/v1/poll/slug/{customUrl}
|
||||
|
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 147 KiB |
|
@ -6,6 +6,7 @@ use App\Entity\Poll;
|
|||
use App\Form\PollType;
|
||||
use App\Repository\PollRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -34,7 +35,7 @@ class PollController extends AbstractController {
|
|||
}
|
||||
|
||||
/**
|
||||
* @Route("/new", name="poll_new", methods={"GET","POST"})
|
||||
* @Route("/new", name="poll_new", methods={"POST"})
|
||||
*/
|
||||
public function new( Request $request ): Response {
|
||||
$poll = new Poll();
|
||||
|
@ -58,7 +59,7 @@ class PollController extends AbstractController {
|
|||
|
||||
/**
|
||||
* on cherche un sondage par son url personnalisée
|
||||
* @Route("/{id}", name="poll_show", methods={"GET"})
|
||||
* @Route("/id/{id}", name="poll_show", methods={"GET"})
|
||||
*/
|
||||
public function show( $id ): Response {
|
||||
$repository = $this->getDoctrine()->getRepository( Poll::class );
|
||||
|
|
|
@ -10,7 +10,6 @@ use App\Repository\PollRepository;
|
|||
use DateTime;
|
||||
use FOS\RestBundle\Controller\Annotations\Delete;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Post;
|
||||
use FOS\RestBundle\Controller\Annotations\Put;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
|
@ -25,14 +24,33 @@ use Symfony\Component\HttpFoundation\Response;
|
|||
* @package App\Controller
|
||||
* @Route("/api/v1/poll",name="api_")
|
||||
*/
|
||||
class PollController extends EmailsController {
|
||||
class PollController extends EmailsController
|
||||
{
|
||||
/**
|
||||
* @Route(
|
||||
* "/essai",
|
||||
* name = "essai",
|
||||
* methods={"GET"}
|
||||
* )
|
||||
* @param Request $request
|
||||
* essai poll
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function essai(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->getContent();
|
||||
$data = json_decode($data, true);
|
||||
return $this->json(["message" => 'essai', 'data' => $data], 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get(
|
||||
* path = "/",
|
||||
* name = "get_all_polls"
|
||||
* )
|
||||
*/
|
||||
public function getAllPollsAction( PollRepository $pollRepository ): Response {
|
||||
public function getAllPollsAction(PollRepository $pollRepository): Response
|
||||
{
|
||||
$data = $pollRepository->findAll();
|
||||
|
||||
|
||||
|
@ -62,7 +80,7 @@ class PollController extends EmailsController {
|
|||
}
|
||||
|
||||
/**
|
||||
* get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
|
||||
* get a poll config by its public custom URL, we do not want polls to be reachable by their numeric id
|
||||
* @Get(
|
||||
* path = "/{customUrl}",
|
||||
* name = "get_poll"
|
||||
|
@ -77,7 +95,8 @@ class PollController extends EmailsController {
|
|||
SerializerInterface $serializer,
|
||||
$customUrl,
|
||||
Request $request
|
||||
) {
|
||||
)
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$poll = $repository->findOneByCustomUrl($customUrl);
|
||||
|
||||
|
@ -116,7 +135,8 @@ class PollController extends EmailsController {
|
|||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function notFoundPoll( $id ): Response {
|
||||
public function notFoundPoll($id): Response
|
||||
{
|
||||
return $this->json([
|
||||
'message' => $id . ' : poll not found',
|
||||
],
|
||||
|
@ -132,7 +152,8 @@ class PollController extends EmailsController {
|
|||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
function getOwnerPolls( $owner_email , LoggerInterface $logger ) {
|
||||
function getOwnerPolls($owner_email, LoggerInterface $logger)
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository(Owner::class);
|
||||
$owner = $repository->findOneByEmail($owner_email);
|
||||
if (!$owner) {
|
||||
|
@ -165,7 +186,8 @@ class PollController extends EmailsController {
|
|||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
function getProtectedPoll( $customUrl, $md5, SerializerInterface $serializer ) {
|
||||
function getProtectedPoll($customUrl, $md5, SerializerInterface $serializer)
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$poll = $repository->findOneByCustomUrl($customUrl);
|
||||
|
||||
|
@ -193,7 +215,9 @@ class PollController extends EmailsController {
|
|||
|
||||
|
||||
/**
|
||||
* as an administrator of a poll, get a poll config by its custom URL, we do not want polls to be reachable by their numeric id
|
||||
* as an administrator of a poll,
|
||||
* get a poll config by its custom URL,
|
||||
* we do not want polls to be reachable by their numeric id
|
||||
* @Get(
|
||||
* path = "admin/{admin_key}",
|
||||
* name = "get_admin_poll",
|
||||
|
@ -204,7 +228,8 @@ class PollController extends EmailsController {
|
|||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
function getAdminPoll( $admin_key, $md5, SerializerInterface $serializer ) {
|
||||
function getAdminPoll($admin_key, $md5, SerializerInterface $serializer)
|
||||
{
|
||||
$repository = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$poll = $repository->findOneByAdminKey($admin_key);
|
||||
|
||||
|
@ -224,7 +249,8 @@ class PollController extends EmailsController {
|
|||
* @param $serializer
|
||||
* @return Response
|
||||
*/
|
||||
function returnPollData( $poll, $serializer ) {
|
||||
function returnPollData($poll, $serializer)
|
||||
{
|
||||
$jsonResponse = $serializer->serialize($poll, 'json');
|
||||
|
||||
$response = new Response($jsonResponse);
|
||||
|
@ -245,7 +271,8 @@ class PollController extends EmailsController {
|
|||
Poll $poll,
|
||||
string $token,
|
||||
Request $request
|
||||
) {
|
||||
)
|
||||
{
|
||||
if ($poll->getAdminKey() !== $token) {
|
||||
return $this->json([
|
||||
'message' => 'you are NOT allowed to update the poll ' . $poll->getTitle(),
|
||||
|
@ -264,27 +291,33 @@ class PollController extends EmailsController {
|
|||
200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Post(
|
||||
* path = "/",
|
||||
* name = "new_poll",
|
||||
* requirements = {"creator"="\w+"}
|
||||
* @Route(
|
||||
* "/",
|
||||
* "_new_poll",
|
||||
* methods={"POST"}
|
||||
* )
|
||||
* @param Request $request
|
||||
* create a new poll
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function newPollAction( Request $request ) {
|
||||
public function newPoll(Request $request): JsonResponse
|
||||
{
|
||||
|
||||
$data = $request->getContent();
|
||||
$data = json_decode($data, true);
|
||||
|
||||
// search for existing custom url, which must be unique
|
||||
if (!isset($data) || !isset($data['custom_url'])) {
|
||||
return $this->json(["message" => 'NOPE, pas de data ou de custom url'], 403);
|
||||
}
|
||||
$custom_url = $data['custom_url'];
|
||||
|
||||
$repository = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$poll = $repository->findOneByCustomUrl($custom_url);
|
||||
if ($poll) {
|
||||
throw new \JsonException( 'NOPE, ce sondage existe déjà: ' . $custom_url );
|
||||
return $this->json(["message" => 'NOPE, ce sondage existe déjà: ' . $custom_url], 403);
|
||||
}
|
||||
|
||||
$newpoll = new Poll();
|
||||
|
@ -292,7 +325,7 @@ class PollController extends EmailsController {
|
|||
->setModificationPolicy(isset($data['modification_policy']) ? $data['modification_policy'] : 'everybody')
|
||||
->setTitle($data['title'])
|
||||
->setKind($data['kind'])
|
||||
->setCustomUrl( $data[ 'custom_url' ] );
|
||||
->setCustomUrl($custom_url);
|
||||
if (count($data['allowed_answers'])) {
|
||||
// TODO check this one
|
||||
$newpoll->setAllowedAnswers($data['allowed_answers']);
|
||||
|
@ -346,10 +379,11 @@ class PollController extends EmailsController {
|
|||
$newpoll->setPassword($data['password']);
|
||||
}
|
||||
|
||||
$choices_debug = '';
|
||||
// text kind of answers, dates are below
|
||||
if ($data['kind'] == 'text') {
|
||||
// manage choices
|
||||
$choices = $data[ 'choices' ];
|
||||
$choices = $data['choicesText'];
|
||||
foreach ($choices as $c) {
|
||||
$newChoice = new Choice();
|
||||
$newChoice
|
||||
|
@ -362,21 +396,33 @@ class PollController extends EmailsController {
|
|||
elseif ($data['kind'] == 'date') {
|
||||
|
||||
$choices = $data['dateChoices'];
|
||||
$choices_debug .= '\n debug count recieved' . count($choices);
|
||||
if (isset($data['hasSeveralHours']) && $data['hasSeveralHours'] == true) {
|
||||
// different hours spans make more choices
|
||||
|
||||
foreach ($choices as $c) {
|
||||
$choices_debug .= '\n c ' . $c['literal'];
|
||||
$currentDate = $c['literal'];
|
||||
|
||||
$timeSlicesOfThisChoice = $c['timeSlices'];
|
||||
foreach ( $timeSlicesOfThisChoice as $t ) {
|
||||
if (count($timeSlicesOfThisChoice)) {
|
||||
|
||||
foreach ($timeSlicesOfThisChoice as $t) {
|
||||
$choices_debug .= '\n timeSlicesOfThisChoice ' . $t['literal'];
|
||||
$newChoice = new Choice();
|
||||
$newChoice
|
||||
->setPoll($newpoll)
|
||||
->setName($currentDate . ' >>> ' . $t['literal']);
|
||||
$em->persist( $newChoice );
|
||||
$newpoll->addChoice($newChoice);
|
||||
$em->persist($newChoice);
|
||||
$em->persist($newpoll);
|
||||
}
|
||||
} else {
|
||||
$newChoice = new Choice();
|
||||
$newChoice
|
||||
->setPoll($newpoll)
|
||||
->setName($currentDate);
|
||||
$newpoll->addChoice($newChoice);
|
||||
$em->persist($newChoice);
|
||||
$em->persist($newpoll);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -413,10 +459,9 @@ class PollController extends EmailsController {
|
|||
|
||||
$this->sendCreationMailAction($foundOwner, $newpoll);
|
||||
|
||||
$newChoices = $newpoll->display()[ 'choices' ];
|
||||
|
||||
return $this->json([
|
||||
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . $precision,
|
||||
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . ' ' . $precision,
|
||||
'debug' => $choices_debug,
|
||||
'id' => $newpoll->getId(),
|
||||
'poll' => $newpoll->displayForAdmin(),
|
||||
'password_protected' => is_string($newpoll->getPassword()),
|
||||
|
@ -444,7 +489,8 @@ class PollController extends EmailsController {
|
|||
// public function sendCreationMailAction( Owner $admin_user, Poll $poll, \Swift_Mailer $mailer) {
|
||||
public function testSendCreationMailAction(
|
||||
$emailChoice = 'tktest_commentateur@tktest.com'
|
||||
) {
|
||||
)
|
||||
{
|
||||
$em = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$foundPoll = $em->findOneByCustomUrl('dessin-anime');
|
||||
$em = $this->getDoctrine()->getRepository(Owner::class);
|
||||
|
@ -470,7 +516,8 @@ class PollController extends EmailsController {
|
|||
public
|
||||
function deletePollAction(
|
||||
$admin_key
|
||||
) {
|
||||
)
|
||||
{
|
||||
|
||||
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$found = $emPoll->findOneByAdminKey($admin_key);
|
||||
|
@ -499,7 +546,8 @@ class PollController extends EmailsController {
|
|||
* name = "check_slug_is_unique",
|
||||
* )
|
||||
*/
|
||||
public function checkSlugIsUniqueAction( string $customUrl ) {
|
||||
public function checkSlugIsUniqueAction(string $customUrl)
|
||||
{
|
||||
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$found = $emPoll->findOneByCustomUrl($customUrl);
|
||||
$elaborated_message_version = false;
|
||||
|
@ -546,7 +594,8 @@ class PollController extends EmailsController {
|
|||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function getAdministrationConfig( SerializerInterface $serializer, $token ) {
|
||||
public function getAdministrationConfig(SerializerInterface $serializer, $token)
|
||||
{
|
||||
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
|
||||
$pollFound = $emPoll->findOneByAdminKey($token);
|
||||
|
||||
|
@ -584,7 +633,8 @@ class PollController extends EmailsController {
|
|||
*
|
||||
* @return JsonResponse|Response
|
||||
*/
|
||||
public function getExpiredPollsCleanup( $token ) {
|
||||
public function getExpiredPollsCleanup($token)
|
||||
{
|
||||
|
||||
if ($token !== 'superCaligistriixpirlidouciousse') {
|
||||
return $this->json([
|
||||
|
|
|
@ -306,8 +306,6 @@ class Poll
|
|||
|
||||
// handle sub time slices
|
||||
if (count($boom) == 2) {
|
||||
|
||||
|
||||
if (!isset($grouped_dates[$boom[0]])) {
|
||||
|
||||
$grouped_dates[$boom[0]] = [
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue