mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Code cleanup.
This commit is contained in:
@@ -23,8 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Validation;
|
||||
|
||||
use Config;
|
||||
use DB;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
@@ -37,14 +35,11 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Services\Password\Verifier;
|
||||
use FireflyIII\Support\ParseDateString;
|
||||
use FireflyIII\TransactionRules\Triggers\TriggerInterface;
|
||||
use FireflyIII\User;
|
||||
use Google2FA;
|
||||
use Illuminate\Validation\Validator;
|
||||
use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException;
|
||||
use PragmaRX\Google2FA\Exceptions\InvalidCharactersException;
|
||||
use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException;
|
||||
use ValueError;
|
||||
|
||||
/**
|
||||
* Class FireflyValidator.
|
||||
@@ -56,10 +51,10 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
* @throws IncompatibleWithGoogleAuthenticatorException
|
||||
* @throws InvalidCharactersException
|
||||
* @throws SecretKeyTooShortException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validate2faCode($attribute, $value): bool
|
||||
@@ -70,6 +65,7 @@ class FireflyValidator extends Validator
|
||||
$user = auth()->user();
|
||||
if (null === $user) {
|
||||
app('log')->error('No user during validate2faCode');
|
||||
|
||||
return false;
|
||||
}
|
||||
$secretPreference = app('preferences')->get('temp-mfa-secret');
|
||||
@@ -78,16 +74,15 @@ class FireflyValidator extends Validator
|
||||
$secret = '';
|
||||
}
|
||||
|
||||
return (bool)Google2FA::verifyKey((string)$secret, $value);
|
||||
return (bool)\Google2FA::verifyKey((string)$secret, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateBelongsToUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
@@ -96,7 +91,7 @@ class FireflyValidator extends Validator
|
||||
if (0 === (int)$value) {
|
||||
return true;
|
||||
}
|
||||
$count = DB::table($parameters[0])->where('user_id', auth()->user()->id)->where($field, $value)->count();
|
||||
$count = \DB::table($parameters[0])->where('user_id', auth()->user()->id)->where($field, $value)->count();
|
||||
|
||||
return 1 === $count;
|
||||
}
|
||||
@@ -104,9 +99,8 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateBic($attribute, $value): bool
|
||||
{
|
||||
@@ -123,11 +117,7 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateIban(mixed $attribute, mixed $value): bool
|
||||
{
|
||||
@@ -225,14 +215,15 @@ class FireflyValidator extends Validator
|
||||
// take
|
||||
$first = substr($value, 0, 4);
|
||||
$last = substr($value, 4);
|
||||
$iban = $last . $first;
|
||||
$iban = $last.$first;
|
||||
$iban = trim(str_replace($search, $replace, $iban));
|
||||
if ('' === $iban) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$checksum = bcmod($iban, '97');
|
||||
} catch (ValueError $e) { // @phpstan-ignore-line
|
||||
} catch (\ValueError $e) { // @phpstan-ignore-line
|
||||
$message = sprintf('Could not validate IBAN check value "%s" (IBAN "%s")', $iban, $value);
|
||||
app('log')->error($message);
|
||||
app('log')->error($e->getTraceAsString());
|
||||
@@ -247,9 +238,8 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateLess($attribute, $value, $parameters): bool
|
||||
{
|
||||
@@ -263,9 +253,8 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateMore($attribute, $value, $parameters): bool
|
||||
{
|
||||
@@ -279,9 +268,8 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateMustExist($attribute, $value, $parameters): bool
|
||||
{
|
||||
@@ -290,18 +278,11 @@ class FireflyValidator extends Validator
|
||||
if (0 === (int)$value) {
|
||||
return true;
|
||||
}
|
||||
$count = DB::table($parameters[0])->where($field, $value)->count();
|
||||
$count = \DB::table($parameters[0])->where($field, $value)->count();
|
||||
|
||||
return 1 === $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attribute
|
||||
*
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateRuleActionValue(string $attribute, string $value = null): bool
|
||||
{
|
||||
// first, get the index from this string:
|
||||
@@ -367,11 +348,6 @@ class FireflyValidator extends Validator
|
||||
|
||||
/**
|
||||
* $attribute has the format triggers.%d.value.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateRuleTriggerValue(string $attribute, string $value = null): bool
|
||||
{
|
||||
@@ -436,6 +412,7 @@ class FireflyValidator extends Validator
|
||||
if (in_array($triggerType, ['date_is', 'created_on', 'updated_on', 'date_before', 'date_after'], true)) {
|
||||
/** @var ParseDateString $parser */
|
||||
$parser = app(ParseDateString::class);
|
||||
|
||||
try {
|
||||
$parser->parseDate($value);
|
||||
} catch (FireflyException $e) {
|
||||
@@ -451,9 +428,8 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateSecurePassword($attribute, $value): bool
|
||||
{
|
||||
@@ -475,167 +451,56 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateUniqueAccountForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
// because a user does not have to be logged in (tests and what-not).
|
||||
if (!auth()->check()) {
|
||||
app('log')->debug('validateUniqueAccountForUser::anon');
|
||||
|
||||
return $this->validateAccountAnonymously();
|
||||
}
|
||||
if (array_key_exists('objectType', $this->data)) {
|
||||
app('log')->debug('validateUniqueAccountForUser::typeString');
|
||||
|
||||
return $this->validateByAccountTypeString($value, $parameters, $this->data['objectType']);
|
||||
}
|
||||
if (array_key_exists('type', $this->data)) {
|
||||
app('log')->debug('validateUniqueAccountForUser::typeString');
|
||||
|
||||
return $this->validateByAccountTypeString($value, $parameters, (string)$this->data['type']);
|
||||
}
|
||||
if (array_key_exists('account_type_id', $this->data)) {
|
||||
app('log')->debug('validateUniqueAccountForUser::typeId');
|
||||
|
||||
return $this->validateByAccountTypeId($value, $parameters);
|
||||
}
|
||||
$parameterId = $parameters[0] ?? null;
|
||||
if (null !== $parameterId) {
|
||||
app('log')->debug('validateUniqueAccountForUser::paramId');
|
||||
|
||||
return $this->validateByParameterId((int)$parameterId, $value);
|
||||
}
|
||||
if (array_key_exists('id', $this->data)) {
|
||||
app('log')->debug('validateUniqueAccountForUser::accountId');
|
||||
|
||||
return $this->validateByAccountId($value);
|
||||
}
|
||||
|
||||
// without type, just try to validate the name.
|
||||
app('log')->debug('validateUniqueAccountForUser::accountName');
|
||||
|
||||
return $this->validateByAccountName($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function validateAccountAnonymously(): bool
|
||||
{
|
||||
if (!array_key_exists('user_id', $this->data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = User::find($this->data['user_id']);
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$value = $this->data['name'];
|
||||
|
||||
/** @var Account|null $result */
|
||||
$result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first();
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @param array $parameters
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
|
||||
{
|
||||
/** @var array|null $search */
|
||||
$search = Config::get('firefly.accountTypeByIdentifier.' . $type);
|
||||
|
||||
if (null === $search) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$accountTypes = AccountType::whereIn('type', $search)->get();
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
$accountTypeIds = $accountTypes->pluck('id')->toArray();
|
||||
/** @var Account|null $result */
|
||||
$result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateByAccountTypeId($value, $parameters): bool
|
||||
{
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
|
||||
/** @var Account|null $result */
|
||||
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateByParameterId(int $accountId, $value): bool
|
||||
{
|
||||
/** @var Account $existingAccount */
|
||||
$existingAccount = Account::find($accountId);
|
||||
|
||||
$type = $existingAccount->accountType;
|
||||
$ignore = $existingAccount->id;
|
||||
|
||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
|
||||
return null === $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateByAccountId($value): bool
|
||||
{
|
||||
/** @var Account $existingAccount */
|
||||
$existingAccount = Account::find($this->data['id']);
|
||||
|
||||
$type = $existingAccount->accountType;
|
||||
$ignore = $existingAccount->id;
|
||||
|
||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first();
|
||||
|
||||
return null === $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function validateByAccountName(string $value): bool
|
||||
{
|
||||
return auth()->user()->accounts()->where('name', $value)->count() === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
@@ -645,10 +510,11 @@ class FireflyValidator extends Validator
|
||||
}
|
||||
|
||||
$query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereNull('accounts.deleted_at')
|
||||
->where('accounts.user_id', auth()->user()->id)
|
||||
->where('account_meta.name', 'account_number')
|
||||
->where('account_meta.data', json_encode($value));
|
||||
->whereNull('accounts.deleted_at')
|
||||
->where('accounts.user_id', auth()->user()->id)
|
||||
->where('account_meta.name', 'account_number')
|
||||
->where('account_meta.data', json_encode($value))
|
||||
;
|
||||
|
||||
if ($accountId > 0) {
|
||||
// exclude current account from check.
|
||||
@@ -666,9 +532,11 @@ class FireflyValidator extends Validator
|
||||
$type = $this->data['objectType'] ?? 'unknown';
|
||||
if ('expense' !== $type && 'revenue' !== $type) {
|
||||
app('log')->warning(sprintf('Account number "%s" is not unique and account type "%s" cannot share its account number.', $value, $type));
|
||||
|
||||
return false;
|
||||
}
|
||||
app('log')->debug(sprintf('Account number "%s" is not unique but account type "%s" may share its account number.', $value, $type));
|
||||
|
||||
// one other account with this account number.
|
||||
/** @var AccountMeta $entry */
|
||||
foreach ($set as $entry) {
|
||||
@@ -676,56 +544,37 @@ class FireflyValidator extends Validator
|
||||
$otherType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $otherAccount->accountType->type));
|
||||
if (('expense' === $otherType || 'revenue' === $otherType) && $otherType !== $type) {
|
||||
app('log')->debug(sprintf('The other account with this account number is a "%s" so return true.', $otherType));
|
||||
|
||||
return true;
|
||||
}
|
||||
app('log')->debug(sprintf('The other account with this account number is a "%s" so return false.', $otherType));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $attribute
|
||||
* @param string|null $value
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencyCode(string | null $attribute, string | null $value): bool
|
||||
public function validateUniqueCurrencyCode(null|string $attribute, null|string $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param string $attribute
|
||||
* @param string $value
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
|
||||
{
|
||||
return 0 === DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
||||
return 0 === \DB::table('transaction_currencies')->where($field, $value)->whereNull('deleted_at')->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $attribute
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencyName(string | null $attribute, string | null $value): bool
|
||||
public function validateUniqueCurrencyName(null|string $attribute, null|string $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $attribute
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencySymbol(string | null $attribute, string | null $value): bool
|
||||
public function validateUniqueCurrencySymbol(null|string $attribute, null|string $value): bool
|
||||
{
|
||||
return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value);
|
||||
}
|
||||
@@ -734,9 +583,8 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @param mixed $something
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateUniqueExistingWebhook($value, $parameters, $something): bool
|
||||
{
|
||||
@@ -750,7 +598,7 @@ class FireflyValidator extends Validator
|
||||
if (auth()->check()) {
|
||||
// get existing webhook value:
|
||||
if (0 !== $existingId) {
|
||||
/** @var Webhook|null $webhook */
|
||||
/** @var null|Webhook $webhook */
|
||||
$webhook = auth()->user()->webhooks()->find($existingId);
|
||||
if (null === $webhook) {
|
||||
return false;
|
||||
@@ -769,18 +617,18 @@ class FireflyValidator extends Validator
|
||||
$userId = auth()->user()->id;
|
||||
|
||||
return 0 === Webhook::whereUserId($userId)
|
||||
->where('trigger', $trigger)
|
||||
->where('response', $response)
|
||||
->where('delivery', $delivery)
|
||||
->where('id', '!=', $existingId)
|
||||
->where('url', $url)->count();
|
||||
->where('trigger', $trigger)
|
||||
->where('response', $response)
|
||||
->where('delivery', $delivery)
|
||||
->where('id', '!=', $existingId)
|
||||
->where('url', $url)->count()
|
||||
;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Validate an object and its uniqueness. Checks for encryption / encrypted values as well.
|
||||
*
|
||||
* parameter 0: the table
|
||||
@@ -790,9 +638,8 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateUniqueObjectForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
@@ -808,13 +655,15 @@ class FireflyValidator extends Validator
|
||||
$exclude = (int)$data['id'];
|
||||
}
|
||||
// get entries from table
|
||||
$result = DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
||||
->where('id', '!=', $exclude)
|
||||
->where($field, $value)
|
||||
->first([$field]);
|
||||
$result = \DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at')
|
||||
->where('id', '!=', $exclude)
|
||||
->where($field, $value)
|
||||
->first([$field])
|
||||
;
|
||||
if (null === $result) {
|
||||
return true; // not found, so true.
|
||||
}
|
||||
|
||||
// found, so not unique.
|
||||
return false;
|
||||
}
|
||||
@@ -823,17 +672,17 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateUniqueObjectGroup($attribute, $value, $parameters): bool
|
||||
{
|
||||
$exclude = $parameters[0] ?? null;
|
||||
$query = DB::table('object_groups')
|
||||
->whereNull('object_groups.deleted_at')
|
||||
->where('object_groups.user_id', auth()->user()->id)
|
||||
->where('object_groups.title', $value);
|
||||
$query = \DB::table('object_groups')
|
||||
->whereNull('object_groups.deleted_at')
|
||||
->where('object_groups.user_id', auth()->user()->id)
|
||||
->where('object_groups.title', $value)
|
||||
;
|
||||
if (null !== $exclude) {
|
||||
$query->where('object_groups.id', '!=', (int)$exclude);
|
||||
}
|
||||
@@ -845,15 +694,15 @@ class FireflyValidator extends Validator
|
||||
* @param mixed $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateUniquePiggyBankForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
$exclude = $parameters[0] ?? null;
|
||||
$query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id);
|
||||
$query = \DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id)
|
||||
;
|
||||
if (null !== $exclude) {
|
||||
$query->where('piggy_banks.id', '!=', (int)$exclude);
|
||||
}
|
||||
@@ -865,9 +714,8 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function validateUniqueWebhook($value, $parameters): bool
|
||||
{
|
||||
@@ -884,12 +732,113 @@ class FireflyValidator extends Validator
|
||||
$userId = auth()->user()->id;
|
||||
|
||||
return 0 === Webhook::whereUserId($userId)
|
||||
->where('trigger', $trigger)
|
||||
->where('response', $response)
|
||||
->where('delivery', $delivery)
|
||||
->where('url', $url)->count();
|
||||
->where('trigger', $trigger)
|
||||
->where('response', $response)
|
||||
->where('delivery', $delivery)
|
||||
->where('url', $url)->count()
|
||||
;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function validateAccountAnonymously(): bool
|
||||
{
|
||||
if (!array_key_exists('user_id', $this->data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = User::find($this->data['user_id']);
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$value = $this->data['name'];
|
||||
|
||||
/** @var null|Account $result */
|
||||
$result = $user->accounts()->where('account_type_id', $type->id)->where('name', $value)->first();
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
|
||||
{
|
||||
/** @var null|array $search */
|
||||
$search = \Config::get('firefly.accountTypeByIdentifier.'.$type);
|
||||
|
||||
if (null === $search) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$accountTypes = AccountType::whereIn('type', $search)->get();
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
$accountTypeIds = $accountTypes->pluck('id')->toArray();
|
||||
|
||||
/** @var null|Account $result */
|
||||
$result = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first()
|
||||
;
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $parameters
|
||||
*/
|
||||
private function validateByAccountTypeId($value, $parameters): bool
|
||||
{
|
||||
$type = AccountType::find($this->data['account_type_id'])->first();
|
||||
$ignore = (int)($parameters[0] ?? 0.0);
|
||||
|
||||
/** @var null|Account $result */
|
||||
$result = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first()
|
||||
;
|
||||
|
||||
return null === $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
private function validateByParameterId(int $accountId, $value): bool
|
||||
{
|
||||
/** @var Account $existingAccount */
|
||||
$existingAccount = Account::find($accountId);
|
||||
|
||||
$type = $existingAccount->accountType;
|
||||
$ignore = $existingAccount->id;
|
||||
|
||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first()
|
||||
;
|
||||
|
||||
return null === $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
private function validateByAccountId($value): bool
|
||||
{
|
||||
/** @var Account $existingAccount */
|
||||
$existingAccount = Account::find($this->data['id']);
|
||||
|
||||
$type = $existingAccount->accountType;
|
||||
$ignore = $existingAccount->id;
|
||||
|
||||
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
|
||||
->where('name', $value)
|
||||
->first()
|
||||
;
|
||||
|
||||
return null === $entry;
|
||||
}
|
||||
|
||||
private function validateByAccountName(string $value): bool
|
||||
{
|
||||
return 0 === auth()->user()->accounts()->where('name', $value)->count();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user