Guard invoice period flags by list permission
This commit is contained in:
@@ -835,8 +835,9 @@ class InvoicingPeriodRoute
|
||||
$response->add_meta('customer_numbers', $customerNumbers);
|
||||
}
|
||||
$paginationOptions = self::getPeriodPaginationOptionsFromRequest();
|
||||
$includeInvoicePeriodFlags = $this->hasPermission('list_invoice_period_flags');
|
||||
// Get the invoicing period for the user
|
||||
$period = self::getInvoicingPeriod($dateFrom, $dateTo, $customerNumbers);
|
||||
$period = self::getInvoicingPeriod($dateFrom, $dateTo, $customerNumbers, $includeInvoicePeriodFlags);
|
||||
if ($paginationOptions !== null) {
|
||||
$paginated = self::applyPeriodPagination($period, $paginationOptions);
|
||||
$period = $paginated['period'];
|
||||
@@ -1841,7 +1842,12 @@ class InvoicingPeriodRoute
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function getInvoicingPeriod(string $dateFrom, string $dateTo, ?array $onlyCustomerNumbers = null): array
|
||||
private static function getInvoicingPeriod(
|
||||
string $dateFrom,
|
||||
string $dateTo,
|
||||
?array $onlyCustomerNumbers = null,
|
||||
bool $includeInvoicePeriodFlags = false
|
||||
): array
|
||||
{
|
||||
//$customersWithTransactions = self::getCustomersWithTransactions($dateFrom, $dateTo)
|
||||
$onlyCustomerNumbers = $onlyCustomerNumbers !== null
|
||||
@@ -1888,14 +1894,16 @@ class InvoicingPeriodRoute
|
||||
$draftOverlay['by_collection_id'] ?? [],
|
||||
$draftOverlay['by_customer_number'] ?? [],
|
||||
);
|
||||
$types = self::debugGetTime(function () use ($types, $dateFrom, $dateTo, $onlyCustomerNumbers) {
|
||||
return (new invoice_period_flag_service())->applyFlagsToPeriodTypes(
|
||||
$types,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$onlyCustomerNumbers
|
||||
);
|
||||
}, 'invoice_period_flags');
|
||||
if ($includeInvoicePeriodFlags) {
|
||||
$types = self::debugGetTime(function () use ($types, $dateFrom, $dateTo, $onlyCustomerNumbers) {
|
||||
return (new invoice_period_flag_service())->applyFlagsToPeriodTypes(
|
||||
$types,
|
||||
$dateFrom,
|
||||
$dateTo,
|
||||
$onlyCustomerNumbers
|
||||
);
|
||||
}, 'invoice_period_flags');
|
||||
}
|
||||
return [
|
||||
'dateFrom' => $dateFrom,
|
||||
'dateTo' => $dateTo,
|
||||
|
||||
@@ -45,12 +45,26 @@ it('streams the main period response instead of encoding the full payload at onc
|
||||
$content = (string)$content;
|
||||
|
||||
expect($content)->toContain('private static function streamInvoicingPeriodResponse(array $period): void')
|
||||
->and($content)->toContain('$period = self::getInvoicingPeriod($dateFrom, $dateTo, $customerNumbers);')
|
||||
->and($content)->toContain("$includeInvoicePeriodFlags = $this->hasPermission('list_invoice_period_flags');")
|
||||
->and($content)->toContain('$period = self::getInvoicingPeriod($dateFrom, $dateTo, $customerNumbers, $includeInvoicePeriodFlags);')
|
||||
->and($content)->toContain('self::streamInvoicingPeriodResponse($period);')
|
||||
->and($content)->not->toContain('$response->success([' . PHP_EOL . ' ...self::getInvoicingPeriod($dateFrom, $dateTo, $customerNumbers)')
|
||||
->and($content)->toContain('echo self::jsonFragment($customer);');
|
||||
});
|
||||
|
||||
it('only includes invoice period flags when the list permission is granted', function (): void {
|
||||
$content = file_get_contents(app_path('routes/InvoicingPeriodRoute.php'));
|
||||
|
||||
expect($content)->not->toBeFalse();
|
||||
$content = (string)$content;
|
||||
|
||||
expect($content)
|
||||
->toContain("$includeInvoicePeriodFlags = $this->hasPermission('list_invoice_period_flags');")
|
||||
->and($content)->toContain('bool $includeInvoicePeriodFlags = false')
|
||||
->and($content)->toContain('if ($includeInvoicePeriodFlags) {')
|
||||
->and($content)->toContain('applyFlagsToPeriodTypes(');
|
||||
});
|
||||
|
||||
it('maps batched period transaction rows to the legacy transaction response shape', function (): void {
|
||||
$reflection = new ReflectionClass(InvoicingPeriodRoute::class);
|
||||
$method = $reflection->getMethod('constructTransactionObjectFromPeriodRow');
|
||||
|
||||
Reference in New Issue
Block a user