Skip to content

Commit

Permalink
Add more IBAN filters
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed May 18, 2024
1 parent 0b63ba2 commit cd7ddd1
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Api/V1/Requests/Models/Account/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getAllAccountData(): array
'order' => $this->convertInteger('order'),
'currency_code' => $this->convertString('currency_code'),
'virtual_balance' => $this->convertString('virtual_balance'),
'iban' => $this->convertString('iban'),
'iban' => $this->convertIban('iban'),
'BIC' => $this->convertString('bic'),
'account_number' => $this->convertString('account_number'),
'account_role' => $this->convertString('account_role'),
Expand Down
2 changes: 1 addition & 1 deletion app/Api/V1/Requests/Models/Account/UpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getUpdateData(): array
'include_net_worth' => ['include_net_worth', 'boolean'],
'account_type_name' => ['type', 'convertString'],
'virtual_balance' => ['virtual_balance', 'convertString'],
'iban' => ['iban', 'convertString'],
'iban' => ['iban', 'convertIban'],
'BIC' => ['bic', 'convertString'],
'account_number' => ['account_number', 'convertString'],
'account_role' => ['account_role', 'convertString'],
Expand Down
4 changes: 2 additions & 2 deletions app/Api/V1/Requests/Models/Transaction/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ private function getTransactionData(): array
// source of transaction. If everything is null, assume cash account.
'source_id' => $this->integerFromValue((string)$object['source_id']),
'source_name' => $this->clearString((string)$object['source_name']),
'source_iban' => $this->clearString((string)$object['source_iban']),
'source_iban' => $this->clearIban((string)$object['source_iban']),
'source_number' => $this->clearString((string)$object['source_number']),
'source_bic' => $this->clearString((string)$object['source_bic']),

// destination of transaction. If everything is null, assume cash account.
'destination_id' => $this->integerFromValue((string)$object['destination_id']),
'destination_name' => $this->clearString((string)$object['destination_name']),
'destination_iban' => $this->clearString((string)$object['destination_iban']),
'destination_iban' => $this->clearIban((string)$object['destination_iban']),
'destination_number' => $this->clearString((string)$object['destination_number']),
'destination_bic' => $this->clearString((string)$object['destination_bic']),

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/AccountFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getAccountData(): array
'account_type_name' => $this->convertString('objectType'),
'currency_id' => $this->convertInteger('currency_id'),
'virtual_balance' => $this->convertString('virtual_balance'),
'iban' => $this->convertString('iban'),
'iban' => $this->convertIban('iban'),
'BIC' => $this->convertString('BIC'),
'account_number' => $this->convertString('account_number'),
'account_role' => $this->convertString('account_role'),
Expand Down
2 changes: 2 additions & 0 deletions app/Repositories/Account/AccountRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use FireflyIII\Models\TransactionType;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
use FireflyIII\Services\Internal\Update\AccountUpdateService;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
Expand Down Expand Up @@ -123,6 +124,7 @@ static function (EloquentBuilder $q1) use ($number): void { // @phpstan-ignore-l

public function findByIbanNull(string $iban, array $types): ?Account
{
$iban = Steam::filterSpaces($iban);
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');

if (0 !== count($types)) {
Expand Down
2 changes: 2 additions & 0 deletions app/Repositories/UserGroups/Account/AccountRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Services\Internal\Update\AccountUpdateService;
use FireflyIII\Support\Facades\Steam;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -80,6 +81,7 @@ static function (EloquentBuilder $q1) use ($number): void { // @phpstan-ignore-l

public function findByIbanNull(string $iban, array $types): ?Account
{
$iban = Steam::filterSpaces($iban);
$query = $this->userGroup->accounts()->where('iban', '!=', '')->whereNotNull('iban');

if (0 !== count($types)) {
Expand Down
5 changes: 5 additions & 0 deletions app/Rules/UniqueIban.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Support\Facades\Steam;
use Illuminate\Contracts\Validation\ValidationRule;

/**
Expand Down Expand Up @@ -95,6 +96,10 @@ public function passes($attribute, $value): bool
$maxCounts = $this->getMaxOccurrences();

foreach ($maxCounts as $type => $max) {

// make sure to trim the value of $value so all spaces are removed.
$value = Steam::filterSpaces($value);

$count = $this->countHits($type, $value);
app('log')->debug(sprintf('Count for "%s" and IBAN "%s" is %d', $type, $value, $count));
if ($count > $max) {
Expand Down
12 changes: 12 additions & 0 deletions app/Support/Request/ConvertsDataTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Carbon\Exceptions\InvalidDateException;
use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface;
use FireflyIII\Support\Facades\Steam;
use Illuminate\Support\Collection;

/**
Expand Down Expand Up @@ -114,6 +115,11 @@ public function convertString(string $field): string
return (string)$this->clearString((string)$entry);
}

public function convertIban(string $field): string
{
return Steam::filterSpaces($this->convertString($field));
}

public function clearString(?string $string): ?string
{
$string = $this->clearStringKeepNewlines($string);
Expand All @@ -131,6 +137,12 @@ public function clearString(?string $string): ?string
return trim($string);
}

public function clearIban(?string $string): ?string
{
$string = $this->clearString($string);
return Steam::filterSpaces($string);
}

public function clearStringKeepNewlines(?string $string): ?string
{
if (null === $string) {
Expand Down
4 changes: 3 additions & 1 deletion app/Support/Steam.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,13 @@ public function filterSpaces(string $string): string
"\u{202F}", // narrow no-break space
"\u{3000}", // ideographic space
"\u{FEFF}", // zero width no -break space
"\x20", // plain old normal space
"\x20", // plain old normal space,
' '
];

// clear zalgo text
$string = preg_replace('/(\pM{2})\pM+/u', '\1', $string);
$string = preg_replace('/\s+/', '', $string);

return str_replace($search, '', $string);
}
Expand Down
1 change: 1 addition & 0 deletions app/Validation/FireflyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public function validateIban(mixed $attribute, mixed $value): bool
"\u{202F}", // narrow no-break space
"\u{3000}", // ideographic space
"\u{FEFF}", // zero width no -break space
' ',
'-',
'?',
];
Expand Down

0 comments on commit cd7ddd1

Please sign in to comment.