From 4230349c0736f548c15617082536f23dd962a40f Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 29 Dec 2023 20:25:32 +0100 Subject: [PATCH] Fix https://github.com/firefly-iii/firefly-iii/issues/8304 --- .../Controllers/Webhook/AttemptController.php | 2 + .../Controllers/Webhook/DestroyController.php | 3 ++ .../Controllers/Webhook/MessageController.php | 2 + .../V1/Controllers/Webhook/ShowController.php | 3 ++ .../Controllers/Webhook/StoreController.php | 1 + .../Controllers/Webhook/SubmitController.php | 1 + .../Controllers/Webhook/UpdateController.php | 1 + .../List/TransactionController.php | 1 - .../Collector/Extensions/MetaCollection.php | 41 +++++++++++++++++-- .../Collector/GroupCollectorInterface.php | 7 +++- app/Helpers/Report/NetWorth.php | 6 +-- .../Controllers/Webhooks/CreateController.php | 1 + .../Controllers/Webhooks/DeleteController.php | 1 + .../Controllers/Webhooks/EditController.php | 1 + .../Controllers/Webhooks/IndexController.php | 1 + .../Controllers/Webhooks/ShowController.php | 1 + app/Repositories/Tag/OperationsRepository.php | 5 +-- .../Budget/AvailableBudgetRepository.php | 5 ++- app/Support/Binder/TagList.php | 5 +++ app/Support/Search/OperatorQuerySearch.php | 2 +- 20 files changed, 75 insertions(+), 15 deletions(-) diff --git a/app/Api/V1/Controllers/Webhook/AttemptController.php b/app/Api/V1/Controllers/Webhook/AttemptController.php index abda6e93a3..d8e0346937 100644 --- a/app/Api/V1/Controllers/Webhook/AttemptController.php +++ b/app/Api/V1/Controllers/Webhook/AttemptController.php @@ -72,6 +72,7 @@ class AttemptController extends Controller } if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User lists webhook attempts of webhook #%d and message #%d, but webhooks are DISABLED.', $webhook->id, $message->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info(sprintf('User lists webhook attempts of webhook #%d and message #%d.', $webhook->id, $message->id)); @@ -115,6 +116,7 @@ class AttemptController extends Controller if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User views single webhook attempt #%d of webhook #%d and message #%d, but webhooks are DISABLED', $attempt->id, $webhook->id, $message->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } diff --git a/app/Api/V1/Controllers/Webhook/DestroyController.php b/app/Api/V1/Controllers/Webhook/DestroyController.php index 43f1fcd11c..464272eb69 100644 --- a/app/Api/V1/Controllers/Webhook/DestroyController.php +++ b/app/Api/V1/Controllers/Webhook/DestroyController.php @@ -64,6 +64,7 @@ class DestroyController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to destroy webhook #%d. but webhooks are DISABLED.', $webhook->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } @@ -93,6 +94,7 @@ class DestroyController extends Controller if (false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to destroy webhook #%d, message #%d, attempt #%d, but webhooks are DISABLED.', $webhook->id, $message->id, $attempt->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } @@ -120,6 +122,7 @@ class DestroyController extends Controller if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to destroy webhook #%d, message #%d, but webhooks are DISABLED.', $webhook->id, $message->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info(sprintf('User destroys webhook #%d, message #%d.', $webhook->id, $message->id)); diff --git a/app/Api/V1/Controllers/Webhook/MessageController.php b/app/Api/V1/Controllers/Webhook/MessageController.php index 88a53e98c8..e175b4cd4c 100644 --- a/app/Api/V1/Controllers/Webhook/MessageController.php +++ b/app/Api/V1/Controllers/Webhook/MessageController.php @@ -68,6 +68,7 @@ class MessageController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to view messages of webhook #%d, but webhooks are DISABLED.', $webhook->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info(sprintf('User views messages of webhook #%d.', $webhook->id)); @@ -107,6 +108,7 @@ class MessageController extends Controller } if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to view message #%d of webhook #%d, but webhooks are DISABLED.', $message->id, $webhook->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } diff --git a/app/Api/V1/Controllers/Webhook/ShowController.php b/app/Api/V1/Controllers/Webhook/ShowController.php index 34945a09be..51420700ed 100644 --- a/app/Api/V1/Controllers/Webhook/ShowController.php +++ b/app/Api/V1/Controllers/Webhook/ShowController.php @@ -73,6 +73,7 @@ class ShowController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info('User tries to view all webhooks, but webhooks are DISABLED.'); + throw new NotFoundHttpException('Webhooks are not enabled.'); } @@ -107,6 +108,7 @@ class ShowController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to view webhook #%d, but webhooks are DISABLED.', $webhook->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } @@ -131,6 +133,7 @@ class ShowController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to trigger webhook #%d on transaction group #%d, but webhooks are DISABLED.', $webhook->id, $group->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } diff --git a/app/Api/V1/Controllers/Webhook/StoreController.php b/app/Api/V1/Controllers/Webhook/StoreController.php index aed4847ee9..9d11cdeeb3 100644 --- a/app/Api/V1/Controllers/Webhook/StoreController.php +++ b/app/Api/V1/Controllers/Webhook/StoreController.php @@ -62,6 +62,7 @@ class StoreController extends Controller $data = $request->getData(); if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info('User tries to store new webhook, but webhooks are DISABLED.', $data); + throw new NotFoundHttpException('Webhooks are not enabled.'); } diff --git a/app/Api/V1/Controllers/Webhook/SubmitController.php b/app/Api/V1/Controllers/Webhook/SubmitController.php index b65b3edcc4..fa69057366 100644 --- a/app/Api/V1/Controllers/Webhook/SubmitController.php +++ b/app/Api/V1/Controllers/Webhook/SubmitController.php @@ -59,6 +59,7 @@ class SubmitController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to submit webhook #%d, but webhooks are DISABLED.', $webhook->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } diff --git a/app/Api/V1/Controllers/Webhook/UpdateController.php b/app/Api/V1/Controllers/Webhook/UpdateController.php index 3e81b0ee09..2131b14bb8 100644 --- a/app/Api/V1/Controllers/Webhook/UpdateController.php +++ b/app/Api/V1/Controllers/Webhook/UpdateController.php @@ -62,6 +62,7 @@ class UpdateController extends Controller $data = $request->getData(); if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User tries to update webhook #%d, but webhooks are DISABLED.', $webhook->id), $data); + throw new NotFoundHttpException('Webhooks are not enabled.'); } diff --git a/app/Api/V2/Controllers/Transaction/List/TransactionController.php b/app/Api/V2/Controllers/Transaction/List/TransactionController.php index 417ce0481f..db23b4df73 100644 --- a/app/Api/V2/Controllers/Transaction/List/TransactionController.php +++ b/app/Api/V2/Controllers/Transaction/List/TransactionController.php @@ -34,7 +34,6 @@ use Illuminate\Http\JsonResponse; */ class TransactionController extends Controller { - public function list(ListRequest $request): JsonResponse { // collect transactions: diff --git a/app/Helpers/Collector/Extensions/MetaCollection.php b/app/Helpers/Collector/Extensions/MetaCollection.php index e082a635cf..bac8a27838 100644 --- a/app/Helpers/Collector/Extensions/MetaCollection.php +++ b/app/Helpers/Collector/Extensions/MetaCollection.php @@ -670,11 +670,11 @@ trait MetaCollection } /** - * Limit results to a specific set of tags. + * Limit results to a SPECIFIC set of tags. */ - public function setTags(Collection $tags): GroupCollectorInterface + public function setAllTags(Collection $tags): GroupCollectorInterface { - Log::debug(sprintf('Now in setTags(%d tag(s))', $tags->count())); + Log::debug(sprintf('Now in setAllTags(%d tag(s))', $tags->count())); $this->withTagInformation(); $this->query->whereNotNull('tag_transaction_journal.tag_id'); @@ -682,7 +682,7 @@ trait MetaCollection $list = $tags->pluck('tag')->toArray(); $list = array_map('strtolower', $list); $filter = static function (array $object) use ($list): bool { - Log::debug(sprintf('Now in setTags(%s) filter', implode(', ', $list))); + Log::debug(sprintf('Now in setAllTags(%s) filter', implode(', ', $list))); $expectedTagCount = count($list); $foundTagCount = 0; foreach ($object['transactions'] as $transaction) { @@ -711,6 +711,39 @@ trait MetaCollection return $this; } + /** + * Limit results to any of the tags in the list. + */ + public function setTags(Collection $tags): GroupCollectorInterface + { + Log::debug(sprintf('Now in setTags(%d tag(s))', $tags->count())); + $this->withTagInformation(); + $this->query->whereNotNull('tag_transaction_journal.tag_id'); + + // this method adds a "postFilter" to the collector. + $list = $tags->pluck('tag')->toArray(); + $list = array_map('strtolower', $list); + $filter = static function (array $object) use ($list): bool { + Log::debug(sprintf('Now in setTags(%s) filter', implode(', ', $list))); + foreach ($object['transactions'] as $transaction) { + foreach ($transaction['tags'] as $tag) { + Log::debug(sprintf('"%s" versus', strtolower($tag['name'])), $list); + if (in_array(strtolower($tag['name']), $list, true)) { + app('log')->debug(sprintf('Transaction has tag "%s" so return true.', $tag['name'])); + + return true; + } + } + } + app('log')->debug('Transaction has no tags from the list, so return false.'); + + return false; + }; + $this->postFilters[] = $filter; + + return $this; + } + /** * Without tags */ diff --git a/app/Helpers/Collector/GroupCollectorInterface.php b/app/Helpers/Collector/GroupCollectorInterface.php index 2f6db27897..232a09aa82 100644 --- a/app/Helpers/Collector/GroupCollectorInterface.php +++ b/app/Helpers/Collector/GroupCollectorInterface.php @@ -559,10 +559,15 @@ interface GroupCollectorInterface public function setTag(Tag $tag): self; /** - * Limit results to a specific set of tags. + * Limit results to any of the specified tags. */ public function setTags(Collection $tags): self; + /** + * Limit results to a SPECIFIC set of tags. + */ + public function setAllTags(Collection $tags): self; + /** * Limit the search to one specific transaction group. */ diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.php index dc647abad8..700097b263 100644 --- a/app/Helpers/Report/NetWorth.php +++ b/app/Helpers/Report/NetWorth.php @@ -51,7 +51,7 @@ class NetWorth implements NetWorthInterface private CurrencyRepositoryInterface $currencyRepos; private User $user; - private null | UserGroup $userGroup; + private null|UserGroup $userGroup; /** * This method collects the user's net worth in ALL the user's currencies @@ -144,7 +144,7 @@ class NetWorth implements NetWorthInterface return $netWorth; } - public function setUser(null | Authenticatable | User $user): void + public function setUser(null|Authenticatable|User $user): void { if (!$user instanceof User) { return; @@ -202,7 +202,7 @@ class NetWorth implements NetWorthInterface return $return; } - private function getRepository(): AccountRepositoryInterface | AdminAccountRepositoryInterface + private function getRepository(): AccountRepositoryInterface|AdminAccountRepositoryInterface { if (null === $this->userGroup) { return $this->accountRepository; diff --git a/app/Http/Controllers/Webhooks/CreateController.php b/app/Http/Controllers/Webhooks/CreateController.php index fe34a8a19b..f1922eb220 100644 --- a/app/Http/Controllers/Webhooks/CreateController.php +++ b/app/Http/Controllers/Webhooks/CreateController.php @@ -61,6 +61,7 @@ class CreateController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info('User visits webhook create page, but webhooks are DISABLED.'); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info('User visits webhook create page.'); diff --git a/app/Http/Controllers/Webhooks/DeleteController.php b/app/Http/Controllers/Webhooks/DeleteController.php index 7b1f303494..9de635f6f5 100644 --- a/app/Http/Controllers/Webhooks/DeleteController.php +++ b/app/Http/Controllers/Webhooks/DeleteController.php @@ -65,6 +65,7 @@ class DeleteController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info('User visits webhook delete page, but webhooks are DISABLED.'); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info('User visits webhook delete page.'); diff --git a/app/Http/Controllers/Webhooks/EditController.php b/app/Http/Controllers/Webhooks/EditController.php index 42547978bc..3173c44327 100644 --- a/app/Http/Controllers/Webhooks/EditController.php +++ b/app/Http/Controllers/Webhooks/EditController.php @@ -64,6 +64,7 @@ class EditController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info('User visits webhook edit page, but webhooks are DISABLED.'); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info('User visits webhook edit page.'); diff --git a/app/Http/Controllers/Webhooks/IndexController.php b/app/Http/Controllers/Webhooks/IndexController.php index 0060615604..3ef74dff77 100644 --- a/app/Http/Controllers/Webhooks/IndexController.php +++ b/app/Http/Controllers/Webhooks/IndexController.php @@ -57,6 +57,7 @@ class IndexController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info('User visits webhook index page, but webhooks are DISABLED.'); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info('User visits webhook index page.'); diff --git a/app/Http/Controllers/Webhooks/ShowController.php b/app/Http/Controllers/Webhooks/ShowController.php index 993178a5ec..db7f6d25fa 100644 --- a/app/Http/Controllers/Webhooks/ShowController.php +++ b/app/Http/Controllers/Webhooks/ShowController.php @@ -64,6 +64,7 @@ class ShowController extends Controller { if(false === config('firefly.allow_webhooks')) { Log::channel('audit')->info(sprintf('User visits webhook #%d page, but webhooks are DISABLED.', $webhook->id)); + throw new NotFoundHttpException('Webhooks are not enabled.'); } Log::channel('audit')->info(sprintf('User visits webhook #%d page.', $webhook->id)); diff --git a/app/Repositories/Tag/OperationsRepository.php b/app/Repositories/Tag/OperationsRepository.php index 113c7f07fd..0458de3901 100644 --- a/app/Repositories/Tag/OperationsRepository.php +++ b/app/Repositories/Tag/OperationsRepository.php @@ -36,8 +36,7 @@ use Illuminate\Support\Collection; */ class OperationsRepository implements OperationsRepositoryInterface { - /** @var User */ - private $user; + private User $user; /** * This method returns a list of all the withdrawal transaction journals (as arrays) set in that period @@ -58,7 +57,7 @@ class OperationsRepository implements OperationsRepositoryInterface if (null === $tags || 0 === $tags->count()) { $collector->setTags($this->getTags()); } - $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation()->withTagInformation(); + $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation(); $journals = $collector->getExtractedJournals(); $array = []; $listedJournals = []; diff --git a/app/Repositories/UserGroups/Budget/AvailableBudgetRepository.php b/app/Repositories/UserGroups/Budget/AvailableBudgetRepository.php index 50c6b43510..66a8e7b4e1 100644 --- a/app/Repositories/UserGroups/Budget/AvailableBudgetRepository.php +++ b/app/Repositories/UserGroups/Budget/AvailableBudgetRepository.php @@ -44,8 +44,9 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface $converter = new ExchangeRateConverter(); $default = app('amount')->getDefaultCurrency(); $availableBudgets = $this->userGroup->availableBudgets() - ->where('start_date', $start->format('Y-m-d')) - ->where('end_date', $end->format('Y-m-d'))->get(); + ->where('start_date', $start->format('Y-m-d')) + ->where('end_date', $end->format('Y-m-d'))->get() + ; /** @var AvailableBudget $availableBudget */ foreach ($availableBudgets as $availableBudget) { diff --git a/app/Support/Binder/TagList.php b/app/Support/Binder/TagList.php index c8f9cc475d..649a9025f6 100644 --- a/app/Support/Binder/TagList.php +++ b/app/Support/Binder/TagList.php @@ -27,6 +27,7 @@ use FireflyIII\Models\Tag; use FireflyIII\Repositories\Tag\TagRepositoryInterface; use Illuminate\Routing\Route; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -63,9 +64,13 @@ class TagList implements BinderInterface $collection = $allTags->filter( static function (Tag $tag) use ($list) { if (in_array(strtolower($tag->tag), $list, true)) { + Log::debug(sprintf('TagList: (string) found tag #%d ("%s") in list.', $tag->id, $tag->tag)); + return true; } if (in_array((string)$tag->id, $list, true)) { + Log::debug(sprintf('TagList: (id) found tag #%d ("%s") in list.', $tag->id, $tag->tag)); + return true; } diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 797268ac94..e8138faef8 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -2754,7 +2754,7 @@ class OperatorQuerySearch implements SearchInterface $collection->push($tag); } } - $this->collector->setTags($collection); + $this->collector->setAllTags($collection); } } }