mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Squashed commit of the following:
commit 977863c2dd56d5c835f2a710cad7f7d3ba42da68 Merge: 5c37b419d3eb7ffed1
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sun Dec 12 14:45:21 2021 +0100 Merge remote-tracking branch 'origin/master' into docgen/improve-normalizer commit 5c37b419ddf0b32b9950c33042396bba1860da84 Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sun Dec 12 14:37:05 2021 +0100 fix normalization for user and type in null value commit 4469d46cdb19051fedec86bbb84e2351e6fcb72e Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sun Dec 12 13:24:23 2021 +0100 add civility to person commit 6cf92fbbde8f4d9f2f4763ec4ee88216257040f7 Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sun Dec 12 13:19:36 2021 +0100 fix person normalization: add a isNull on not null person commit ed6087ff8fd47b80ea5e9526756fe5d032d478e3 Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sun Dec 12 13:08:46 2021 +0100 fix stan and cs issues commit 8429c334c33b3545835cbde034fccaa529c134a7 Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sun Dec 12 13:08:36 2021 +0100 fix id type commit 39ae00d172a9f29320a97abb8518b2ea48d89d9b Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sun Dec 12 12:52:41 2021 +0100 fix test and fix null or not-null value have same keys commit 312fcc44c07affa7aa60f6c5fce58f9d1c564cc3 Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sat Dec 11 03:27:30 2021 +0100 improve normalization wip commit f91a29635827005fc58617dc1c9d210091372be5 Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sat Dec 11 01:15:32 2021 +0100 improve normalization commit 56060e5e6a2191ef441039fdc91a01fb4653a553 Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Sat Dec 11 00:41:09 2021 +0100 handle changelog with translatable string commit9004686a13
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Fri Dec 10 01:10:55 2021 +0100 improve docgen wip commite266fa0e5d
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Thu Dec 9 21:50:56 2021 +0100 show errors from relatorio driver commit75ba56fa09
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Thu Dec 9 21:14:12 2021 +0100 add verification tool for admin commit12d6829b98
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Thu Dec 9 14:17:42 2021 +0100 fix type with phonenumber helper commit7b5e96771f
Merge:8a9024de1
8a4748dc2
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Thu Dec 9 14:11:14 2021 +0100 Merge remote-tracking branch 'origin/master' into docgen/improve-normalizer commit8a9024de13
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Thu Dec 9 13:51:36 2021 +0100 add docgen:normalization for relation commit24a404964b
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Thu Dec 9 12:44:41 2021 +0100 docgen normalization for relation commit5d24bd4d11
Merge:70ab23214
455b225f4
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 21:08:30 2021 +0100 Merge branch 'master' into docgen/improve-normalizer commit70ab232149
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 13:58:49 2021 +0100 improve docgen, trnslations, admin commit027c01fc58
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 12:23:24 2021 +0100 fix css block commitfdc5127c74
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 11:57:16 2021 +0100 fix some error in test (wip) commitb8d48f04ae
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 11:47:50 2021 +0100 fix tests (wip) commitf1b1771d6b
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 11:35:00 2021 +0100 fix tests (wip) commit62dabbe1e7
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 11:14:46 2021 +0100 fix code style commit4101392190
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 11:13:49 2021 +0100 fix tests and type hinting commit3f1bed0b1c
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 11:05:41 2021 +0100 fix tests (wip) commit79fbdcdee4
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 11:05:29 2021 +0100 type hint User class commit3d8d79323e
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 10:56:30 2021 +0100 remove error messages commit32178e22fe
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 10:51:30 2021 +0100 fix tests (wip) commit60a8c20896
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 10:29:54 2021 +0100 update app commit9d8011da61
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 10:06:35 2021 +0100 fix loading origin commit789eeadb40
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 09:52:51 2021 +0100 fix loading fixtures for doc generator template commitf206fdb08c
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 09:52:35 2021 +0100 fix code style commit9d5409d8d9
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 09:52:06 2021 +0100 fix casting commite297d82533
Author: Julien Fastré <julien.fastre@champs-libres.coop> Date: Wed Dec 8 09:26:13 2021 +0100 fixes on tests [WIP]
This commit is contained in:
@@ -18,6 +18,7 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface;
|
||||
use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
@@ -28,10 +29,15 @@ use GuzzleHttp\Exception\TransferException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
// TODO à mettre dans services
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
@@ -78,6 +84,27 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/admin/doc/gen/generate/test/from/{template}/for/{entityClassName}/{entityId}",
|
||||
* name="chill_docgenerator_test_generate_from_template"
|
||||
* )
|
||||
*/
|
||||
public function adminTestGenerateDocFromTemplateAction(
|
||||
DocGeneratorTemplate $template,
|
||||
string $entityClassName,
|
||||
int $entityId,
|
||||
Request $request
|
||||
): Response {
|
||||
return $this->generateDocFromTemplate(
|
||||
$template,
|
||||
$entityClassName,
|
||||
$entityId,
|
||||
$request,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/doc/gen/generate/from/{template}/for/{entityClassName}/{entityId}",
|
||||
@@ -89,6 +116,81 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
string $entityClassName,
|
||||
int $entityId,
|
||||
Request $request
|
||||
): Response {
|
||||
return $this->generateDocFromTemplate(
|
||||
$template,
|
||||
$entityClassName,
|
||||
$entityId,
|
||||
$request,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/api/1.0/docgen/templates/by-entity/{entityClassName}",
|
||||
* name="chill_docgenerator_templates_for_entity_api"
|
||||
* )
|
||||
*/
|
||||
public function listTemplateApiAction(string $entityClassName): Response
|
||||
{
|
||||
$nb = $this->docGeneratorTemplateRepository->countByEntity($entityClassName);
|
||||
$paginator = $this->paginatorFactory->create($nb);
|
||||
$entities = $this->docGeneratorTemplateRepository->findByEntity(
|
||||
$entityClassName,
|
||||
$paginator->getCurrentPageFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
);
|
||||
|
||||
return $this->json(
|
||||
new Collection($entities, $paginator),
|
||||
Response::HTTP_OK,
|
||||
[],
|
||||
[AbstractNormalizer::GROUPS => ['read']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "{_locale}/admin/doc/gen/generate/test/redirect",
|
||||
* name="chill_docgenerator_test_generate_redirect"
|
||||
* )
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function redirectToTestGenerate(Request $request): RedirectResponse
|
||||
{
|
||||
$template = $request->query->getInt('template');
|
||||
|
||||
if (null === $template) {
|
||||
throw new BadRequestHttpException('template parameter is missing');
|
||||
}
|
||||
|
||||
$entityClassName = $request->query->get('entityClassName');
|
||||
|
||||
if (null === $entityClassName) {
|
||||
throw new BadRequestHttpException('entityClassName is missing');
|
||||
}
|
||||
|
||||
$entityId = $request->query->get('entityId');
|
||||
|
||||
if (null === $entityId) {
|
||||
throw new BadRequestHttpException('entityId is missing');
|
||||
}
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'chill_docgenerator_test_generate_from_template',
|
||||
['template' => $template, 'entityClassName' => $entityClassName, 'entityId' => $entityId,
|
||||
'returnPath' => $request->query->get('returnPath', '/'), ]
|
||||
);
|
||||
}
|
||||
|
||||
private function generateDocFromTemplate(
|
||||
DocGeneratorTemplate $template,
|
||||
string $entityClassName,
|
||||
int $entityId,
|
||||
Request $request,
|
||||
bool $isTest
|
||||
): Response {
|
||||
try {
|
||||
$context = $this->contextManager->getContextByDocGeneratorTemplate($template);
|
||||
@@ -105,9 +207,29 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
$contextGenerationData = [];
|
||||
|
||||
if ($context instanceof DocGeneratorContextWithPublicFormInterface
|
||||
&& $context->hasPublicForm($template, $entity)) {
|
||||
$builder = $this->createFormBuilder($context->getFormData($template, $entity));
|
||||
&& $context->hasPublicForm($template, $entity) || $isTest) {
|
||||
if ($context instanceof DocGeneratorContextWithPublicFormInterface) {
|
||||
$builder = $this->createFormBuilder(
|
||||
array_merge(
|
||||
$context->getFormData($template, $entity),
|
||||
$isTest ? ['test_file' => null] : []
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$builder = $this->createFormBuilder(
|
||||
['test_file' => null]
|
||||
);
|
||||
}
|
||||
|
||||
$context->buildPublicForm($builder, $template, $entity);
|
||||
|
||||
if ($isTest) {
|
||||
$builder->add('test_file', FileType::class, [
|
||||
'label' => 'Template file',
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$form = $builder->getForm()->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@@ -121,43 +243,72 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||
'GET',
|
||||
$template->getFile()->getFilename()
|
||||
);
|
||||
if ($isTest && null !== $contextGenerationData['test_file']) {
|
||||
/** @var File $file */
|
||||
$file = $contextGenerationData['test_file'];
|
||||
$templateResource = fopen($file->getPathname(), 'rb');
|
||||
} else {
|
||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||
'GET',
|
||||
$template->getFile()->getFilename()
|
||||
);
|
||||
|
||||
$data = $this->client->request('GET', $getUrlGen->url);
|
||||
$data = $this->client->request('GET', $getUrlGen->url);
|
||||
|
||||
$iv = $template->getFile()->getIv(); // iv as an Array
|
||||
$ivGoodFormat = pack('C*', ...$iv); // iv as a String (ok for openssl_decrypt)
|
||||
$iv = $template->getFile()->getIv(); // iv as an Array
|
||||
$ivGoodFormat = pack('C*', ...$iv); // iv as a String (ok for openssl_decrypt)
|
||||
|
||||
$method = 'AES-256-CBC';
|
||||
$method = 'AES-256-CBC';
|
||||
|
||||
$key = $template->getFile()->getKeyInfos()['k'];
|
||||
$keyGoodFormat = Base64Url::decode($key);
|
||||
$key = $template->getFile()->getKeyInfos()['k'];
|
||||
$keyGoodFormat = Base64Url::decode($key);
|
||||
|
||||
$dataDecrypted = openssl_decrypt($data->getContent(), $method, $keyGoodFormat, 1, $ivGoodFormat);
|
||||
$dataDecrypted = openssl_decrypt($data->getContent(), $method, $keyGoodFormat, 1, $ivGoodFormat);
|
||||
|
||||
if (false === $dataDecrypted) {
|
||||
throw new Exception('Error during Decrypt ', 1);
|
||||
if (false === $dataDecrypted) {
|
||||
throw new Exception('Error during Decrypt ', 1);
|
||||
}
|
||||
|
||||
if (false === $templateResource = fopen('php://memory', 'r+b')) {
|
||||
$this->logger->error('Could not write data to memory');
|
||||
|
||||
throw new HttpException(500);
|
||||
}
|
||||
fwrite($templateResource, $dataDecrypted);
|
||||
rewind($templateResource);
|
||||
}
|
||||
|
||||
if (false === $templateResource = fopen('php://memory', 'r+b')) {
|
||||
$this->logger->error('Could not write data to memory');
|
||||
|
||||
throw new HttpException(500);
|
||||
}
|
||||
|
||||
fwrite($templateResource, $dataDecrypted);
|
||||
rewind($templateResource);
|
||||
|
||||
$datas = $context->getData($template, $entity, $contextGenerationData);
|
||||
dump('datas compiled', $datas);
|
||||
|
||||
$generatedResource = $this->driver->generateFromResource($templateResource, $template->getFile()->getType(), $datas, $template->getFile()->getFilename());
|
||||
try {
|
||||
$generatedResource = $this->driver->generateFromResource($templateResource, $template->getFile()->getType(), $datas, $template->getFile()->getFilename());
|
||||
} catch (TemplateException $e) {
|
||||
$msg = implode("\n", $e->getErrors());
|
||||
|
||||
return new Response($msg, 400, [
|
||||
'Content-Type' => 'text/plain',
|
||||
]);
|
||||
}
|
||||
|
||||
fclose($templateResource);
|
||||
|
||||
if ($isTest) {
|
||||
return new StreamedResponse(
|
||||
static function () use ($generatedResource) {
|
||||
fpassthru($generatedResource);
|
||||
fclose($generatedResource);
|
||||
},
|
||||
Response::HTTP_OK,
|
||||
[
|
||||
'Content-Transfer-Encoding', 'binary',
|
||||
'Content-Type' => 'application/vnd.oasis.opendocument.text',
|
||||
'Content-Disposition' => sprintf('attachment; filename="%s.odt"', 'generated'),
|
||||
'Content-Length' => fstat($generatedResource)['size'],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
$genDocName = 'doc_' . sprintf('%010d', mt_rand()) . 'odt';
|
||||
|
||||
$getUrlGen = $this->tempUrlGenerator->generate(
|
||||
@@ -206,28 +357,4 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
throw new Exception('Unable to generate document.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/api/1.0/docgen/templates/by-entity/{entityClassName}",
|
||||
* name="chill_docgenerator_templates_for_entity_api"
|
||||
* )
|
||||
*/
|
||||
public function listTemplateApiAction(string $entityClassName): Response
|
||||
{
|
||||
$nb = $this->docGeneratorTemplateRepository->countByEntity($entityClassName);
|
||||
$paginator = $this->paginatorFactory->create($nb);
|
||||
$entities = $this->docGeneratorTemplateRepository->findByEntity(
|
||||
$entityClassName,
|
||||
$paginator->getCurrentPageFirstItemNumber(),
|
||||
$paginator->getItemsPerPage()
|
||||
);
|
||||
|
||||
return $this->json(
|
||||
new Collection($entities, $paginator),
|
||||
Response::HTTP_OK,
|
||||
[],
|
||||
[AbstractNormalizer::GROUPS => ['read']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user