1
0
mirror of https://framagit.org/tykayn/date-poll-api synced 2023-08-25 08:23:11 +02:00

Compare commits

..

No commits in common. "f2edaa49f00c8c74113c6ff39bb3fa3a92e031c9" and "f5a154b20ed4471a98b0497259c976580a997085" have entirely different histories.

15 changed files with 503 additions and 607 deletions

View File

@ -1,8 +0,0 @@
# config/packages/dev/mailer.yaml
framework:
mailer:
envelope:
sender: 'noreply@tktest.com'
recipients: ['tykayn@pm.me']
headers:
from: 'dev framadate funky <noreply@tktest.com>'

View File

@ -1,6 +1,6 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html # see https://symfony.com/doc/current/reference/configuration/framework.html
framework: framework:
trusted_hosts: ['localhost:4200', 'localhost', 'tktest.lan', '127.0.0.1', 'framadate-api.cipherbliss.com'] trusted_hosts: ['localhost:4200', 'localhost', 'tktest.lan', 'framadate-api.cipherbliss.com']
secret: '%env(APP_SECRET)%' secret: '%env(APP_SECRET)%'
#csrf_protection: true #csrf_protection: true
#http_method_override: true #http_method_override: true

View File

@ -1,31 +0,0 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210518212646 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE poll ADD is_zero_knowledge TINYINT(1) DEFAULT NULL');
}
public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE poll DROP is_zero_knowledge');
}
}

View File

