mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-03 19:28:40 +00:00
Various fixes and checks.
This commit is contained in:
@@ -24,8 +24,14 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Rules;
|
||||
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
/**
|
||||
@@ -71,7 +77,40 @@ class IsValidAttachmentModel implements Rule
|
||||
if (!auth()->check()) {
|
||||
return false;
|
||||
}
|
||||
$model = false === strpos('FireflyIII', $this->model) ? 'FireflyIII\\Models\\' . $this->model : $this->model;
|
||||
|
||||
if (Bill::class === $model) {
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$repository->setUser($user);
|
||||
$bill = $repository->find((int)$value);
|
||||
|
||||
return null !== $bill;
|
||||
}
|
||||
|
||||
if (ImportJob::class === $model) {
|
||||
/** @var ImportJobRepositoryInterface $repository */
|
||||
$repository = app(ImportJobRepositoryInterface::class);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$repository->setUser($user);
|
||||
$importJob = $repository->find((int)$value);
|
||||
|
||||
return null !== $importJob;
|
||||
}
|
||||
|
||||
if (Transaction::class === $model) {
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$repository->setUser($user);
|
||||
$transaction = $repository->findTransaction((int)$value);
|
||||
|
||||
return null !== $transaction;
|
||||
}
|
||||
|
||||
if (TransactionJournal::class === $this->model) {
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
|
Reference in New Issue
Block a user