From d3f3b75252934084127b521fc552130bd4224b24 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 22 Nov 2021 11:02:32 +0100 Subject: [PATCH] max 360 days expiracy for creation poll --- config/packages/nelmio_cors.yaml | 3 ++- src/Controller/api/v1/PollController.php | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config/packages/nelmio_cors.yaml b/config/packages/nelmio_cors.yaml index 96e6871..ddce62e 100644 --- a/config/packages/nelmio_cors.yaml +++ b/config/packages/nelmio_cors.yaml @@ -1,7 +1,8 @@ nelmio_cors: defaults: origin_regex: true - allow_origin: [ '%env(CORS_ALLOW_ORIGIN)%' ] # you can test locally with this value '^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' +# allow_origin: [ '%env(CORS_ALLOW_ORIGIN)%' ] # you can test locally with this value '^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' + allow_origin: [ '^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' ] allow_methods: [ 'GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE' ] allow_headers: [ '*' ] expose_headers: [ 'Authorization' ] diff --git a/src/Controller/api/v1/PollController.php b/src/Controller/api/v1/PollController.php index 1b37a04..79738c0 100644 --- a/src/Controller/api/v1/PollController.php +++ b/src/Controller/api/v1/PollController.php @@ -265,7 +265,7 @@ class PollController extends EmailsController { * requirements = {"creator"="\w+"} * ) * @param Request $request - * + * @description create a new poll * @return JsonResponse */ public function newPollAction( Request $request ) { @@ -291,8 +291,10 @@ class PollController extends EmailsController { // TODO check this one $newpoll->setAllowedAnswers( $data[ 'allowed_answers' ] ); } - $expiracyCalculated = $newpoll->addDaysToDate( new DateTime(), - $data[ 'default_expiracy_days_from_now' ] ); + // define a maximum expiration + $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 );