James Cole 2023-12-29 20:25:32 +01:00
parent 33b95b9371
commit 4230349c07
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
20 changed files with 75 additions and 15 deletions

View File

@ -72,6 +72,7 @@ class AttemptController extends Controller
} }
if(false === config('firefly.allow_webhooks')) { 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)); 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.'); 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)); 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')) { 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)); 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.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }

View File

@ -64,6 +64,7 @@ class DestroyController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info(sprintf('User tries to destroy webhook #%d. but webhooks are DISABLED.', $webhook->id)); Log::channel('audit')->info(sprintf('User tries to destroy webhook #%d. but webhooks are DISABLED.', $webhook->id));
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
@ -93,6 +94,7 @@ class DestroyController extends Controller
if (false === config('firefly.allow_webhooks')) { 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)); 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.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
@ -120,6 +122,7 @@ class DestroyController extends Controller
if(false === config('firefly.allow_webhooks')) { 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)); 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.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
Log::channel('audit')->info(sprintf('User destroys webhook #%d, message #%d.', $webhook->id, $message->id)); Log::channel('audit')->info(sprintf('User destroys webhook #%d, message #%d.', $webhook->id, $message->id));

View File

@ -68,6 +68,7 @@ class MessageController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { 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)); 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.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
Log::channel('audit')->info(sprintf('User views messages of webhook #%d.', $webhook->id)); 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')) { 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)); 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.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }

View File

@ -73,6 +73,7 @@ class ShowController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info('User tries to view all webhooks, but webhooks are DISABLED.'); Log::channel('audit')->info('User tries to view all webhooks, but webhooks are DISABLED.');
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
@ -107,6 +108,7 @@ class ShowController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info(sprintf('User tries to view webhook #%d, but webhooks are DISABLED.', $webhook->id)); Log::channel('audit')->info(sprintf('User tries to view webhook #%d, but webhooks are DISABLED.', $webhook->id));
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
@ -131,6 +133,7 @@ class ShowController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { 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)); 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.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }

View File

@ -62,6 +62,7 @@ class StoreController extends Controller
$data = $request->getData(); $data = $request->getData();
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info('User tries to store new webhook, but webhooks are DISABLED.', $data); Log::channel('audit')->info('User tries to store new webhook, but webhooks are DISABLED.', $data);
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }

View File

@ -59,6 +59,7 @@ class SubmitController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info(sprintf('User tries to submit webhook #%d, but webhooks are DISABLED.', $webhook->id)); Log::channel('audit')->info(sprintf('User tries to submit webhook #%d, but webhooks are DISABLED.', $webhook->id));
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }

View File

@ -62,6 +62,7 @@ class UpdateController extends Controller
$data = $request->getData(); $data = $request->getData();
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info(sprintf('User tries to update webhook #%d, but webhooks are DISABLED.', $webhook->id), $data); 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.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }

View File

