1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/app/Http/Requests/Report/ReportPreviewRequest.php

64 lines
1.4 KiB
PHP
Raw Normal View History

2023-08-18 13:36:50 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2023-08-18 13:36:50 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\Report;
2024-03-25 05:17:16 +01:00
use App\Utils\Ninja;
2023-08-18 13:36:50 +02:00
use App\Http\Requests\Request;
2024-03-25 05:17:16 +01:00
use Illuminate\Auth\Access\AuthorizationException;
2023-08-18 13:36:50 +02:00
class ReportPreviewRequest extends Request
{
2024-03-25 05:17:16 +01:00
private string $error_message = '';
2023-08-18 13:36:50 +02:00
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
2024-01-14 05:05:00 +01:00
public function authorize(): bool
2023-08-18 13:36:50 +02:00
{
2024-03-25 05:17:16 +01:00
return $this->checkAuthority();
2023-08-18 13:36:50 +02:00
}
public function rules()
{
return [
];
}
public function prepareForValidation()
{
}
2024-03-25 05:17:16 +01:00
private function checkAuthority()
{
$this->error_message = ctrans('texts.authorization_failure');
/** @var \App\Models\User $user */
$user = auth()->user();
if(Ninja::isHosted() && $user->account->isFreeHostedClient()){
$this->error_message = ctrans('texts.upgrade_to_view_reports');
return false;
}
return $user->isAdmin() || $user->hasPermission('view_reports');
}
protected function failedAuthorization()
{
throw new AuthorizationException($this->error_message);
}
2023-08-18 13:36:50 +02:00
}