Skip to content

Firefly III: a personal finances manager

Add some todo's, and fix some issues.

James Coleff81245a2fcd
diff --git a/app/Api/V1/Requests/Models/BudgetLimit/StoreRequest.php b/app/Api/V1/Requests/Models/BudgetLimit/StoreRequest.php
index 6703df8783..def8bae449 100644
--- a/app/Api/V1/Requests/Models/BudgetLimit/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/BudgetLimit/StoreRequest.php
@@ -71,8 +71,8 @@ class StoreRequest extends FormRequest
public function rules(): array
{
return [
- 'start' => ['required', 'before:end', 'date'],
- 'end' => ['required', 'after:start', 'date'],
+ 'start' => ['required', 'before:end', 'date', 'after:1970-01-02', 'before:2038-01-17'],
+ 'end' => ['required', 'after:start', 'date', 'after:1970-01-02', 'before:2038-01-17'],
'amount' => ['required', new IsValidPositiveAmount()],
'currency_id' => ['numeric', 'exists:transaction_currencies,id'],
'currency_code' => ['min:3', 'max:51', 'exists:transaction_currencies,code'],
diff --git a/app/Helpers/Collector/Extensions/TimeCollection.php b/app/Helpers/Collector/Extensions/TimeCollection.php
index d2786ec3be..a0e592ec67 100644
--- a/app/Helpers/Collector/Extensions/TimeCollection.php
+++ b/app/Helpers/Collector/Extensions/TimeCollection.php
@@ -26,6 +26,8 @@ namespace FireflyIII\Helpers\Collector\Extensions;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
+use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
+use Illuminate\Database\Query\Builder;
/**
* Trait TimeCollection
@@ -65,7 +67,7 @@ trait TimeCollection
if ($end < $start) {
[$start, $end] = [$end, $start];
}
- $end = clone $end; // this is so weird, but it works if $end and $start secretly point to the same object.
+ $end = clone $end; // this is so weird, but it works if $end and $start secretly point to the same object.
$end->endOfDay();
$start->startOfDay();
$this->withMetaDate($field);
@@ -106,9 +108,11 @@ trait TimeCollection
}
$startStr = $start->format('Y-m-d 00:00:00');
$endStr = $end->format('Y-m-d 23:59:59');
+ $this->query->where(function (EloquentBuilder $q) use ($startStr, $endStr) {
+ $q->where('transaction_journals.date', '<', $startStr);
+ $q->orWhere('transaction_journals.date', '>', $endStr);
+ });
- $this->query->where('transaction_journals.date', '<', $startStr);
- $this->query->orWhere('transaction_journals.date', '>', $endStr);
return $this;
}
@@ -119,7 +123,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $day): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $transaction[$field]->day >= (int) $day;
+ return $transaction[$field]->day >= (int)$day;
}
}
@@ -136,7 +140,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $day): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $transaction[$field]->day <= (int) $day;
+ return $transaction[$field]->day <= (int)$day;
}
}
@@ -153,7 +157,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $day): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return (int) $day === $transaction[$field]->day;
+ return (int)$day === $transaction[$field]->day;
}
}
@@ -170,7 +174,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $day): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return (int) $day !== $transaction[$field]->day;
+ return (int)$day !== $transaction[$field]->day;
}
}
@@ -187,7 +191,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $month): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $transaction[$field]->month >= (int) $month;
+ return $transaction[$field]->month >= (int)$month;
}
}
@@ -204,7 +208,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $month): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $transaction[$field]->month <= (int) $month;
+ return $transaction[$field]->month <= (int)$month;
}
}
@@ -221,7 +225,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $month): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return (int) $month === $transaction[$field]->month;
+ return (int)$month === $transaction[$field]->month;
}
}
@@ -238,7 +242,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $month): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return (int) $month !== $transaction[$field]->month;
+ return (int)$month !== $transaction[$field]->month;
}
}
@@ -255,7 +259,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $year): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $transaction[$field]->year >= (int) $year;
+ return $transaction[$field]->year >= (int)$year;
}
}
@@ -272,7 +276,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $year): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $transaction[$field]->year <= (int) $year;
+ return $transaction[$field]->year <= (int)$year;
}
}
@@ -289,7 +293,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $year): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $year === (string) $transaction[$field]->year;
+ return $year === (string)$transaction[$field]->year;
}
}
@@ -306,7 +310,7 @@ trait TimeCollection
$filter = static function (array $object) use ($field, $year): bool {
foreach ($object['transactions'] as $transaction) {
if (array_key_exists($field, $transaction) && $transaction[$field] instanceof Carbon) {
- return $year !== (string) $transaction[$field]->year;
+ return $year !== (string)$transaction[$field]->year;
}
}
@@ -517,7 +521,7 @@ trait TimeCollection
if ($end < $start) {
[$start, $end] = [$end, $start];
}
- $end = clone $end; // this is so weird, but it works if $end and $start secretly point to the same object.
+ $end = clone $end; // this is so weird, but it works if $end and $start secretly point to the same object.
$end->endOfDay();
$start->startOfDay();
$this->withMetaDate($field);
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php
index 67b4badf71..fe4871616f 100644
--- a/app/Http/Controllers/Auth/LoginController.php
+++ b/app/Http/Controllers/Auth/LoginController.php
@@ -102,8 +102,7 @@ final class LoginController extends Controller
$this->fireLockoutEvent($request);
$seconds = $this->limiter()->availableIn($this->throttleKey($request));
$message = (string) trans('auth.throttle', ['seconds' => $seconds, 'minutes' => ceil($seconds / 60)]);
- Log::error(sprintf('Will SLEEP for %d second(s).', $seconds));
- sleep($seconds);
+ sleep(5);
throw new LockedOutException($message);
}
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 415cd5331a..dc12fbb9f2 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -34,6 +34,7 @@ use FireflyIII\Http\Middleware\Installer;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Support\Facades\Preferences;
+use FireflyIII\TransactionRules\Engine\CustomExpressionLanguage;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
diff --git a/app/Http/Controllers/Json/RecurrenceController.php b/app/Http/Controllers/Json/RecurrenceController.php
index 848eafd0cf..60ed58bb1e 100644
--- a/app/Http/Controllers/Json/RecurrenceController.php
+++ b/app/Http/Controllers/Json/RecurrenceController.php
@@ -94,11 +94,12 @@ final class RecurrenceController extends Controller
$endsAt = (string) $request->input('ends');
$repetitionType = explode(',', (string) $request->input('type'))[0];
$repetitions = (int) $request->input('reps');
+ $repetitions = clamp($repetitions,1,100);
$weekend = (int) $request->input('weekend');
$repetitionMoment = '';
$skip = (int) $request->input('skip');
- $skip = $skip < 0 || $skip > 31 ? 0 : $skip;
- $weekend = $weekend < 1 || $weekend > 4 ? 1 : $weekend;
+ $skip = clamp($skip,0,31);
+ $weekend = clamp($weekend,1,4);
$start = session()->get('start');
diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php
index a040c37027..47b17e9fe5 100644
--- a/app/Http/Controllers/SearchController.php
+++ b/app/Http/Controllers/SearchController.php
@@ -62,6 +62,7 @@ final class SearchController extends Controller
{
// search params:
$fullQuery = $request->input('search');
+ $fullQuery = substr($fullQuery, 0, 500);
if (is_array($request->input('search'))) {
$fullQuery = '';
}
diff --git a/app/Models/RuleAction.php b/app/Models/RuleAction.php
index 28245d8410..2929cd396b 100644
--- a/app/Models/RuleAction.php
+++ b/app/Models/RuleAction.php
@@ -51,6 +51,7 @@ class RuleAction extends Model
$expr = new ActionExpression($this->action_value);
try {
+ $journal['date'] = $journal['date']->toW3cString();
$result = $expr->evaluate($journal);
} catch (SyntaxError $e) {
Log::error(sprintf('Expression engine failed to evaluate expression "%s" with error "%s".', $this->action_value, $e->getMessage()));
diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.php
index 2cb871e0a8..b67dfc8f3e 100644
--- a/app/Repositories/Recurring/RecurringRepository.php
+++ b/app/Repositories/Recurring/RecurringRepository.php
@@ -382,6 +382,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
*/
public function getXOccurrences(RecurrenceRepetition $repetition, Carbon $date, int $count): array
{
+ $count = clamp($count, 1,100);
$skipMod = $repetition->repetition_skip + 1;
$occurrences = [];
if ('daily' === $repetition->repetition_type) {
diff --git a/app/Support/Models/AvailableBudgetCalculator.php b/app/Support/Models/AvailableBudgetCalculator.php
index 32c380f93f..f113309b22 100644
--- a/app/Support/Models/AvailableBudgetCalculator.php
+++ b/app/Support/Models/AvailableBudgetCalculator.php
@@ -73,8 +73,16 @@ class AvailableBudgetCalculator
Log::debug(sprintf('Limit period is from %s to %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
// from the start until the end of the budget limit, need to loop!
+ $count = 0;
+ $max = 14_600; // 40 years in days.
$current = clone $start;
while ($current <= $end) {
+ if ($count > $max) {
+ Log::error(sprintf('Count %d is greater than max %d, stop.', $count, $max));
+
+ return;
+ }
+ $count++;
$this->refreshAvailableBudget($current);
$current = Navigation::addPeriod($current, $this->viewRange);
}
diff --git a/app/Support/Search/AccountSearch.php b/app/Support/Search/AccountSearch.php
index d95335befc..6c347e1f8f 100644
--- a/app/Support/Search/AccountSearch.php
+++ b/app/Support/Search/AccountSearch.php
@@ -64,17 +64,19 @@ class AccountSearch implements GenericSearchInterface
switch ($this->field) {
default:
case self::SEARCH_ALL:
- $searchQuery->where(static function (Builder $q) use ($like): void {
- $q->whereLike('accounts.id', $like);
- $q->orWhereLike('accounts.name', $like);
- $q->orWhereLike('accounts.iban', $like);
+ $searchQuery->where(static function (Builder $q1) use ($like, $originalQuery): void {
+ $q1->where(static function (Builder $q2) use ($like): void {
+ $q2->whereLike('accounts.id', $like);
+ $q2->orWhereLike('accounts.name', $like);
+ $q2->orWhereLike('accounts.iban', $like);
});
// meta data:
- $searchQuery->orWhere(static function (Builder $q) use ($originalQuery): void {
+ $q1->orWhere(static function (Builder $q3) use ($originalQuery): void {
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
- $q->where('account_meta.name', '=', 'account_number');
- $q->whereLike('account_meta.data', $json);
+ $q3->where('account_meta.name', '=', 'account_number');
+ $q3->whereLike('account_meta.data', $json);
});
+ });
break;
@@ -95,7 +97,7 @@ class AccountSearch implements GenericSearchInterface
case self::SEARCH_NUMBER:
// meta data:
- $searchQuery->Where(static function (Builder $q) use ($originalQuery): void {
+ $searchQuery->where(static function (Builder $q) use ($originalQuery): void {
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
$q->where('account_meta.name', 'account_number');
$q->where('account_meta.data', $json);
diff --git a/app/Support/Search/QueryParser/QueryParser.php b/app/Support/Search/QueryParser/QueryParser.php
index 9e6c3ea690..d08c494d8c 100644
--- a/app/Support/Search/QueryParser/QueryParser.php
+++ b/app/Support/Search/QueryParser/QueryParser.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Search\QueryParser;
+use LogicException;
use SensitiveParameter;
use function Safe\preg_split;
@@ -36,13 +37,19 @@ use function Safe\preg_split;
class QueryParser implements QueryParserInterface
{
private int $position = 0;
- private string $query;
+ private int $depth = 0;
+ private const int MAX_DEPTH = 32;
+ // private string $query;
+ private array $chrArray = [];
+ private int $count = 0;
public function parse(string $query): NodeGroup
{
// Log::debug(sprintf('Parsing query in QueryParser: "%s"', $query));
- $this->query = $query;
+ // $this->query = $query;
$this->position = 0;
+ $this->chrArray = preg_split('//u', $query, -1, PREG_SPLIT_NO_EMPTY);
+ $this->count = count($this->chrArray);
return $this->buildNodeGroup(false);
}
@@ -53,12 +60,10 @@ class QueryParser implements QueryParserInterface
$inQuotes = false;
$fieldName = '';
$prohibited = false;
- $chrArray = preg_split('//u', $this->query, -1, PREG_SPLIT_NO_EMPTY);
- $count = count($chrArray);
- while ($this->position < $count) {
- $char = $chrArray[$this->position];
- $nextChar = $chrArray[$this->position + 1] ?? '';
- $prevChar = $chrArray[$this->position - 1] ?? '';
+ while ($this->position < $this->count) {
+ $char = $this->chrArray[$this->position];
+ $nextChar = $this->chrArray[$this->position + 1] ?? '';
+ $prevChar = $this->chrArray[$this->position - 1] ?? '';
// Log::debug(sprintf('Char #%d: %s', $this->position, $char));
// If we're in a quoted string, we treat all characters except another quote as ordinary characters
@@ -112,10 +117,15 @@ class QueryParser implements QueryParserInterface
case '(':
if ('' === $tokenUnderConstruction) {
+ if ($this->depth >= self::MAX_DEPTH) {
+ throw new LogicException('Subquery nesting is too deep.');
+ }
// A left parentheses at the beginning of a token indicates the start of a subquery
++$this->position;
-
- return new NodeResult($this->buildNodeGroup(true, $prohibited), false);
+ ++$this->depth;
+ $group = $this->buildNodeGroup(true, $prohibited);
+ --$this->depth;
+ return new NodeResult($group, false);
}
// In any other location, it's just a normal character
$tokenUnderConstruction .= $char;
diff --git a/app/TransactionRules/Expressions/ActionExpression.php b/app/TransactionRules/Expressions/ActionExpression.php
index 88eb7b7634..18f3270707 100644
--- a/app/TransactionRules/Expressions/ActionExpression.php
+++ b/app/TransactionRules/Expressions/ActionExpression.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Expressions;
use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\TransactionRules\Engine\CustomExpressionLanguage;
use Illuminate\Support\Facades\Log;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\SyntaxError;
@@ -83,14 +84,14 @@ class ActionExpression
// 'destination_transaction_id',
'notes',
];
- private readonly ExpressionLanguage $expressionLanguage;
+ private readonly CustomExpressionLanguage $expressionLanguage;
private readonly bool $isExpression;
private readonly ?SyntaxError $validationError;
public function __construct(
private readonly string $expr
) {
- $this->expressionLanguage = app(ExpressionLanguage::class);
+ $this->expressionLanguage = app(CustomExpressionLanguage::class);
$this->isExpression = $this->isExpression($this->expr);
$this->validationError = $this->validate();
diff --git a/resources/views/administrations/edit.blade.php b/resources/views/administrations/edit.blade.php
index 978cf46d28..4298bddd73 100644
--- a/resources/views/administrations/edit.blade.php
+++ b/resources/views/administrations/edit.blade.php
@@ -49,7 +49,11 @@
</div>
<div class="card-body">
<x-form.alpine.title value="administration.title" />
+
+ TODO currency
+
<Title :value=administration.title :error="errors.title" v-on:input="administration.title = $event"></Title>
+
<UserGroupCurrency :value=administration.currency_id :error="errors.currency_id"
v-on:input="administration.currency_id = $event"></UserGroupCurrency>
</div>