From e431a1ad9e0968bc521dc58b72668d63d7b7ead5 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Tue, 21 Jun 2022 14:06:23 +0200 Subject: [PATCH] Export invoice metafields (#3366) --- .github/release-drafter.yml | 6 +++--- src/Constants.php | 4 ++-- src/Controller/InvoiceController.php | 10 +++++++--- tests/Controller/InvoiceControllerTest.php | 12 ++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 4afc553d..5464a8e3 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,5 +1,5 @@ -name-template: 'v$RESOLVED_VERSION' -tag-template: 'v$RESOLVED_VERSION' +name-template: '$RESOLVED_VERSION' +tag-template: '$RESOLVED_VERSION' categories: - title: 'Enhancements' labels: @@ -35,7 +35,7 @@ version-resolver: - 'translation' default: patch template: | - [Upgrade guide](https://www.kimai.org/documentation/updates.html) - [Installation docs](https://www.kimai.org/documentation/installation.html) - [Docker docs](https://tobybatch.github.io/kimai2/) - [Docker Hub](https://hub.docker.com/r/kimai/kimai2) + [Upgrade Kimai](https://www.kimai.org/documentation/updates.html) - [Install Kimai](https://www.kimai.org/documentation/installation.html) - [Docker](https://tobybatch.github.io/kimai2/) & [Hub](https://hub.docker.com/r/kimai/kimai2) **PHP Version compatibility:** - PHP 7.3 is [end-of-life](https://www.php.net/supported-versions.php): you need to update now diff --git a/src/Constants.php b/src/Constants.php index 06d50fa5..e6d7a364 100644 --- a/src/Constants.php +++ b/src/Constants.php @@ -17,11 +17,11 @@ class Constants /** * The current release version */ - public const VERSION = '1.20.4'; + public const VERSION = '1.20.5'; /** * The current release: major * 10000 + minor * 100 + patch */ - public const VERSION_ID = 12004; + public const VERSION_ID = 12005; /** * The current release status, either "stable" or "dev" */ diff --git a/src/Controller/InvoiceController.php b/src/Controller/InvoiceController.php index 885ce926..c2c9255d 100644 --- a/src/Controller/InvoiceController.php +++ b/src/Controller/InvoiceController.php @@ -18,7 +18,7 @@ use App\Event\InvoiceCreatedMultipleEvent; use App\Event\InvoiceDocumentsEvent; use App\Event\InvoiceMetaDefinitionEvent; use App\Event\InvoiceMetaDisplayEvent; -use App\Export\Spreadsheet\AnnotatedObjectExporter; +use App\Export\Spreadsheet\EntityWithMetaFieldsExporter; use App\Export\Spreadsheet\Writer\BinaryFileResponseWriter; use App\Export\Spreadsheet\Writer\XlsxWriter; use App\Form\InvoiceDocumentUploadForm; @@ -359,7 +359,7 @@ final class InvoiceController extends AbstractController * @Route(path="/export", name="invoice_export", methods={"GET"}) * @Security("is_granted('view_invoice')") */ - public function exportAction(Request $request, AnnotatedObjectExporter $exporter) + public function exportAction(Request $request, EntityWithMetaFieldsExporter $exporter) { $query = new InvoiceArchiveQuery(); $query->setCurrentUser($this->getUser()); @@ -370,7 +370,11 @@ final class InvoiceController extends AbstractController $entries = $this->invoiceRepository->getInvoicesForQuery($query); - $spreadsheet = $exporter->export(Invoice::class, $entries); + $spreadsheet = $exporter->export( + Invoice::class, + $entries, + new InvoiceMetaDisplayEvent($query, InvoiceMetaDisplayEvent::INVOICE) + ); $writer = new BinaryFileResponseWriter(new XlsxWriter(), 'kimai-invoices'); return $writer->getFileResponse($spreadsheet); diff --git a/tests/Controller/InvoiceControllerTest.php b/tests/Controller/InvoiceControllerTest.php index daaabd9c..4f35f7c2 100644 --- a/tests/Controller/InvoiceControllerTest.php +++ b/tests/Controller/InvoiceControllerTest.php @@ -443,4 +443,16 @@ class InvoiceControllerTest extends ControllerBaseTest self::assertEquals(1, $node->count(), 'Could not find upload form'); // we do not test the upload here, just make sure that the action can be rendered properly } + + public function testExportIsSecureForRole() + { + $this->assertUrlIsSecuredForRole(User::ROLE_USER, '/invoice/export'); + } + + public function testExportAction() + { + $client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD); + $this->assertAccessIsGranted($client, '/invoice/export'); + $this->assertExcelExportResponse($client, 'kimai-invoices_'); + } }