mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-24 16:10:37 -06:00
Clean up requests
This commit is contained in:
parent
58c1880219
commit
c7eab7873e
@ -24,10 +24,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests;
|
||||
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
|
||||
@ -44,21 +42,7 @@ class UserStoreRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
$result = false;
|
||||
// Only allow authenticated users
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
|
||||
if ($repository->hasRole($user, 'owner')) {
|
||||
$result = true; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return auth()->check() && auth()->user()->hasRole('owner');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,21 +44,7 @@ class UserUpdateRequest extends FormRequest
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
$result = false;
|
||||
// Only allow authenticated users
|
||||
if (auth()->check()) {
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
|
||||
if ($repository->hasRole($user, 'owner')) {
|
||||
$result = true; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return auth()->check() && auth()->user()->hasRole('owner');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,8 @@ namespace FireflyIII\Http\Requests;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Rules\UniqueIban;
|
||||
use FireflyIII\Support\Request\AppendsLocationData;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -32,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class AccountFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes, AppendsLocationData;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -31,6 +32,8 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class AttachmentFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -29,6 +30,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class BillStoreRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class BillUpdateRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -22,6 +22,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use FireflyIII\Validation\AutoBudget\ValidatesAutoBudgetRequest;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
@ -31,6 +33,7 @@ use Illuminate\Validation\Validator;
|
||||
*/
|
||||
class BudgetFormStoreRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes, ValidatesAutoBudgetRequest;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use FireflyIII\Validation\AutoBudget\ValidatesAutoBudgetRequest;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
@ -32,6 +34,7 @@ use Illuminate\Validation\Validator;
|
||||
*/
|
||||
class BudgetFormUpdateRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes, ValidatesAutoBudgetRequest;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class CategoryFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class CurrencyFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -31,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class JournalLinkRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -29,6 +30,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class PiggyBankStoreRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class PiggyBankUpdateRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Rules\ValidJournals;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Log;
|
||||
|
||||
@ -32,6 +33,7 @@ use Log;
|
||||
*/
|
||||
class ReconciliationStoreRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -29,6 +29,7 @@ use FireflyIII\Models\Recurrence;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Rules\ValidRecurrenceRepetitionType;
|
||||
use FireflyIII\Rules\ValidRecurrenceRepetitionValue;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use FireflyIII\Validation\AccountValidator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
@ -39,7 +40,7 @@ use Log;
|
||||
*/
|
||||
class RecurrenceFormRequest extends FormRequest
|
||||
{
|
||||
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -38,25 +38,6 @@ use Log;
|
||||
*/
|
||||
class Request extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
|
||||
|
||||
/**
|
||||
* Return floating value.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
public function float(string $field): ?float
|
||||
{
|
||||
$res = $this->get($field);
|
||||
if (null === $res) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (float) $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class RuleFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -31,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class RuleGroupFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -24,6 +24,8 @@ namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Models\Location;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Support\Request\AppendsLocationData;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -31,6 +33,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class TagFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes, AppendsLocationData;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
@ -31,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
*/
|
||||
class UserFormRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
/**
|
||||
* Verify the request.
|
||||
*
|
||||
|
@ -64,6 +64,25 @@ trait ConvertsDataTypes
|
||||
return (int) $this->get($field);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return floating value.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return float|null
|
||||
*/
|
||||
protected function float(string $field): ?float
|
||||
{
|
||||
$res = $this->get($field);
|
||||
if (null === $res) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (float) $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse and clean a string, but keep the newlines.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user