mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Various fixes and checks.
This commit is contained in:
@@ -25,6 +25,7 @@ namespace FireflyIII\Api\V1\Requests;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Rules\IsValidAttachmentModel;
|
||||
|
||||
@@ -72,7 +73,7 @@ class AttachmentRequest extends Request
|
||||
str_replace('FireflyIII\\Models\\', '', Bill::class),
|
||||
str_replace('FireflyIII\\Models\\', '', ImportJob::class),
|
||||
str_replace('FireflyIII\\Models\\', '', TransactionJournal::class),
|
||||
str_replace('FireflyIII\\Models\\', '', ImportJob::class),
|
||||
str_replace('FireflyIII\\Models\\', '', Transaction::class),
|
||||
]
|
||||
);
|
||||
$model = $this->string('model');
|
||||
|
@@ -23,8 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\User;
|
||||
use Log;
|
||||
|
||||
@@ -33,6 +36,9 @@ use Log;
|
||||
*/
|
||||
class AttachmentFactory
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
@@ -42,22 +48,34 @@ class AttachmentFactory
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
||||
}
|
||||
}
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Attachment|null
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function create(array $data): ?Attachment
|
||||
{
|
||||
// append if necessary.
|
||||
$model = false === strpos('FireflyIII', $data['model']) ? 'FireflyIII\\Models\\' . $data['model'] : $data['model'];
|
||||
|
||||
if (Transaction::class === $model) {
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $this->user->transactions()->find((int)$data['model_id']);
|
||||
if (null === $transaction) {
|
||||
throw new FireflyException('Unexpectedly could not find transaction');
|
||||
}
|
||||
$data['model_id'] = $transaction->transaction_journal_id;
|
||||
$model = TransactionJournal::class;
|
||||
}
|
||||
|
||||
// create attachment:
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'attachable_id' => $data['model_id'],
|
||||
'attachable_type' => $data['model'],
|
||||
'attachable_type' => $model,
|
||||
'md5' => '',
|
||||
'filename' => $data['filename'],
|
||||
'title' => '' === $data['title'] ? null : $data['title'],
|
||||
|
@@ -252,8 +252,8 @@ class BillController extends Controller
|
||||
// simply fire off all rules?
|
||||
/** @var TransactionMatcher $matcher */
|
||||
$matcher = app(TransactionMatcher::class);
|
||||
$matcher->setLimit(100000); // large upper limit
|
||||
$matcher->setRange(100000); // large upper limit
|
||||
$matcher->setSearchLimit(100000); // large upper limit
|
||||
$matcher->setTriggeredLimit(100000); // large upper limit
|
||||
$matcher->setRule($rule);
|
||||
$matchingTransactions = $matcher->findTransactionsByRule();
|
||||
$total += $matchingTransactions->count();
|
||||
|
@@ -154,6 +154,16 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
throw new FireflyException('Could not create an import job with a unique key after 30 tries.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $jobId
|
||||
*
|
||||
* @return ImportJob|null
|
||||
*/
|
||||
public function find(int $jobId): ?ImportJob
|
||||
{
|
||||
return $this->user->importJobs()->find($jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
|
@@ -69,6 +69,13 @@ interface ImportJobRepositoryInterface
|
||||
*/
|
||||
public function create(string $importProvider): ImportJob;
|
||||
|
||||
/**
|
||||
* @param int $jobId
|
||||
*
|
||||
* @return ImportJob|null
|
||||
*/
|
||||
public function find(int $jobId): ?ImportJob;
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
|
@@ -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);
|
||||
|
@@ -65,7 +65,7 @@ class TransactionLinkTransformer extends AbstractTransformer
|
||||
'updated_at' => $link->updated_at->toAtomString(),
|
||||
'inward_id' => $link->source_id,
|
||||
'outward_id' => $link->destination_id,
|
||||
'notes' => $notes,
|
||||
'notes' => '' === $notes ? null : $notes,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
|
Reference in New Issue
Block a user