mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-25 08:21:08 -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;
|
namespace FireflyIII\Api\V1\Requests;
|
||||||
|
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
|
||||||
use FireflyIII\Rules\IsBoolean;
|
use FireflyIII\Rules\IsBoolean;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use FireflyIII\User;
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
|
||||||
@ -44,21 +42,7 @@ class UserStoreRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
$result = false;
|
return auth()->check() && auth()->user()->hasRole('owner');
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,21 +44,7 @@ class UserUpdateRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
$result = false;
|
return auth()->check() && auth()->user()->hasRole('owner');
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +25,8 @@ namespace FireflyIII\Http\Requests;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Location;
|
use FireflyIII\Models\Location;
|
||||||
use FireflyIII\Rules\UniqueIban;
|
use FireflyIII\Rules\UniqueIban;
|
||||||
|
use FireflyIII\Support\Request\AppendsLocationData;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,6 +34,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class AccountFormRequest extends FormRequest
|
class AccountFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes, AppendsLocationData;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +32,8 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class AttachmentFormRequest extends FormRequest
|
class AttachmentFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,6 +30,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class BillStoreRequest extends FormRequest
|
class BillStoreRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class BillUpdateRequest extends FormRequest
|
class BillUpdateRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
|
use FireflyIII\Validation\AutoBudget\ValidatesAutoBudgetRequest;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
@ -31,6 +33,7 @@ use Illuminate\Validation\Validator;
|
|||||||
*/
|
*/
|
||||||
class BudgetFormStoreRequest extends FormRequest
|
class BudgetFormStoreRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes, ValidatesAutoBudgetRequest;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
|
use FireflyIII\Validation\AutoBudget\ValidatesAutoBudgetRequest;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
|
|
||||||
@ -32,6 +34,7 @@ use Illuminate\Validation\Validator;
|
|||||||
*/
|
*/
|
||||||
class BudgetFormUpdateRequest extends FormRequest
|
class BudgetFormUpdateRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes, ValidatesAutoBudgetRequest;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class CategoryFormRequest extends FormRequest
|
class CategoryFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class CurrencyFormRequest extends FormRequest
|
class CurrencyFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\LinkType;
|
use FireflyIII\Models\LinkType;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class JournalLinkRequest extends FormRequest
|
class JournalLinkRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,6 +30,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class PiggyBankStoreRequest extends FormRequest
|
class PiggyBankStoreRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class PiggyBankUpdateRequest extends FormRequest
|
class PiggyBankUpdateRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Rules\ValidJournals;
|
use FireflyIII\Rules\ValidJournals;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class ReconciliationStoreRequest extends FormRequest
|
class ReconciliationStoreRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -29,6 +29,7 @@ use FireflyIII\Models\Recurrence;
|
|||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Rules\ValidRecurrenceRepetitionType;
|
use FireflyIII\Rules\ValidRecurrenceRepetitionType;
|
||||||
use FireflyIII\Rules\ValidRecurrenceRepetitionValue;
|
use FireflyIII\Rules\ValidRecurrenceRepetitionValue;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use FireflyIII\Validation\AccountValidator;
|
use FireflyIII\Validation\AccountValidator;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
@ -39,7 +40,7 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class RecurrenceFormRequest extends FormRequest
|
class RecurrenceFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -38,25 +38,6 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class Request extends FormRequest
|
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;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
use FireflyIII\Models\Rule;
|
use FireflyIII\Models\Rule;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,6 +31,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class RuleFormRequest extends FormRequest
|
class RuleFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Http\Requests;
|
|||||||
|
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
use FireflyIII\Rules\IsBoolean;
|
use FireflyIII\Rules\IsBoolean;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class RuleGroupFormRequest extends FormRequest
|
class RuleGroupFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,8 @@ namespace FireflyIII\Http\Requests;
|
|||||||
|
|
||||||
use FireflyIII\Models\Location;
|
use FireflyIII\Models\Location;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
|
use FireflyIII\Support\Request\AppendsLocationData;
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +33,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class TagFormRequest extends FormRequest
|
class TagFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes, AppendsLocationData;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +32,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||||||
*/
|
*/
|
||||||
class UserFormRequest extends FormRequest
|
class UserFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
|
use ConvertsDataTypes;
|
||||||
/**
|
/**
|
||||||
* Verify the request.
|
* Verify the request.
|
||||||
*
|
*
|
||||||
|
@ -64,6 +64,25 @@ trait ConvertsDataTypes
|
|||||||
return (int) $this->get($field);
|
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.
|
* Parse and clean a string, but keep the newlines.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user