@ -9,6 +9,7 @@ use Swift_Mailer;
use Swift_Message; use Swift_Message;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
/** /**
* sending emails controller * sending emails controller
* *

View File

@ -97,10 +97,10 @@ class MigrationController extends EmailsController {
$moments = explode( ',', $d->moments ); $moments = explode( ',', $d->moments );
foreach ( $moments as $moment ) { foreach ( $moments as $moment ) {
$newChoice = new Choice(); $newChoice = new Choice();
$dateOfDay = date_create( strtotime( $d->title ) );
$newChoice $newChoice
->setPoll( $poll ) ->setPoll( $poll )
->setName( $dateOfDay->format('y-m-d'). ' >>> ' . $moment ); ->setDateTime( date_create( strtotime( $d->title ) ) )
->setName( $moment );
$pollChoicesOrderedBySlug[ $pollSlug ][] = $newChoice; $pollChoicesOrderedBySlug[ $pollSlug ][] = $newChoice;
$poll->addChoice( $newChoice ); $poll->addChoice( $newChoice );

View File

@ -240,17 +240,9 @@ class PollController extends EmailsController {
$data = $request->getContent(); $data = $request->getContent();
$data = json_decode( $data, true ); $data = json_decode( $data, true );
// search for existing custom url, which must be unique
$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 );
}
$newpoll = new Poll(); $newpoll = new Poll();
$newpoll $newpoll
->setModificationPolicy( isset( $data[ 'modification_policy' ] ) ? $data[ 'modification_policy' ] : 'everybody' ) ->setModificationPolicy( $data[ 'modification_policy' ] )
->setTitle( $data[ 'title' ] ) ->setTitle( $data[ 'title' ] )
->setKind( $data[ 'kind' ] ) ->setKind( $data[ 'kind' ] )
->setCustomUrl( $data[ 'custom_url' ] ); ->setCustomUrl( $data[ 'custom_url' ] );
@ -302,18 +294,17 @@ class PollController extends EmailsController {
if ( $data[ 'password' ] ) { if ( $data[ 'password' ] ) {
$newpoll->setPassword( $data[ 'password' ] ); $newpoll->setPassword( $data[ 'password' ] );
} }
// manage choices
// text kind of answers, dates are below // text kind of answers, dates are below
if ( $data[ 'kind' ] == 'text' ) { if ( $data[ 'kind' ] == 'text' ) {
// manage choices
$choices = $data[ 'choices' ]; $choices = $data[ 'dateChoices' ];
foreach ( $choices as $c ) { foreach ( $choices as $c ) {
$newChoice = new Choice(); $newChoice = new Choice();
$newChoice $newChoice
->setPoll( $newpoll ) ->setPoll( $newpoll )
->setName( $c[ 'literal' ] ); ->setName( $c[ 'literal' ] );
$em->persist( $newChoice ); $em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
} }
} // date kind of poll } // date kind of poll
elseif ( $data[ 'kind' ] == 'date' ) { elseif ( $data[ 'kind' ] == 'date' ) {
@ -325,7 +316,7 @@ class PollController extends EmailsController {
foreach ( $choices as $c ) { foreach ( $choices as $c ) {
$currentDate = $c[ 'literal' ]; $currentDate = $c[ 'literal' ];
$timeSlicesOfThisChoice = $c[ 'timeSlices' ]; $timeSlicesOfThisChoice = $c[ 'timeList' ];
foreach ( $timeSlicesOfThisChoice as $t ) { foreach ( $timeSlicesOfThisChoice as $t ) {
$newChoice = new Choice(); $newChoice = new Choice();
@ -333,16 +324,14 @@ class PollController extends EmailsController {
->setPoll( $newpoll ) ->setPoll( $newpoll )
->setName( $currentDate . ' >>> ' . $t[ 'literal' ] ); ->setName( $currentDate . ' >>> ' . $t[ 'literal' ] );
$em->persist( $newChoice ); $em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
} }
} }
} else { } else {
// all choices will be having the same time slices from timeSlices // all choices will be having the same time slices from timeSlices
$timeSlicesForAllChoices = $data[ 'timeSlices' ]; $timeSlicesForAllChoices = $data[ 'timeSlices' ];
foreach ( $choices as $c ) { foreach ( $choices as $c ) {
$currentDate = $c[ 'date_object' ]; $currentDate = $c[ 'literal' ];
foreach ( $timeSlicesForAllChoices as $t ) { foreach ( $timeSlicesForAllChoices as $t ) {
@ -351,7 +340,6 @@ class PollController extends EmailsController {
->setPoll( $newpoll ) ->setPoll( $newpoll )
->setName( $currentDate . ' >>> ' . $t[ 'literal' ] ); ->setName( $currentDate . ' >>> ' . $t[ 'literal' ] );
$em->persist( $newChoice ); $em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
} }
@ -359,6 +347,7 @@ class PollController extends EmailsController {
} }
} }
$em->persist( $newpoll ); $em->persist( $newpoll );
@ -370,11 +359,8 @@ class PollController extends EmailsController {
$this->sendCreationMailAction( $foundOwner, $newpoll ); $this->sendCreationMailAction( $foundOwner, $newpoll );
$newChoices = $newpoll->display()[ 'choices' ];
return $this->json( [ return $this->json( [
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . $precision, 'message' => 'you created a poll ' . $precision,
'id' => $newpoll->getId(),
'poll' => $newpoll->displayForAdmin(), 'poll' => $newpoll->displayForAdmin(),
'password_protected' => is_string( $newpoll->getPassword() ), 'password_protected' => is_string( $newpoll->getPassword() ),
@ -402,34 +388,19 @@ class PollController extends EmailsController {
public function testSendCreationMailAction( public function testSendCreationMailAction(
$emailChoice = 'tktest_commentateur@tktest.com' $emailChoice = 'tktest_commentateur@tktest.com'
) { ) {
$em = $this->getDoctrine()->getRepository( Poll::class );
$foundPoll = $em->findOneByCustomUrl( 'dessin-anime' );
$em = $this->getDoctrine()->getRepository( Owner::class ); $em = $this->getDoctrine()->getRepository( Owner::class );
$foundOwner = $em->findOneByEmail( $emailChoice ); $foundOwner = $em->findOneByEmail( $emailChoice );
if ( $foundOwner ) {
$poll = $foundOwner->getPolls()[ 0 ];
$comment = $foundOwner->getComments()[ 0 ];
return $this->render( 'emails/creation-mail.html.twig', $sent = $this->sendOwnerPollsAction( $foundOwner );
[ 'poll' => $foundPoll, 'owner' => $foundPoll->getOwner() ] ); if ( $sent ) {
return $this->json( [ "message" => "test email sent to " . $foundOwner->getEmail() . "!" ], 200 );
}
}
return $this->json( [ "message" => "user with this email was not found" ], 400 );
// if ( $foundOwner ) {
// $sent = $this->sendOwnerPollsAction( $foundOwner );
// if ( $sent ) {
// $config = [
// 'owner' => $foundOwner,
// 'title' => $this->getParameter( 'WEBSITE_NAME' ) . ' | Mes sondages',
// 'email_template' => 'emails/owner-list.html.twig',
// ];
// return $this->render( 'emails/owner-list.html.twig', $config );
// }
// }
// return $this->json( [ "message" => "test email sent to " . $foundOwner->getEmail() . "!" ], 200 );
// $this->sendMailWithVars( $config );
// return $this->json( [ "message" => "user with this email was not found" ], 400 );
} }

View File

@ -47,22 +47,14 @@ class VoteController extends EmailsController {
) { ) {
/***
* checks before persisting
*/
$em = $this->getDoctrine()->getManager(); $em = $this->getDoctrine()->getManager();
$emPol = $em->getRepository( Poll::class ); $emPol = $em->getRepository( Poll::class );
$poll = $emPol->findOneByCustomUrl( $custom_url ); $poll = $emPol->findOneByCustomUrl( $custom_url );
// check : existence of poll
if ( ! $poll ) { if ( ! $poll ) {
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 ); return $this->json( [ 'message' => 'poll "' . $custom_url . '" not found' ], 404 );
} }
// check : limit of number of participation max
if ( count( $poll->getStacksOfVotes() ) == $poll->getVotesMax() ) {
return $this->json( [ 'message' => 'poll "' . $custom_url . '" not allowed to have more stack of votes than ' . $poll->getVotesMax() ],
403 );
}
$data = $request->getContent(); $data = $request->getContent();
$data = json_decode( $data, true ); $data = json_decode( $data, true );
@ -71,7 +63,9 @@ class VoteController extends EmailsController {
$owner = new Owner(); $owner = new Owner();
$owner $owner
->addPoll( $poll ); ->addPoll( $poll )
;
$newStack = new StackOfVotes(); $newStack = new StackOfVotes();
$newStack $newStack
->setPoll($poll) ->setPoll($poll)

View File

@ -85,15 +85,6 @@ class Poll {
* @Serializer\Expose() * @Serializer\Expose()
*/ */
public $votesAllowed = true; public $votesAllowed = true;
/**
* people can add votes
* @ORM\Column(type="boolean", nullable=true)
* @Serializer\Type("boolean")
* @Serializer\Expose()
*/
public $isZeroKnowledge ;
/** /**
* max number of stack of votes possible. * max number of stack of votes possible.
* limits the number of people who can answer. as long as you trust the people to give only one answer with a reliable system. * limits the number of people who can answer. as long as you trust the people to give only one answer with a reliable system.
@ -771,18 +762,6 @@ class Poll {
public function setCommentsAllowed( ?bool $commentsAllowed ): self { public function setCommentsAllowed( ?bool $commentsAllowed ): self {
$this->commentsAllowed = $commentsAllowed; $this->commentsAllowed = $commentsAllowed;
return $this;
}
public function getIsZeroKnowledge(): ?bool
{
return $this->isZeroKnowledge;
}
public function setIsZeroKnowledge(?bool $isZeroKnowledge): self
{
$this->isZeroKnowledge = $isZeroKnowledge;
return $this; return $this;
} }
} }

View File

@ -9,9 +9,9 @@
<header> <header>
{% block title %} {% block title %}
{% if title is defined %} {% if title is defined %}
<h1 class="text-center">{{ title }}</h1> <h1>{{ title }}</h1>
{% else %} {% else %}
<h1 class="text-center">Framadate</h1> <h1>Framadate - email</h1>
{% endif %} {% endif %}
<hr> <hr>
{% endblock %} {% endblock %}
@ -30,9 +30,6 @@
</div> </div>
<style type="text/css"> <style type="text/css">
.text-center{
text-align:center;
}
html, body, main, header, footer, div { html, body, main, header, footer, div {
font-family: "Open Sans", "Helvetica Neue", sans-serif; font-family: "Open Sans", "Helvetica Neue", sans-serif;
} }

View File

@ -2,12 +2,12 @@
{% extends 'email-base.html.twig' %} {% extends 'email-base.html.twig' %}
{% block content %} {% block content %}
<h1>✨ Création de votre sondage {{ poll.title }} </h1>
Suite à la création de votre sondage <strong>{{ poll.title }}</strong> vous recevez deux emails afin de ne pas transmettre par erreur aux sondés le lien d'administration de votre sondage. Suite à la création de votre sondage {{ title }} vous recevez deux emails afin de ne pas transmettre par erreur aux sondés le lien d'administration de votre sondage.
<br> <br>
Ce mail est le premier, comportant le message qui doit être envoyé aux sondés.<br> Ce mail est le premier, comportant le message qui doit être envoyé aux sondés.<br>
Vous pouvez maintenant transmettre ce message à toutes les personnes susceptibles de participer au vote. ✔️ <br> Vous pouvez maintenant transmettre ce message à toutes les personnes susceptibles de participer au vote.<br>
<br> <br>
<fieldset> <fieldset>
@ -15,7 +15,7 @@
<blockquote> <blockquote>
<i> <i>
💡 {{ owner.pseudo }} ( {{ owner.email }} ) vient de créer un sondage intitulé : " <strong>{{ poll.title }} {{ owner.pseudo }} ( {{ owner.email }} ) vient de créer un sondage intitulé : " <strong>{{ title }}
"</strong>. "</strong>.
<br> <br>
<br> <br>

View File

@ -3,17 +3,13 @@
{% block content %} {% block content %}
<h1> 🎌 Votre sondage {{ poll.title }} va bientôt expirer dans 1 jour,</h1> Ce sondage va bientôt expirer dans 1 jour, <br>
<blockquote> <blockquote>
le {{ poll.expiracyDate | date('D Y-m-d') }} : le {{ poll.expiracyDate | date('D Y-m-d') }}
</blockquote> </blockquote>
il ne sera plus possible d'y voter. <br> il ne sera plus possible d'y voter. <br>
Dans 31 jours il sera supprimé.<br> Dans 31 jours il sera supprimé.<br>
Vous pouvez exporter ses données à tout moment en vous rendant à ce lien pour l'administrer: Vous pouvez exporter ses données à tout moment en vous rendant à ce lien pour l'administrer:
<br> <br>
{% include 'emails/partial/admin_link.html.twig' %} {% include 'emails/partial/admin_link.html.twig' %}
<hr>
Plus de détails sur votre sondage :
{% include 'emails/partial/poll.html.twig' %}
{% endblock %} {% endblock %}

View File

@ -13,10 +13,10 @@
<a href="https://framagit.org/framasoft/framadate/funky-framadate-front"> <a href="https://framagit.org/framasoft/framadate/funky-framadate-front">
Sources du client Front end, Sources du client Front end,
</a> </a>
<a href="https://framagit.org/tykayn/date-poll-api"> <a href="https://framagit.org/framasoft/framadate/framadate">
API back end. API back end.
</a> </a>
<a href="https://framagit.org/framasoft/framadate/funky-framadate-front/docs"> <a href="https://framagit.org/framasoft/framadate/funky-framadate-front/-/wikis/home">
Documentation Documentation
</a> </a>

View File

@ -1 +1,2 @@
<a href="{{ BASE_URL }}/#/poll/{{ poll.customUrl }}/admin/{{ poll.adminKey }}">{{ BASE_URL }}/#/poll/{{ poll.customUrl }}/admin/{{ poll.adminKey }}</a> <a href="{{ BASE_URL }}/#/poll/{{ poll.id }}/admin/{{ poll.adminKey }}">{{ BASE_URL }}
/admin/{{ poll.adminKey }}</a>

View File

@ -2,9 +2,11 @@
<h1> <h1>
Sondage {{ poll.title }} Sondage {{ poll.title }}
</h1> </h1>
<br> <br>
<div class="creation"> <div class="creation">
créé le {{ poll.createdAt| date('Y m d ') }} créé le {{ poll.creationDate| date('Y m d ') }}
</div> </div>
<div class="creation"> <div class="creation">
expirera le {{ poll.expiracyDate| date('Y m d ') }} expirera le {{ poll.expiracyDate| date('Y m d ') }}
@ -16,29 +18,22 @@
{{ poll.comments |length }} commentaires {{ poll.comments |length }} commentaires
</span> </span>
{% if poll.password |length %} {% if poll.password |length %}
<div class="protected"> (accès avec mot de passe)
🔐 (accès avec mot de passe)
</div>
{% else %}
{% endif %}
{% if poll.isZeroKnowledge |length %}
<div class="protected-zero-knoledge">
🔐 Ce sondage bénéficie du chiffrement Zéro knowledge, nos administrateurs ne sont pas en mesure de connaître les informations du sondage.
</div>
{% else %} {% else %}
{% endif %} {% endif %}
<br> <br>
<div class="public"> <div class="public">
<div> <span>
lien à donner aux votants: lien à donner aux votants:
</div> </span>
{% include 'emails/partial/public_link.html.twig' %} {% include 'emails/partial/public_link.html.twig' %}
</div> </div>
<div class="admin"> <div class="admin">
<div> <span>
administration: administration:
</div> </span>
{% include 'emails/partial/admin_link.html.twig' %} {% include 'emails/partial/admin_link.html.twig' %}
</div> </div>
</div> </div>

View File

@ -1,10 +1,11 @@
<span class="public-link"> <span class="public-link">
{% if poll.customUrl |length %} {% if poll.customUrl |length %}
<a href="{{ BASE_URL }}/#/poll/{{ poll.customUrl }}/consultation"> <a href="{{ BASE_URL }}/#/vote/poll/key/{{ poll.customUrl }}">
{{ BASE_URL }}/#/vote/poll/key/{{ poll.customUrl }}
✉️ {{ BASE_URL }}/#/poll/{{ poll.customUrl }}/consultation
</a> </a>
{% else %} {% else %}
erreur, il manque la customUrl de ce sondage. <a href="{{ BASE_URL }}/#/vote/poll/id/{{ poll.id }}">
{{ BASE_URL }}/#/vote/poll/id/{{ poll.id }}
</a>
{% endif %} {% endif %}
</span> </span>