Compare commits

...

5 Commits

Author SHA1 Message Date
Tykayn 9cfb974c27 handle creation of mixed subset of datechoice 2022-02-10 11:02:03 +01:00
Tykayn e488b76a2d up essai 2022-02-10 10:41:31 +01:00
Tykayn 110ef9fc7a hop up script 2022-02-10 10:32:13 +01:00
Tykayn 38fdbf8e85 add essai route 2022-02-10 10:23:06 +01:00
Tykayn 46d6d21c6b up debug message in poll creation 2022-02-10 09:53:24 +01:00
109 changed files with 623 additions and 569 deletions

0
.env.test Normal file → Executable file
View File

1
.gitignore vendored
View File

@ -40,4 +40,5 @@ public/*
###< symfony/phpunit-bridge ###
node_modules
funky-framadate-front/*
funky-framadate-front

0
.gitlab-ci.yml Normal file → Executable file
View File

0
LICENSE Normal file → Executable file
View File

View File

@ -8,50 +8,52 @@ https://framagit.org/framasoft/framadate/funky-framadate-front
------------------------------------ --------------- -------- ------ --------------------------------------------------
Name Method Scheme Host Path
------------------------------------ --------------- -------- ------ --------------------------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
admin_homepage_get_default GET ANY ANY /admin/
admin_homepage_clean_expired_polls GET ANY ANY /admin/polls/clean/{token}
admin_homepage_migrate_framadate GET ANY ANY /admin/polls/migrate
home_sweet_home GET ANY ANY /
admin_homepage_migrate_from_v1 GET ANY ANY /migration-from-v1/{unique_key}
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_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_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_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}
api_get_admin_config GET ANY ANY /api/v1/poll/admin/{token}
api_clean_expired_polls GET ANY ANY /api/v1/poll/admin/clean_expired_polls/{token}
api_new_vote_stack POST|OPTIONS ANY ANY /api/v1/vote-stack/
api_update_vote_stack PATCH|OPTIONS ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken}
api_delete_vote_stack DELETE ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken}
api_poll_votes_delete DELETE ANY ANY /api/v1/vote-stack/poll/{id}/votes/{accessToken}
app.swagger GET ANY ANY /api/doc.json
_preview_error ANY ANY ANY /_error/{code}.{_format}
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
admin_homepage_get_default GET ANY ANY /admin/
admin_homepage_clean_expired_polls GET ANY ANY /admin/polls/clean/{token}
admin_homepage_migrate_framadate GET ANY ANY /admin/polls/migrate
home_sweet_home GET ANY ANY /
admin_homepage_migrate_from_v1 GET ANY ANY /migration-from-v1/{unique_key}
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 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_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}
api_get_admin_config GET ANY ANY /api/v1/poll/admin/{token}
api_clean_expired_polls GET ANY ANY /api/v1/poll/admin/clean_expired_polls/{token}
api_new_vote_stack POST|OPTIONS ANY ANY /api/v1/vote-stack/
api_update_vote_stack PATCH|OPTIONS ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken}
api_delete_vote_stack DELETE ANY ANY /api/v1/vote-stack/{id}/token/{modifierToken}
api_poll_votes_delete DELETE ANY ANY /api/v1/vote-stack/poll/{id}/votes/{accessToken}
app.swagger GET ANY ANY /api/doc.json
------------------------------------ --------------- -------- ------ --------------------------------------------------
## TODO:

0
assets/styles/app.scss Normal file → Executable file
View File

0
assets/styles/pages/_global.scss Normal file → Executable file
View File

0
assets/styles/pages/_home.scss Normal file → Executable file
View File

0
assets/styles/pages/libs.scss Normal file → Executable file
View File

0
composer-setup.php Normal file → Executable file
View File

0
composer.json Normal file → Executable file
View File

0
composer.lock generated Normal file → Executable file
View File

0
config/bundles.php Normal file → Executable file
View File

0
config/graphql/types/Apartment.types.yaml Normal file → Executable file
View File

0
config/graphql/types/Query.types.yaml Normal file → Executable file
View File

0
config/packages/cache.yaml Normal file → Executable file
View File

0
config/packages/dev/debug.yaml Normal file → Executable file
View File

0
config/packages/dev/jms_serializer.yaml Normal file → Executable file
View File

0
config/packages/dev/mailer.yaml Normal file → Executable file
View File

0
config/packages/dev/swiftmailer.yaml Normal file → Executable file
View File

0
config/packages/dev/web_profiler.yaml Normal file → Executable file
View File

0
config/packages/doctrine.yaml Normal file → Executable file
View File

0
config/packages/doctrine_migrations.yaml Normal file → Executable file
View File

0
config/packages/fos_rest.yaml Normal file → Executable file
View File

0
config/packages/framework.yaml Normal file → Executable file
View File

0
config/packages/jms_serializer.yaml Normal file → Executable file
View File

0
config/packages/mailer.yaml Normal file → Executable file
View File

0
config/packages/nelmio_api_doc.yaml Normal file → Executable file
View File

0
config/packages/nelmio_cors.yaml Normal file → Executable file
View File

0
config/packages/prod/doctrine.yaml Normal file → Executable file
View File

0
config/packages/prod/jms_serializer.yaml Normal file → Executable file
View File

0
config/packages/prod/mailer.yml Normal file → Executable file
View File

0
config/packages/prod/monolog.yaml Normal file → Executable file
View File

0
config/packages/prod/routing.yaml Normal file → Executable file
View File

0
config/packages/routing.yaml Normal file → Executable file
View File

0
config/packages/sensio_framework_extra.yaml Normal file → Executable file
View File

0
config/packages/swiftmailer.yaml Normal file → Executable file
View File

0
config/packages/test/doctrine.yaml Normal file → Executable file
View File

0
config/packages/test/framework.yaml Normal file → Executable file
View File

0
config/packages/test/swiftmailer.yaml Normal file → Executable file
View File

0
config/packages/test/twig.yaml Normal file → Executable file
View File

0
config/packages/test/web_profiler.yaml Normal file → Executable file
View File

0
config/packages/twig.yaml Normal file → Executable file
View File

0
config/preload.php Normal file → Executable file
View File

0
config/routes.yaml Normal file → Executable file
View File

0
config/routes/annotations.yaml Normal file → Executable file
View File

0
config/routes/dev/framework.yaml Normal file → Executable file
View File

0
config/routes/dev/web_profiler.yaml Normal file → Executable file
View File

0
config/routes/nelmio_api_doc.yaml Normal file → Executable file
View File

0
config/services.yaml Normal file → Executable file
View File

0
doc/SCHEMA:framadate_api.uml Normal file → Executable file
View File

0
doc/apache2/dev.conf Normal file → Executable file
View File

0
doc/apache2/dev_php_fpm.conf Normal file → Executable file
View File

0
doc/database_creation.md Normal file → Executable file
View File

0
doc/framadate_api.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 192 KiB

0
doc/framadate_api.svg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 147 KiB

After

Width:  |  Height:  |  Size: 147 KiB

0
doc/migration.md Normal file → Executable file
View File

0
doc/php-8-install.md Normal file → Executable file
View File

0
front_update.sh Normal file → Executable file
View File

0
migrations/.gitignore vendored Normal file → Executable file
View File

0
migrations/Version20210419202522.php Normal file → Executable file
View File

0
migrations/Version20210518212646.php Normal file → Executable file
View File

0
phpunit.xml.dist Normal file → Executable file
View File

0
public/index.php Normal file → Executable file
View File

0
src/Controller/.gitignore vendored Normal file → Executable file
View File

0
src/Controller/EmailsController.php Normal file → Executable file
View File

5
src/Controller/PollController.php Normal file → Executable file
View File

@ -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 );

0
src/Controller/api/v1/CommentController.php Normal file → Executable file
View File

440
src/Controller/api/v1/PollController.php Normal file → Executable file
View File

@ -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();
@ -41,28 +59,28 @@ class PollController extends EmailsController {
$pollData = [
'message' => 'here are your polls',
'count' => count( $polls ),
'count' => count($polls),
];
$debug = 1;
if ( $debug ) {
foreach ( $polls as $poll ) {
if ($debug) {
foreach ($polls as $poll) {
$titles[] = [
'title' => $poll->getTitle(),
'slug' => $poll->getCustomUrl(),
];
}
$pollData[ 'polls' ] = $titles;
$pollData['polls'] = $titles;
}
return $this->json( $pollData );
return $this->json($pollData);
}
/**
* 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,12 +95,13 @@ class PollController extends EmailsController {
SerializerInterface $serializer,
$customUrl,
Request $request
) {
$repository = $this->getDoctrine()->getRepository( Poll::class );
$poll = $repository->findOneByCustomUrl( $customUrl );
)
{
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByCustomUrl($customUrl);
if ( ! $poll ) {
return $this->notFoundPoll( $customUrl );
if (!$poll) {
return $this->notFoundPoll($customUrl);
}
$comments = $poll->getComments();
@ -95,17 +114,17 @@ class PollController extends EmailsController {
/**
* password protected content
*/
if ( $pass ) {
if ($pass) {
// no password possibly given by this route
return $this->json( [
return $this->json([
'message' => 'this is protected by a password,but you did not provide the encoded password parameter, and you should feel bad. ',
],
403 );
403);
} else {
// free access to poll
$pollResult = $poll->display();
return $this->json( $pollResult );
return $this->json($pollResult);
}
}
@ -116,11 +135,12 @@ class PollController extends EmailsController {
*
* @return JsonResponse
*/
public function notFoundPoll( $id ): Response {
return $this->json( [
public function notFoundPoll($id): Response
{
return $this->json([
'message' => $id . ' : poll not found',
],
404 );
404);
}
/**
@ -132,22 +152,23 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
function getOwnerPolls( $owner_email , LoggerInterface $logger ) {
$repository = $this->getDoctrine()->getRepository( Owner::class );
$owner = $repository->findOneByEmail( $owner_email );
if ( ! $owner ) {
return $this->json( [ 'message' => "Owner $owner_email non trouvé" ], 404 );
function getOwnerPolls($owner_email, LoggerInterface $logger)
{
$repository = $this->getDoctrine()->getRepository(Owner::class);
$owner = $repository->findOneByEmail($owner_email);
if (!$owner) {
return $this->json(['message' => "Owner $owner_email non trouvé"], 404);
} else {
$polls = $owner->getPolls();
$pollsDisplay = [];
foreach ( $polls as $p ) {
foreach ($polls as $p) {
$pollsDisplay[] = $p->displayForAdmin();
}
$mail_sent = $this->sendOwnerPollsAction( $owner );
$logger->info('getOwnerPolls : Email sent : '.$mail_sent);
return $this->json( [ 'mail_sent' => $mail_sent ], $mail_sent ? 200 : 404 );
$mail_sent = $this->sendOwnerPollsAction($owner);
$logger->info('getOwnerPolls : Email sent : ' . $mail_sent);
return $this->json(['mail_sent' => $mail_sent], $mail_sent ? 200 : 404);
// return $this->json(['owner' => $owner->displayForAdmin(), 'polls' => $pollsDisplay], 200);
}
@ -165,27 +186,28 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
function getProtectedPoll( $customUrl, $md5, SerializerInterface $serializer ) {
$repository = $this->getDoctrine()->getRepository( Poll::class );
$poll = $repository->findOneByCustomUrl( $customUrl );
function getProtectedPoll($customUrl, $md5, SerializerInterface $serializer)
{
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByCustomUrl($customUrl);
if ( ! $poll ) {
return $this->notFoundPoll( $customUrl );
if (!$poll) {
return $this->notFoundPoll($customUrl);
}
if ( md5( $poll->getPassword() ) === $md5 ) {
if (md5($poll->getPassword()) === $md5) {
// good matching pass
return $this->json( $poll->display() );
return $this->json($poll->display());
} else {
// wrong pass
return $this->json( [
return $this->json([
'message' => 'this is protected by a password, your password hash "' . $md5 . '" is wrong, and you should feel bad',
'pass' => $md5 ,
'md5' => md5( $md5 ),
'md5( $poll->getPassword() )' => md5( $poll->getPassword() ),
'pass' => $md5,
'md5' => md5($md5),
'md5( $poll->getPassword() )' => md5($poll->getPassword()),
'data' => null,
],
403 );
403);
}
@ -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,16 +228,17 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
function getAdminPoll( $admin_key, $md5, SerializerInterface $serializer ) {
$repository = $this->getDoctrine()->getRepository( Poll::class );
$poll = $repository->findOneByAdminKey( $admin_key );
function getAdminPoll($admin_key, $md5, SerializerInterface $serializer)
{
$repository = $this->getDoctrine()->getRepository(Poll::class);
$poll = $repository->findOneByAdminKey($admin_key);
if ( ! $poll ) {
return $this->notFoundPoll( $admin_key );
if (!$poll) {
return $this->notFoundPoll($admin_key);
}
// good matching pass
return $this->json( $poll->displayForAdmin() );
return $this->json($poll->displayForAdmin());
}
@ -224,12 +249,13 @@ class PollController extends EmailsController {
* @param $serializer
* @return Response
*/
function returnPollData( $poll, $serializer ) {
$jsonResponse = $serializer->serialize( $poll, 'json' );
function returnPollData($poll, $serializer)
{
$jsonResponse = $serializer->serialize($poll, 'json');
$response = new Response( $jsonResponse );
$response->headers->set( 'Content-Type', 'application/json' );
$response->setStatusCode( 200 );
$response = new Response($jsonResponse);
$response->headers->set('Content-Type', 'application/json');
$response->setStatusCode(200);
return $response;
}
@ -245,156 +271,176 @@ class PollController extends EmailsController {
Poll $poll,
string $token,
Request $request
) {
if ( $poll->getAdminKey() !== $token ) {
return $this->json( [
)
{
if ($poll->getAdminKey() !== $token) {
return $this->json([
'message' => 'you are NOT allowed to update the poll ' . $poll->getTitle(),
],
403 );
403);
}
// TODO check validity of request
// update only if we have the admin key
$em = $this->getDoctrine()->getManager();
$em->persist( $poll );
$em->persist($poll);
$em->flush();
return $this->json( $poll->displayForAdmin()
return $this->json($poll->displayForAdmin()
,
200 );
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 );
$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 );
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) {
return $this->json(["message" => 'NOPE, ce sondage existe déjà: ' . $custom_url], 403);
}
$newpoll = new Poll();
$newpoll
->setModificationPolicy( isset( $data[ 'modification_policy' ] ) ? $data[ 'modification_policy' ] : 'everybody' )
->setTitle( $data[ 'title' ] )
->setKind( $data[ 'kind' ] )
->setCustomUrl( $data[ 'custom_url' ] );
if ( count( $data[ 'allowed_answers' ] ) ) {
->setModificationPolicy(isset($data['modification_policy']) ? $data['modification_policy'] : 'everybody')
->setTitle($data['title'])
->setKind($data['kind'])
->setCustomUrl($custom_url);
if (count($data['allowed_answers'])) {
// TODO check this one
$newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] );
$newpoll->setAllowedAnswers($data['allowed_answers']);
}
// define a maximum expiration
$expiracyCalculated = min($newpoll->addDaysToDate( new DateTime(),
$data[ 'default_expiracy_days_from_now' ] ), $newpoll->addDaysToDate( new DateTime(),
360 ));
$expiracyCalculated = min($newpoll->addDaysToDate(new DateTime(),
$data['default_expiracy_days_from_now']), $newpoll->addDaysToDate(new DateTime(),
360));
$newpoll->setExpiracyDate( $expiracyCalculated );
$emOwner = $this->getDoctrine()->getRepository( Owner::class );
$foundOwner = $emOwner->findOneByEmail( $data[ 'owner' ][ 'email' ] );
$newpoll->setExpiracyDate($expiracyCalculated);
$emOwner = $this->getDoctrine()->getRepository(Owner::class);
$foundOwner = $emOwner->findOneByEmail($data['owner']['email']);
$userWasFound = false;
if ( ! $foundOwner ) {
if (!$foundOwner) {
//create a new owner
$owner = new Owner();
$owner->setPseudo( $data[ 'owner' ][ 'pseudo' ] );
$owner->setEmail( $data[ 'owner' ][ 'email' ] );
$owner->setPseudo($data['owner']['pseudo']);
$owner->setEmail($data['owner']['email']);
$foundOwner = $owner;
} else {
$userWasFound = true;
}
// link the owner and the poll
$newpoll->setOwner( $foundOwner );
$foundOwner->addPoll( $newpoll );
$newpoll->setOwner($foundOwner);
$foundOwner->addPoll($newpoll);
$em = $this->getDoctrine()->getManager();
$em->persist( $newpoll );
$em->persist( $foundOwner );
$em->persist($newpoll);
$em->persist($foundOwner);
// emails
$newpoll->setMailOnComment( true );
$newpoll->setMailOnVote( $data[ 'isOwnerNotifiedByEmailOnNewVote' ] );
$newpoll->setMailOnComment( $data[ 'isOwnerNotifiedByEmailOnNewComment' ] );
$newpoll->setMailOnComment(true);
$newpoll->setMailOnVote($data['isOwnerNotifiedByEmailOnNewVote']);
$newpoll->setMailOnComment($data['isOwnerNotifiedByEmailOnNewComment']);
$newpoll->setIsZeroKnowledge( $data[ 'is_zero_knowledge' ] );
$newpoll->setDescription( $data[ 'description' ] );
$newpoll->setHideResults( $data[ 'hideResults' ] );
$newpoll->setIsZeroKnowledge($data['is_zero_knowledge']);
$newpoll->setDescription($data['description']);
$newpoll->setHideResults($data['hideResults']);
// possible answers
$newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] );
$newpoll->setVotesMax( $data[ 'maxCountOfAnswers' ] );
$newpoll->setCommentsAllowed( $data[ 'allowComments' ] );
$newpoll->setAllowedAnswers($data['allowed_answers']);
$newpoll->setVotesMax($data['maxCountOfAnswers']);
$newpoll->setCommentsAllowed($data['allowComments']);
// setup the password, converting the raw with md5 hash
if ( $data[ 'password' ] ) {
$newpoll->setPassword( $data[ 'password' ] );
if ($data['password']) {
$newpoll->setPassword($data['password']);
}
$choices_debug = '';
// text kind of answers, dates are below
if ( $data[ 'kind' ] == 'text' ) {
if ($data['kind'] == 'text') {
// manage choices
$choices = $data[ 'choices' ];
foreach ( $choices as $c ) {
$choices = $data['choicesText'];
foreach ($choices as $c) {
$newChoice = new Choice();
$newChoice
->setPoll( $newpoll )
->setName( $c[ 'literal' ] );
$em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
->setPoll($newpoll)
->setName($c['literal']);
$em->persist($newChoice);
$newpoll->addChoice($newChoice);
}
} // date kind of poll
elseif ( $data[ 'kind' ] == 'date' ) {
elseif ($data['kind'] == 'date') {
$choices = $data[ 'dateChoices' ];
if ( isset( $data[ 'hasSeveralHours' ] ) && $data[ 'hasSeveralHours' ] == true ) {
$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'];
if (count($timeSlicesOfThisChoice)) {
foreach ( $choices as $c ) {
$currentDate = $c[ 'literal' ];
$timeSlicesOfThisChoice = $c[ 'timeSlices' ];
foreach ( $timeSlicesOfThisChoice as $t ) {
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 );
->setPoll($newpoll)
->setName($currentDate . ' >>> ' . $t['literal']);
$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);
}
}
} else {
// all choices will be having the same time slices from timeSlices
$timeSlicesForAllChoices = $data[ 'timeSlices' ];
foreach ( $choices as $c ) {
$currentDate = $c[ 'date_object' ];
$timeSlicesForAllChoices = $data['timeSlices'];
foreach ($choices as $c) {
$currentDate = $c['date_object'];
foreach ( $timeSlicesForAllChoices as $t ) {
foreach ($timeSlicesForAllChoices as $t) {
$newChoice = new Choice();
$newChoice
->setPoll( $newpoll )
->setName( $currentDate . ' >>> ' . $t[ 'literal' ] );
$em->persist( $newChoice );
$newpoll->addChoice( $newChoice );
->setPoll($newpoll)
->setName($currentDate . ' >>> ' . $t['literal']);
$em->persist($newChoice);
$newpoll->addChoice($newChoice);
}
@ -404,25 +450,24 @@ class PollController extends EmailsController {
}
$em->persist( $newpoll );
$em->persist($newpoll);
$em->flush();
$precision = '';
if ( $userWasFound ) {
if ($userWasFound) {
$precision = 'from an existing user : ' . $foundOwner->getEmail();
}
$this->sendCreationMailAction( $foundOwner, $newpoll );
$this->sendCreationMailAction($foundOwner, $newpoll);
$newChoices = $newpoll->display()[ 'choices' ];
return $this->json( [
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . $precision,
return $this->json([
'message' => 'you created the poll ' . $newpoll->getCustomUrl() . ' ' . $precision,
'debug' => $choices_debug,
'id' => $newpoll->getId(),
'poll' => $newpoll->displayForAdmin(),
'password_protected' => is_string( $newpoll->getPassword() ),
'password_protected' => is_string($newpoll->getPassword()),
],
201 );
201);
}
@ -444,14 +489,15 @@ 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 );
$foundOwner = $em->findOneByEmail( $emailChoice );
)
{
$em = $this->getDoctrine()->getRepository(Poll::class);
$foundPoll = $em->findOneByCustomUrl('dessin-anime');
$em = $this->getDoctrine()->getRepository(Owner::class);
$foundOwner = $em->findOneByEmail($emailChoice);
return $this->render( 'emails/creation-mail.html.twig',
[ 'poll' => $foundPoll, 'owner' => $foundPoll->getOwner() ] );
return $this->render('emails/creation-mail.html.twig',
['poll' => $foundPoll, 'owner' => $foundPoll->getOwner()]);
}
@ -470,24 +516,25 @@ class PollController extends EmailsController {
public
function deletePollAction(
$admin_key
) {
)
{
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
$found = $emPoll->findOneByAdminKey( $admin_key );
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
$found = $emPoll->findOneByAdminKey($admin_key);
if ( $found ) {
if ($found) {
$em = $this->getDoctrine()->getManager();
$em->remove( $found );
$em->remove($found);
$em->flush();
return $this->json( [
return $this->json([
'message' => 'boom! le sondage et ses objets assocités a été supprimé',
] );
]);
} else {
return $this->json( [
return $this->json([
'message' => 'le token d\'autorisation est invalide, vous ne pouvez pas modifier ce sondage',
] );
]);
}
}
@ -499,38 +546,39 @@ class PollController extends EmailsController {
* name = "check_slug_is_unique",
* )
*/
public function checkSlugIsUniqueAction( string $customUrl ) {
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
$found = $emPoll->findOneByCustomUrl( $customUrl );
public function checkSlugIsUniqueAction(string $customUrl)
{
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
$found = $emPoll->findOneByCustomUrl($customUrl);
$elaborated_message_version = false;
if ( $found ) {
if ( ! $elaborated_message_version ) {
return $this->json( null,
204 );
if ($found) {
if (!$elaborated_message_version) {
return $this->json(null,
204);
}
// we should use an other slug
return $this->json( [
return $this->json([
'message' => ' NO, this custom_url is already taken on this Framadate instance ',
'data' => [
'slug' => $customUrl,
],
],
204 );
204);
}
if ( ! $elaborated_message_version ) {
return $this->json( null,
404 );
if (!$elaborated_message_version) {
return $this->json(null,
404);
}
return $this->json( [
return $this->json([
'message' => ' yes this slug is available on this Framadate instance ',
'data' => [
'slug' => $customUrl,
],
],
404 );
404);
}
@ -546,11 +594,12 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
public function getAdministrationConfig( SerializerInterface $serializer, $token ) {
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
$pollFound = $emPoll->findOneByAdminKey( $token );
public function getAdministrationConfig(SerializerInterface $serializer, $token)
{
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
$pollFound = $emPoll->findOneByAdminKey($token);
if ( $pollFound ) {
if ($pollFound) {
$poll = $pollFound;
@ -559,17 +608,17 @@ class PollController extends EmailsController {
'poll' => $poll->displayForAdmin(),
];
return $this->json( $returnedPoll,
200 );;
return $this->json($returnedPoll,
200);;
}
return $this->json( [
return $this->json([
'message' => 'You are not allowed to do anything with this token',
'data' => [
'token' => $token,
],
],
403 );
403);
}
@ -584,19 +633,20 @@ class PollController extends EmailsController {
*
* @return JsonResponse|Response
*/
public function getExpiredPollsCleanup( $token ) {
public function getExpiredPollsCleanup($token)
{
if ( $token !== 'superCaligistriixpirlidouciousse' ) {
return $this->json( [
if ($token !== 'superCaligistriixpirlidouciousse') {
return $this->json([
'message' => 'not allowed',
'data' => [
'token' => $token,
],
],
403 );
403);
}
$em = $this->getDoctrine()->getManager();
$emPoll = $this->getDoctrine()->getRepository( Poll::class );
$emPoll = $this->getDoctrine()->getRepository(Poll::class);
$deletablePollsFound = $emPoll->findDeletableExpiredPolls(); // dead by more than 30 days
$expiredPollsFound = $emPoll->findExpiredPolls(); // just dead
$soon_expired_polls = $emPoll->findSoonExpiredPolls(); // will die in 30 days
@ -608,42 +658,42 @@ class PollController extends EmailsController {
$really_delete = false;
foreach ( $soon_expired_polls as $item ) {
foreach ($soon_expired_polls as $item) {
$soon_expired_title[] = $item->getTitle();
}
foreach ( $expiredPollsFound as $item ) {
foreach ($expiredPollsFound as $item) {
$expiredTitle[] = $item->getTitle();
$item->setVotesAllowed( false );
$em->persist( $item );
$item->setVotesAllowed(false);
$em->persist($item);
}
foreach ( $deletablePollsFound as $item ) {
foreach ($deletablePollsFound as $item) {
$deletedTitle[] = $item->getTitle();
if ( $really_delete ) {
if ($really_delete) {
$item->setVotesAllowed( false );
$em->remove( $item );
$item->setVotesAllowed(false);
$em->remove($item);
}
}
$em->flush();
return $this->json( [
return $this->json([
'message' => 'cleanup report',
'really_delete' => $really_delete,
'deleted' => count( $deletablePollsFound ),
'deleted' => count($deletablePollsFound),
'deleted_titles' => $deletedTitle,
'expired' => count( $expiredPollsFound ),
'expired' => count($expiredPollsFound),
'expired_titles' => $expiredTitle,
'soon_to_be_expired' => count( $soon_expired_polls ),
'soon_to_be_expired' => count($soon_expired_polls),
'soon_to_be_expired_titles' => $soon_expired_title,
'data' => [
'token' => $token,
],
],
200 );
200);
}

0
src/Controller/api/v1/VoteController.php Normal file → Executable file
View File

0
src/DataFixtures/CommentFixtures.php Normal file → Executable file
View File

0
src/DataFixtures/VotesStacksFixtures.php Normal file → Executable file
View File

0
src/Entity/.gitignore vendored Normal file → Executable file
View File

View File

@ -306,8 +306,6 @@ class Poll
// handle sub time slices
if (count($boom) == 2) {
if (!isset($grouped_dates[$boom[0]])) {
$grouped_dates[$boom[0]] = [

0
src/Form/PollType.php Normal file → Executable file
View File

0
src/GraphQL/Resolver/ApartmentResolver.php Normal file → Executable file
View File

0
src/Kernel.php Normal file → Executable file
View File

0
src/Repository/.gitignore vendored Normal file → Executable file
View File

0
src/Service/MailService.php Normal file → Executable file
View File

0
symfony.lock Normal file → Executable file
View File

0
templates/admin/index.html.twig Normal file → Executable file
View File

0
templates/default/index.html.twig Normal file → Executable file
View File

0
templates/email-base-plaintext.html.twig Normal file → Executable file
View File

0
templates/email-base.html.twig Normal file → Executable file
View File

0
templates/emails/comment-notification.html.twig Normal file → Executable file
View File

0
templates/emails/partial/admin_link.html.twig Normal file → Executable file
View File

0
templates/emails/partial/poll.html.twig Normal file → Executable file
View File

0
templates/emails/partial/public_link.html.twig Normal file → Executable file
View File

0
templates/emails/vote-notification.html.twig Normal file → Executable file
View File

0
templates/migration/index.html.twig Normal file → Executable file
View File

0
templates/owner/index.html.twig Normal file → Executable file
View File

0
templates/pages/funky.html.twig Normal file → Executable file
View File

0
templates/pages/home.html.twig Normal file → Executable file
View File

0
templates/pages/migration.html.twig Normal file → Executable file
View File

0
templates/poll/_delete_form.html.twig Normal file → Executable file
View File

0
templates/poll/_form.html.twig Normal file → Executable file
View File

0
templates/poll/edit.html.twig Normal file → Executable file
View File

0
templates/poll/index.html.twig Normal file → Executable file
View File

0
templates/poll/new.html.twig Normal file → Executable file
View File

0
templates/poll/show.html.twig Normal file → Executable file
View File

Some files were not shown because too many files have changed in this diff Show More