@ -34,7 +34,6 @@ use Illuminate\Http\JsonResponse;
*/ */
class TransactionController extends Controller class TransactionController extends Controller
{ {
public function list(ListRequest $request): JsonResponse public function list(ListRequest $request): JsonResponse
{ {
// collect transactions: // collect transactions:

View File

@ -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->withTagInformation();
$this->query->whereNotNull('tag_transaction_journal.tag_id'); $this->query->whereNotNull('tag_transaction_journal.tag_id');
@ -682,7 +682,7 @@ trait MetaCollection
$list = $tags->pluck('tag')->toArray(); $list = $tags->pluck('tag')->toArray();
$list = array_map('strtolower', $list); $list = array_map('strtolower', $list);
$filter = static function (array $object) use ($list): bool { $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); $expectedTagCount = count($list);
$foundTagCount = 0; $foundTagCount = 0;
foreach ($object['transactions'] as $transaction) { foreach ($object['transactions'] as $transaction) {
@ -711,6 +711,39 @@ trait MetaCollection
return $this; 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 * Without tags
*/ */

View File

@ -559,10 +559,15 @@ interface GroupCollectorInterface
public function setTag(Tag $tag): self; 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; 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. * Limit the search to one specific transaction group.
*/ */

View File

@ -51,7 +51,7 @@ class NetWorth implements NetWorthInterface
private CurrencyRepositoryInterface $currencyRepos; private CurrencyRepositoryInterface $currencyRepos;
private User $user; 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 * This method collects the user's net worth in ALL the user's currencies
@ -144,7 +144,7 @@ class NetWorth implements NetWorthInterface
return $netWorth; return $netWorth;
} }
public function setUser(null | Authenticatable | User $user): void public function setUser(null|Authenticatable|User $user): void
{ {
if (!$user instanceof User) { if (!$user instanceof User) {
return; return;
@ -202,7 +202,7 @@ class NetWorth implements NetWorthInterface
return $return; return $return;
} }
private function getRepository(): AccountRepositoryInterface | AdminAccountRepositoryInterface private function getRepository(): AccountRepositoryInterface|AdminAccountRepositoryInterface
{ {
if (null === $this->userGroup) { if (null === $this->userGroup) {
return $this->accountRepository; return $this->accountRepository;

View File

@ -61,6 +61,7 @@ class CreateController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info('User visits webhook create page, but webhooks are DISABLED.'); Log::channel('audit')->info('User visits webhook create page, but webhooks are DISABLED.');
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
Log::channel('audit')->info('User visits webhook create page.'); Log::channel('audit')->info('User visits webhook create page.');

View File

@ -65,6 +65,7 @@ class DeleteController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info('User visits webhook delete page, but webhooks are DISABLED.'); Log::channel('audit')->info('User visits webhook delete page, but webhooks are DISABLED.');
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
Log::channel('audit')->info('User visits webhook delete page.'); Log::channel('audit')->info('User visits webhook delete page.');

View File

@ -64,6 +64,7 @@ class EditController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info('User visits webhook edit page, but webhooks are DISABLED.'); Log::channel('audit')->info('User visits webhook edit page, but webhooks are DISABLED.');
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
Log::channel('audit')->info('User visits webhook edit page.'); Log::channel('audit')->info('User visits webhook edit page.');

View File

@ -57,6 +57,7 @@ class IndexController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info('User visits webhook index page, but webhooks are DISABLED.'); Log::channel('audit')->info('User visits webhook index page, but webhooks are DISABLED.');
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
Log::channel('audit')->info('User visits webhook index page.'); Log::channel('audit')->info('User visits webhook index page.');

View File

@ -64,6 +64,7 @@ class ShowController extends Controller
{ {
if(false === config('firefly.allow_webhooks')) { if(false === config('firefly.allow_webhooks')) {
Log::channel('audit')->info(sprintf('User visits webhook #%d page, but webhooks are DISABLED.', $webhook->id)); Log::channel('audit')->info(sprintf('User visits webhook #%d page, but webhooks are DISABLED.', $webhook->id));
throw new NotFoundHttpException('Webhooks are not enabled.'); throw new NotFoundHttpException('Webhooks are not enabled.');
} }
Log::channel('audit')->info(sprintf('User visits webhook #%d page.', $webhook->id)); Log::channel('audit')->info(sprintf('User visits webhook #%d page.', $webhook->id));

View File

@ -36,8 +36,7 @@ use Illuminate\Support\Collection;
*/ */
class OperationsRepository implements OperationsRepositoryInterface class OperationsRepository implements OperationsRepositoryInterface
{ {
/** @var User */ private User $user;
private $user;
/** /**
* This method returns a list of all the withdrawal transaction journals (as arrays) set in that period * 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()) { if (null === $tags || 0 === $tags->count()) {
$collector->setTags($this->getTags()); $collector->setTags($this->getTags());
} }
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation()->withTagInformation(); $collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$array = []; $array = [];
$listedJournals = []; $listedJournals = [];

View File

@ -44,8 +44,9 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
$default = app('amount')->getDefaultCurrency(); $default = app('amount')->getDefaultCurrency();
$availableBudgets = $this->userGroup->availableBudgets() $availableBudgets = $this->userGroup->availableBudgets()
->where('start_date', $start->format('Y-m-d')) ->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->get(); ->where('end_date', $end->format('Y-m-d'))->get()
;
/** @var AvailableBudget $availableBudget */ /** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) { foreach ($availableBudgets as $availableBudget) {

View File

@ -27,6 +27,7 @@ use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Routing\Route; use Illuminate\Routing\Route;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
@ -63,9 +64,13 @@ class TagList implements BinderInterface
$collection = $allTags->filter( $collection = $allTags->filter(
static function (Tag $tag) use ($list) { static function (Tag $tag) use ($list) {
if (in_array(strtolower($tag->tag), $list, true)) { 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; return true;
} }
if (in_array((string)$tag->id, $list, 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; return true;
} }

View File

@ -2754,7 +2754,7 @@ class OperatorQuerySearch implements SearchInterface
$collection->push($tag); $collection->push($tag);
} }
} }
$this->collector->setTags($collection); $this->collector->setAllTags($collection);
} }
} }
} }