Fixed multipart form request for slide updates (PUT)
Change-Id: I47e0698de233e070d8b5b2867665642fc535d58f
This commit is contained in:
parent
6d08cc94ac
commit
06572735fd
@ -28,6 +28,7 @@ use Exception;
|
|||||||
use models\utils\IEntity;
|
use models\utils\IEntity;
|
||||||
use ModelSerializers\SerializerRegistry;
|
use ModelSerializers\SerializerRegistry;
|
||||||
use services\model\IPresentationService;
|
use services\model\IPresentationService;
|
||||||
|
use utils\ParseMultiPartFormDataInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OAuth2PresentationApiController
|
* Class OAuth2PresentationApiController
|
||||||
@ -675,7 +676,24 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController
|
|||||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||||
if (is_null($summit)) return $this->error404();
|
if (is_null($summit)) return $this->error404();
|
||||||
|
|
||||||
$data = $request->all();
|
|
||||||
|
$content_type = $request->headers->has('Content-Type') ? strtolower( $request->headers->get('Content-Type')) : null;
|
||||||
|
|
||||||
|
if (false !== $pos = strpos($content_type, ';')) {
|
||||||
|
$content_type = substr($content_type, 0, $pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!strstr($content_type, 'multipart/form-data'))
|
||||||
|
return $this->error400();
|
||||||
|
|
||||||
|
$parser = new ParseMultiPartFormDataInputStream(file_get_contents('php://input'));
|
||||||
|
$input = $parser->getInput();
|
||||||
|
$data = $input['parameters'];
|
||||||
|
$files = $input['files'];
|
||||||
|
$file = null;
|
||||||
|
|
||||||
|
if(isset($files['file']))
|
||||||
|
$file = $files['file'];
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'link' => 'nullable|url',
|
'link' => 'nullable|url',
|
||||||
@ -700,7 +718,10 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController
|
|||||||
'description',
|
'description',
|
||||||
];
|
];
|
||||||
|
|
||||||
$slide = $this->presentation_service->updateSlide($request, $presentation_id, $slide_id, HTMLCleaner::cleanData($data, $fields));
|
$slide = $this->presentation_service->updateSlide
|
||||||
|
(
|
||||||
|
$request, $presentation_id, $slide_id, HTMLCleaner::cleanData($data, $fields), $file
|
||||||
|
);
|
||||||
|
|
||||||
return $this->updated(SerializerRegistry::getInstance()->getSerializer($slide)->serialize());
|
return $this->updated(SerializerRegistry::getInstance()->getSerializer($slide)->serialize());
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ use models\summit\PresentationSlide;
|
|||||||
use models\summit\PresentationVideo;
|
use models\summit\PresentationVideo;
|
||||||
use models\summit\Summit;
|
use models\summit\Summit;
|
||||||
use Illuminate\Http\Request as LaravelRequest;
|
use Illuminate\Http\Request as LaravelRequest;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
/**
|
/**
|
||||||
* Interface IPresentationService
|
* Interface IPresentationService
|
||||||
* @package services\model
|
* @package services\model
|
||||||
@ -115,6 +116,7 @@ interface IPresentationService
|
|||||||
* @param int $presentation_id
|
* @param int $presentation_id
|
||||||
* @param int $slide_id
|
* @param int $slide_id
|
||||||
* @param array $slide_data
|
* @param array $slide_data
|
||||||
|
* @param UploadedFile $file
|
||||||
* @param array $allowed_extensions
|
* @param array $allowed_extensions
|
||||||
* @param int $max_file_size
|
* @param int $max_file_size
|
||||||
* @return mixed|PresentationSlide
|
* @return mixed|PresentationSlide
|
||||||
@ -126,6 +128,7 @@ interface IPresentationService
|
|||||||
$presentation_id,
|
$presentation_id,
|
||||||
$slide_id,
|
$slide_id,
|
||||||
array $slide_data,
|
array $slide_data,
|
||||||
|
UploadedFile $file = null,
|
||||||
array $allowed_extensions = ['ppt', 'pptx', 'xps', 'key', 'pdf', 'jpg', 'jpeg', 'png', 'svg', 'bmp', 'tga', 'tiff', 'gif'],
|
array $allowed_extensions = ['ppt', 'pptx', 'xps', 'key', 'pdf', 'jpg', 'jpeg', 'png', 'svg', 'bmp', 'tga', 'tiff', 'gif'],
|
||||||
$max_file_size = 10485760
|
$max_file_size = 10485760
|
||||||
);
|
);
|
||||||
|
@ -38,6 +38,7 @@ use libs\utils\ITransactionService;
|
|||||||
use models\summit\Summit;
|
use models\summit\Summit;
|
||||||
use Illuminate\Http\Request as LaravelRequest;
|
use Illuminate\Http\Request as LaravelRequest;
|
||||||
use App\Services\Model\IFolderService;
|
use App\Services\Model\IFolderService;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
/**
|
/**
|
||||||
* Class PresentationService
|
* Class PresentationService
|
||||||
* @package services\model
|
* @package services\model
|
||||||
@ -642,7 +643,7 @@ final class PresentationService
|
|||||||
if (!$presentation instanceof Presentation)
|
if (!$presentation instanceof Presentation)
|
||||||
throw new EntityNotFoundException('presentation not found!');
|
throw new EntityNotFoundException('presentation not found!');
|
||||||
|
|
||||||
$hasLink = isset($slide_data['link']);
|
$hasLink = isset($slide_data['link']) && !empty($slide_data['link']);
|
||||||
$hasFile = $request->hasFile('file');
|
$hasFile = $request->hasFile('file');
|
||||||
|
|
||||||
if($hasFile && $hasLink){
|
if($hasFile && $hasLink){
|
||||||
@ -683,11 +684,11 @@ final class PresentationService
|
|||||||
* @param int $presentation_id
|
* @param int $presentation_id
|
||||||
* @param int $slide_id
|
* @param int $slide_id
|
||||||
* @param array $slide_data
|
* @param array $slide_data
|
||||||
|
* @param UploadedFile $file
|
||||||
* @param array $allowed_extensions
|
* @param array $allowed_extensions
|
||||||
* @param int $max_file_size
|
* @param int $max_file_size
|
||||||
* @return mixed|PresentationSlide
|
* @return mixed|PresentationSlide
|
||||||
* @throws EntityNotFoundException
|
* @throws \Exception
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
*/
|
||||||
public function updateSlide
|
public function updateSlide
|
||||||
(
|
(
|
||||||
@ -695,9 +696,11 @@ final class PresentationService
|
|||||||
$presentation_id,
|
$presentation_id,
|
||||||
$slide_id,
|
$slide_id,
|
||||||
array $slide_data,
|
array $slide_data,
|
||||||
|
UploadedFile $file = null,
|
||||||
array $allowed_extensions = ['ppt', 'pptx', 'xps', 'key', 'pdf', 'jpg', 'jpeg', 'png', 'svg', 'bmp', 'tga', 'tiff', 'gif'],
|
array $allowed_extensions = ['ppt', 'pptx', 'xps', 'key', 'pdf', 'jpg', 'jpeg', 'png', 'svg', 'bmp', 'tga', 'tiff', 'gif'],
|
||||||
$max_file_size = 10485760
|
$max_file_size = 10485760
|
||||||
){
|
){
|
||||||
|
|
||||||
$slide = $this->tx_service->transaction(function () use
|
$slide = $this->tx_service->transaction(function () use
|
||||||
(
|
(
|
||||||
$request,
|
$request,
|
||||||
@ -705,7 +708,8 @@ final class PresentationService
|
|||||||
$slide_data,
|
$slide_data,
|
||||||
$max_file_size,
|
$max_file_size,
|
||||||
$allowed_extensions,
|
$allowed_extensions,
|
||||||
$slide_id
|
$slide_id,
|
||||||
|
$file
|
||||||
) {
|
) {
|
||||||
|
|
||||||
$presentation = $this->presentation_repository->getById($presentation_id);
|
$presentation = $this->presentation_repository->getById($presentation_id);
|
||||||
@ -724,8 +728,9 @@ final class PresentationService
|
|||||||
if (!$slide instanceof PresentationSlide)
|
if (!$slide instanceof PresentationSlide)
|
||||||
throw new EntityNotFoundException('slide not found!');
|
throw new EntityNotFoundException('slide not found!');
|
||||||
|
|
||||||
$hasLink = isset($slide_data['link']);
|
|
||||||
$hasFile = $request->hasFile('file');
|
$hasLink = isset($slide_data['link']) && !empty($slide_data['link']);
|
||||||
|
$hasFile = !is_null($file);
|
||||||
|
|
||||||
if($hasFile && $hasLink){
|
if($hasFile && $hasLink){
|
||||||
throw new ValidationException("you must provide a file or a link, not both.");
|
throw new ValidationException("you must provide a file or a link, not both.");
|
||||||
@ -746,7 +751,6 @@ final class PresentationService
|
|||||||
|
|
||||||
// check if there is any file sent
|
// check if there is any file sent
|
||||||
if($hasFile){
|
if($hasFile){
|
||||||
$file = $request->file('file');
|
|
||||||
if (!in_array($file->extension(), $allowed_extensions)) {
|
if (!in_array($file->extension(), $allowed_extensions)) {
|
||||||
throw new ValidationException(
|
throw new ValidationException(
|
||||||
sprintf("file does not has a valid extension '(%s)'.", implode("','", $allowed_extensions)));
|
sprintf("file does not has a valid extension '(%s)'.", implode("','", $allowed_extensions)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user