mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Code for new release
This commit is contained in:
@@ -123,10 +123,10 @@ trait DepositValidation
|
||||
}
|
||||
|
||||
// if there is an iban, it can only be in use by a revenue account or we will fail.
|
||||
if(null !== $accountIban && '' !== $accountIban) {
|
||||
if (null !== $accountIban && '' !== $accountIban) {
|
||||
app('log')->debug('Check if there is not already an account with this IBAN');
|
||||
$existing = $this->findExistingAccount([AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], ['iban' => $accountIban]);
|
||||
if(null !== $existing) {
|
||||
if (null !== $existing) {
|
||||
$this->destError = (string)trans('validation.deposit_src_iban_exists');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ trait TransferValidation
|
||||
*/
|
||||
protected function validateTransferDestination(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
Log::debug('Now in validateTransferDestination', $array);
|
||||
@@ -65,7 +65,7 @@ trait TransferValidation
|
||||
// must not be the same as the source account
|
||||
if (null !== $this->source && $this->source->id === $this->destination->id) {
|
||||
$this->sourceError = 'Source and destination are the same.';
|
||||
$this->destError = 'Source and destination are the same.';
|
||||
$this->destError = 'Source and destination are the same.';
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -95,9 +95,9 @@ trait TransferValidation
|
||||
*/
|
||||
protected function validateTransferSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountNumber = array_key_exists('number', $array) ? $array['number'] : null;
|
||||
Log::debug('Now in validateTransferSource', $array);
|
||||
// source can be any of the following types.
|
||||
|
||||
@@ -119,10 +119,10 @@ trait WithdrawalValidation
|
||||
}
|
||||
}
|
||||
// if there is an iban, it can only be in use by a revenue account or we will fail.
|
||||
if(null !== $accountIban && '' !== $accountIban) {
|
||||
if (null !== $accountIban && '' !== $accountIban) {
|
||||
app('log')->debug('Check if there is not already an account with this IBAN');
|
||||
$existing = $this->findExistingAccount([AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], ['iban' => $accountIban]);
|
||||
if(null !== $existing) {
|
||||
if (null !== $existing) {
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_iban_exists');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* ValidatesAdministrationAccess.php
|
||||
* Copyright (c) 2023 james@firefly-iii.org
|
||||
@@ -21,6 +21,8 @@ declare(strict_types=1);
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Validation\Administration;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -39,12 +41,12 @@ trait ValidatesAdministrationAccess
|
||||
/**
|
||||
* @param Validator $validator
|
||||
* @param array $allowedRoles
|
||||
*
|
||||
* @return void
|
||||
* @throws AuthenticationException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function validateAdministration(Validator $validator, array $allowedRoles): void
|
||||
{
|
||||
protected function validateAdministration(Validator $validator, array $allowedRoles): void {
|
||||
Log::debug('Now in validateAdministration()');
|
||||
if (!auth()->check()) {
|
||||
Log::error('User is not authenticated.');
|
||||
|
||||
@@ -675,6 +675,7 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencyCode($attribute, $value): bool
|
||||
@@ -686,6 +687,7 @@ class FireflyValidator extends Validator
|
||||
* @param string $field
|
||||
* @param string $attribute
|
||||
* @param string $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrency(string $field, string $attribute, string $value): bool
|
||||
@@ -696,6 +698,7 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencyName($attribute, $value): bool
|
||||
@@ -706,6 +709,7 @@ class FireflyValidator extends Validator
|
||||
/**
|
||||
* @param $attribute
|
||||
* @param $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validateUniqueCurrencySymbol($attribute, $value): bool
|
||||
|
||||
@@ -38,6 +38,7 @@ trait GroupValidation
|
||||
{
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function preventNoAccountInfo(Validator $validator): void
|
||||
@@ -185,7 +186,7 @@ trait GroupValidation
|
||||
return;
|
||||
}
|
||||
$journalId = (int)$journalId;
|
||||
$count = $transactionGroup->transactionJournals()->where('transaction_journals.id', $journalId)->count();
|
||||
$count = $transactionGroup->transactionJournals()->where('transaction_journals.id', $journalId)->count();
|
||||
if (null === $journalId || 0 === $count) {
|
||||
app('log')->warning(sprintf('Transaction group #%d has %d journals with ID %d', $transactionGroup->id, $count, $journalId));
|
||||
app('log')->warning('Invalid submission: Each split must have transaction_journal_id (either valid ID or 0).');
|
||||
|
||||
@@ -169,6 +169,7 @@ trait RecurrenceValidation
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function validateRecurringConfig(Validator $validator)
|
||||
@@ -327,7 +328,8 @@ trait RecurrenceValidation
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function validateTransactionId(Recurrence $recurrence, Validator $validator): void
|
||||
|
||||
@@ -159,6 +159,7 @@ trait TransactionValidation
|
||||
* @param int $index
|
||||
* @param array $source
|
||||
* @param array $destination
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function sanityCheckReconciliation(Validator $validator, string $transactionType, int $index, array $source, array $destination): void
|
||||
@@ -193,6 +194,7 @@ trait TransactionValidation
|
||||
* @param array $transaction
|
||||
* @param string $transactionType
|
||||
* @param int $index
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function sanityCheckForeignCurrency(
|
||||
@@ -293,6 +295,7 @@ trait TransactionValidation
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isLiabilityOrAsset(Account $account): bool
|
||||
@@ -302,6 +305,7 @@ trait TransactionValidation
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isLiability(Account $account): bool
|
||||
@@ -315,6 +319,7 @@ trait TransactionValidation
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isAsset(Account $account): bool
|
||||
@@ -325,6 +330,7 @@ trait TransactionValidation
|
||||
|
||||
/**
|
||||
* @param array $transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasForeignCurrencyInfo(array $transaction): bool
|
||||
@@ -347,8 +353,9 @@ trait TransactionValidation
|
||||
/**
|
||||
* Validates the given account information. Switches on given transaction type.
|
||||
*
|
||||
* @param Validator $validator
|
||||
* @param Validator $validator
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function validateAccountInformationUpdate(Validator $validator, TransactionGroup $transactionGroup): void
|
||||
@@ -403,11 +410,11 @@ trait TransactionValidation
|
||||
array_key_exists('source_number', $transaction)
|
||||
) {
|
||||
Log::debug('Will try to validate source account information.');
|
||||
$sourceId = (int)($transaction['source_id'] ?? 0);
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$sourceIban = $transaction['source_iban'] ?? null;
|
||||
$sourceId = (int)($transaction['source_id'] ?? 0);
|
||||
$sourceName = $transaction['source_name'] ?? null;
|
||||
$sourceIban = $transaction['source_iban'] ?? null;
|
||||
$sourceNumber = $transaction['source_number'] ?? null;
|
||||
$validSource = $accountValidator->validateSource(
|
||||
$validSource = $accountValidator->validateSource(
|
||||
['id' => $sourceId, 'name' => $sourceName, 'iban' => $sourceIban, 'number' => $sourceNumber]
|
||||
);
|
||||
|
||||
@@ -427,7 +434,7 @@ trait TransactionValidation
|
||||
if (
|
||||
array_key_exists('destination_id', $transaction) ||
|
||||
array_key_exists('destination_name', $transaction) ||
|
||||
array_key_exists('destination_iban', $transaction) ||
|
||||
array_key_exists('destination_iban', $transaction) ||
|
||||
array_key_exists('destination_number', $transaction)
|
||||
|
||||
) {
|
||||
@@ -443,12 +450,12 @@ trait TransactionValidation
|
||||
$accountValidator->source = $source;
|
||||
}
|
||||
}
|
||||
$destinationId = (int)($transaction['destination_id'] ?? 0);
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$destinationIban = $transaction['destination_iban'] ?? null;
|
||||
$destinationNumber = $transaction['destination_number'] ?? null;
|
||||
$array = ['id' => $destinationId, 'name' => $destinationName, 'iban' => $destinationIban, 'number' => $destinationNumber];
|
||||
$validDestination = $accountValidator->validateDestination($array);
|
||||
$destinationId = (int)($transaction['destination_id'] ?? 0);
|
||||
$destinationName = $transaction['destination_name'] ?? null;
|
||||
$destinationIban = $transaction['destination_iban'] ?? null;
|
||||
$destinationNumber = $transaction['destination_number'] ?? null;
|
||||
$array = ['id' => $destinationId, 'name' => $destinationName, 'iban' => $destinationIban, 'number' => $destinationNumber];
|
||||
$validDestination = $accountValidator->validateDestination($array);
|
||||
// do something with result:
|
||||
if (false === $validDestination) {
|
||||
app('log')->warning('Looks like the destination account is not valid so complain to the user about it.');
|
||||
@@ -776,8 +783,8 @@ trait TransactionValidation
|
||||
private function compareAccountData(string $type, array $comparison): bool
|
||||
{
|
||||
return match ($type) {
|
||||
default => $this->compareAccountDataWithdrawal($comparison),
|
||||
'deposit' => $this->compareAccountDataDeposit($comparison),
|
||||
default => $this->compareAccountDataWithdrawal($comparison),
|
||||
'deposit' => $this->compareAccountDataDeposit($comparison),
|
||||
'transfer' => $this->compareAccountDataTransfer($comparison),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user