Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
make sure all route binders use guard.
James Cole909dc212fb0f
diff --git a/app/Models/Account.php b/app/Models/Account.phpindex 81ad0d8016..75e97e7cfd 100644--- a/app/Models/Account.php+++ b/app/Models/Account.php@@ -118,11 +118,11 @@ class Account extends Model** @return Account*/- public static function routeBinder(string $value): Account+ public static function routeBinder($guard, string $value): Account{- if (auth()->check()) {+ if ($guard->check()) {$accountId = intval($value);- $account = auth()->user()->accounts()->find($accountId);+ $account = $guard->user()->accounts()->find($accountId);if (!is_null($account)) {return $account;}@@ -290,6 +290,15 @@ class Account extends Modelreturn $journal->date;}+ /**+ * @codeCoverageIgnore+ * Get all of the notes.+ */+ public function notes()+ {+ return $this->morphMany(Note::class, 'noteable');+ }+/*** @return HasMany* @codeCoverageIgnore@@ -345,15 +354,6 @@ class Account extends Model$this->attributes['iban'] = Crypt::encrypt($value);}- /**- * @codeCoverageIgnore- * Get all of the notes.- */- public function notes()- {- return $this->morphMany(Note::class, 'noteable');- }-/*** @codeCoverageIgnore*diff --git a/app/Models/Attachment.php b/app/Models/Attachment.phpindex f78478dde8..5c0b2a841c 100644--- a/app/Models/Attachment.php+++ b/app/Models/Attachment.php@@ -56,11 +56,11 @@ class Attachment extends Model** @return Attachment*/- public static function routeBinder(string $value): Attachment+ public static function routeBinder($guard, string $value): Attachment{- if (auth()->check()) {+ if ($guard->check()) {$attachmentId = intval($value);- $attachment = auth()->user()->attachments()->find($attachmentId);+ $attachment = $guard->user()->attachments()->find($attachmentId);if (!is_null($attachment)) {return $attachment;}diff --git a/app/Models/Bill.php b/app/Models/Bill.phpindex ec09d0fcc7..9b3a94af90 100644--- a/app/Models/Bill.php+++ b/app/Models/Bill.php@@ -73,11 +73,11 @@ class Bill extends Model** @return Bill*/- public static function routeBinder(string $value): Bill+ public static function routeBinder($guard, string $value): Bill{- if (auth()->check()) {+ if ($guard->check()) {$billId = intval($value);- $bill = auth()->user()->bills()->find($billId);+ $bill = $guard->user()->bills()->find($billId);if (!is_null($bill)) {return $bill;}diff --git a/app/Models/Budget.php b/app/Models/Budget.phpindex ba013701ea..05c5928569 100644--- a/app/Models/Budget.php+++ b/app/Models/Budget.php@@ -88,11 +88,11 @@ class Budget extends Model** @return Budget*/- public static function routeBinder(string $value): Budget+ public static function routeBinder($guard, string $value): Budget{- if (auth()->check()) {+ if ($guard->check()) {$budgetId = intval($value);- $budget = auth()->user()->budgets()->find($budgetId);+ $budget = $guard->user()->budgets()->find($budgetId);if (!is_null($budget)) {return $budget;}diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.phpindex 741e2706c3..2738cd1cb0 100644--- a/app/Models/BudgetLimit.php+++ b/app/Models/BudgetLimit.php@@ -49,13 +49,13 @@ class BudgetLimit extends Model** @return mixed*/- public static function routeBinder(string $value): BudgetLimit+ public static function routeBinder($guard, string $value): BudgetLimit{- if (auth()->check()) {+ if ($guard->check()) {$budgetLimitId = intval($value);$budgetLimit = self::where('budget_limits.id', $budgetLimitId)->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')- ->where('budgets.user_id', auth()->user()->id)+ ->where('budgets.user_id', $guard->user()->id)->first(['budget_limits.*']);if (!is_null($budgetLimit)) {return $budgetLimit;diff --git a/app/Models/Category.php b/app/Models/Category.phpindex 38f6e3712d..cdede7e5eb 100644--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -87,11 +87,11 @@ class Category extends Model** @return Category*/- public static function routeBinder(string $value): Category+ public static function routeBinder($guard, string $value): Category{- if (auth()->check()) {+ if ($guard->check()) {$categoryId = intval($value);- $category = auth()->user()->categories()->find($categoryId);+ $category = $guard->user()->categories()->find($categoryId);if (!is_null($category)) {return $category;}diff --git a/app/Models/ExportJob.php b/app/Models/ExportJob.phpindex 629d212b18..6968664ce0 100644--- a/app/Models/ExportJob.php+++ b/app/Models/ExportJob.php@@ -29,7 +29,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;/*** Class ExportJob.*- * @property User $user+ * @property User $user* @property string $key*/class ExportJob extends Model@@ -48,11 +48,11 @@ class ExportJob extends Model** @throws NotFoundHttpException*/- public static function routeBinder(string $value): ExportJob+ public static function routeBinder($guard, string $value): ExportJob{- if (auth()->check()) {+ if ($guard->check()) {$key = trim($value);- $exportJob = auth()->user()->exportJobs()->where('key', $key)->first();+ $exportJob = $guard->user()->exportJobs()->where('key', $key)->first();if (null !== $exportJob) {return $exportJob;}diff --git a/app/Models/ImportJob.php b/app/Models/ImportJob.phpindex 9ad55c7c31..530af07f2e 100644--- a/app/Models/ImportJob.php+++ b/app/Models/ImportJob.php@@ -65,11 +65,11 @@ class ImportJob extends Model* @throws NotFoundHttpException* @throws FireflyException*/- public static function routeBinder($value): ImportJob+ public static function routeBinder($guard, string $value): ImportJob{- if (auth()->check()) {+ if ($guard->check()) {$key = trim($value);- $importJob = auth()->user()->importJobs()->where('key', $key)->first();+ $importJob = $guard->user()->importJobs()->where('key', $key)->first();if (null !== $importJob) {// must have valid status:if (!in_array($importJob->status, $importJob->validStatus)) {diff --git a/app/Models/LinkType.php b/app/Models/LinkType.phpindex 143e30f4e6..6a44ea96e9 100644--- a/app/Models/LinkType.php+++ b/app/Models/LinkType.php@@ -54,9 +54,9 @@ class LinkType extends Model** @throws NotFoundHttpException*/- public static function routeBinder(string $value): LinkType+ public static function routeBinder($guard, string $value): LinkType{- if (auth()->check()) {+ if ($guard->check()) {$linkTypeId = intval($value);$linkType = self::find($linkTypeId);if (null !== $linkType) {diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.phpindex 2140c33b8b..f943398653 100644--- a/app/Models/PiggyBank.php+++ b/app/Models/PiggyBank.php@@ -65,13 +65,13 @@ class PiggyBank extends Model** @return PiggyBank*/- public static function routeBinder(string $value): PiggyBank+ public static function routeBinder($guard, string $value): PiggyBank{- if (auth()->check()) {+ if ($guard->check()) {$piggyBankId = intval($value);$piggyBank = self::where('piggy_banks.id', $piggyBankId)->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')- ->where('accounts.user_id', auth()->user()->id)->first(['piggy_banks.*']);+ ->where('accounts.user_id', $guard->user()->id)->first(['piggy_banks.*']);if (!is_null($piggyBank)) {return $piggyBank;}diff --git a/app/Models/Rule.php b/app/Models/Rule.phpindex a59525674f..b21f1f2147 100644--- a/app/Models/Rule.php+++ b/app/Models/Rule.php@@ -53,11 +53,11 @@ class Rule extends Model** @return Rule*/- public static function routeBinder(string $value): Rule+ public static function routeBinder($guard, string $value): Rule{- if (auth()->check()) {+ if ($guard->check()) {$ruleId = intval($value);- $rule = auth()->user()->rules()->find($ruleId);+ $rule = $guard->user()->rules()->find($ruleId);if (!is_null($rule)) {return $rule;}diff --git a/app/Models/RuleGroup.php b/app/Models/RuleGroup.phpindex c57ebc4ad8..28a15ecead 100644--- a/app/Models/RuleGroup.php+++ b/app/Models/RuleGroup.php@@ -56,11 +56,11 @@ class RuleGroup extends Model** @return RuleGroup*/- public static function routeBinder(string $value): RuleGroup+ public static function routeBinder($guard, string $value): RuleGroup{- if (auth()->check()) {+ if ($guard->check()) {$ruleGroupId = intval($value);- $ruleGroup = auth()->user()->ruleGroups()->find($ruleGroupId);+ $ruleGroup = $guard->user()->ruleGroups()->find($ruleGroupId);if (!is_null($ruleGroup)) {return $ruleGroup;}diff --git a/app/Models/Tag.php b/app/Models/Tag.phpindex 5f70bee39e..81b44ad1e0 100644--- a/app/Models/Tag.php+++ b/app/Models/Tag.php@@ -91,11 +91,11 @@ class Tag extends Model** @return Tag*/- public static function routeBinder(string $value): Tag+ public static function routeBinder($guard, string $value): Tag{- if (auth()->check()) {+ if ($guard->check()) {$tagId = intval($value);- $tag = auth()->user()->tags()->find($tagId);+ $tag = $guard->user()->tags()->find($tagId);if (!is_null($tag)) {return $tag;}diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.phpindex 304b45487f..390dff6906 100644--- a/app/Models/TransactionCurrency.php+++ b/app/Models/TransactionCurrency.php@@ -58,9 +58,9 @@ class TransactionCurrency extends Model** @return TransactionCurrency*/- public static function routeBinder(string $value): TransactionCurrency+ public static function routeBinder($guard, string $value): TransactionCurrency{- if (auth()->check()) {+ if ($guard->check()) {$currencyId = intval($value);$currency = self::find($currencyId);if (!is_null($currency)) {diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex 985ee14906..9cc480fcf4 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -86,11 +86,11 @@ class TransactionJournal extends Model** @return TransactionJournal*/- public static function routeBinder(string $value): TransactionJournal+ public static function routeBinder($guard, string $value): TransactionJournal{- if (auth()->check()) {+ if ($guard->check()) {$journalId = intval($value);- $journal = auth()->user()->transactionJournals()->where('transaction_journals.id', $journalId)+ $journal = $guard->user()->transactionJournals()->where('transaction_journals.id', $journalId)->first(['transaction_journals.*']);if (!is_null($journal)) {return $journal;diff --git a/app/Models/TransactionJournalLink.php b/app/Models/TransactionJournalLink.phpindex 8d216cc8ae..1154b85187 100644--- a/app/Models/TransactionJournalLink.php+++ b/app/Models/TransactionJournalLink.php@@ -44,15 +44,15 @@ class TransactionJournalLink extends Model** @throws NotFoundHttpException*/- public static function routeBinder(string $value): TransactionJournalLink+ public static function routeBinder($guard, string $value): TransactionJournalLink{- if (auth()->check()) {+ if ($guard->check()) {$linkId = intval($value);$link = self::where('journal_links.id', $linkId)->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id')->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id')- ->where('t_a.user_id', auth()->user()->id)- ->where('t_b.user_id', auth()->user()->id)+ ->where('t_a.user_id', $guard->user()->id)+ ->where('t_b.user_id', $guard->user()->id)->first(['journal_links.*']);if (!is_null($link)) {return $link;diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.phpindex 5fd8972049..a803fc4e1e 100644--- a/app/Models/TransactionType.php+++ b/app/Models/TransactionType.php@@ -72,9 +72,9 @@ class TransactionType extends Model** @return Model|null|static*/- public static function routeBinder(string $type)+ public static function routeBinder($guard, string $type): TransactionType{- if (!auth()->check()) {+ if (!$guard->check()) {throw new NotFoundHttpException();}$transactionType = self::where('type', ucfirst($type))->first();diff --git a/app/Support/Binder/AccountList.php b/app/Support/Binder/AccountList.phpindex 78be7c6e38..208b1488a7 100644--- a/app/Support/Binder/AccountList.php+++ b/app/Support/Binder/AccountList.php@@ -39,9 +39,9 @@ class AccountList implements BinderInterface** @return Collection*/- public static function routeBinder(string $value, Route $route): Collection+ public static function routeBinder($guard, string $value, Route $route): Collection{- if (auth()->check()) {+ if ($guard->check()) {$list = [];$incoming = explode(',', $value);foreach ($incoming as $entry) {@@ -53,7 +53,7 @@ class AccountList implements BinderInterface}/** @var \Illuminate\Support\Collection $collection */- $collection = auth()->user()->accounts()+ $collection = $guard->user()->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')->whereIn('accounts.id', $list)->get(['accounts.*']);diff --git a/app/Support/Binder/BinderInterface.php b/app/Support/Binder/BinderInterface.phpindex 3488867ba1..f16c1d9a0c 100644--- a/app/Support/Binder/BinderInterface.php+++ b/app/Support/Binder/BinderInterface.php@@ -35,5 +35,5 @@ interface BinderInterface** @return mixed*/- public static function routeBinder(string $value, Route $route);+ public static function routeBinder($guard, string $value, Route $route);}diff --git a/app/Support/Binder/BudgetList.php b/app/Support/Binder/BudgetList.phpindex f02cd32765..d5f442d84b 100644--- a/app/Support/Binder/BudgetList.php+++ b/app/Support/Binder/BudgetList.php@@ -38,9 +38,9 @@ class BudgetList implements BinderInterface** @return Collection*/- public static function routeBinder(string $value, Route $route): Collection+ public static function routeBinder($guard, string $value, Route $route): Collection{- if (auth()->check()) {+ if ($guard->check()) {$list = [];$incoming = explode(',', $value);foreach ($incoming as $entry) {@@ -52,7 +52,7 @@ class BudgetList implements BinderInterface}/** @var \Illuminate\Support\Collection $collection */- $collection = auth()->user()->budgets()+ $collection = $guard->user()->budgets()->where('active', 1)->whereIn('id', $list)->get();diff --git a/app/Support/Binder/CategoryList.php b/app/Support/Binder/CategoryList.phpindex 3ce93ce553..dfe38433e4 100644--- a/app/Support/Binder/CategoryList.php+++ b/app/Support/Binder/CategoryList.php@@ -38,9 +38,9 @@ class CategoryList implements BinderInterface** @return Collection*/- public static function routeBinder(string $value, Route $route): Collection+ public static function routeBinder($guard, string $value, Route $route): Collection{- if (auth()->check()) {+ if ($guard->check()) {$list = [];$incoming = explode(',', $value);foreach ($incoming as $entry) {@@ -52,7 +52,7 @@ class CategoryList implements BinderInterface}/** @var \Illuminate\Support\Collection $collection */- $collection = auth()->user()->categories()+ $collection = $guard->user()->categories()->whereIn('id', $list)->get();diff --git a/app/Support/Binder/CurrencyCode.php b/app/Support/Binder/CurrencyCode.phpindex e142ee83a6..102087df43 100644--- a/app/Support/Binder/CurrencyCode.php+++ b/app/Support/Binder/CurrencyCode.php@@ -37,9 +37,9 @@ class CurrencyCode implements BinderInterface** @return TransactionCurrency*/- public static function routeBinder(string $value, Route $route): TransactionCurrency+ public static function routeBinder($guard, string $value, Route $route): TransactionCurrency{- if (auth()->check()) {+ if ($guard->check()) {$currency = TransactionCurrency::where('code', trim($value))->first();if (null !== $currency) {return $currency;diff --git a/app/Support/Binder/Date.php b/app/Support/Binder/Date.phpindex 5b04cfbd54..ce4fa4c96e 100644--- a/app/Support/Binder/Date.php+++ b/app/Support/Binder/Date.php@@ -40,7 +40,7 @@ class Date implements BinderInterface** @return Carbon*/- public static function routeBinder(string $value, Route $route): Carbon+ public static function routeBinder($guard, string $value, Route $route): Carbon{/** @var FiscalHelperInterface $fiscalHelper */$fiscalHelper = app(FiscalHelperInterface::class);diff --git a/app/Support/Binder/JournalList.php b/app/Support/Binder/JournalList.phpindex ee556f9907..ef4d67cca6 100644--- a/app/Support/Binder/JournalList.php+++ b/app/Support/Binder/JournalList.php@@ -37,9 +37,9 @@ class JournalList implements BinderInterface** @return mixed*/- public static function routeBinder(string $value, Route $route): Collection+ public static function routeBinder($guard, string $value, Route $route): Collection{- if (auth()->check()) {+ if ($guard->check()) {$list = [];$incoming = explode(',', $value);foreach ($incoming as $entry) {@@ -51,7 +51,7 @@ class JournalList implements BinderInterface}/** @var \Illuminate\Support\Collection $collection */- $collection = auth()->user()->transactionJournals()+ $collection = $guard->user()->transactionJournals()->whereIn('transaction_journals.id', $list)->where('transaction_journals.completed', 1)->get(['transaction_journals.*']);diff --git a/app/Support/Binder/TagList.php b/app/Support/Binder/TagList.phpindex 8cf851c9dc..b3d8ef98a0 100644--- a/app/Support/Binder/TagList.php+++ b/app/Support/Binder/TagList.php@@ -39,9 +39,9 @@ class TagList implements BinderInterface** @return Collection*/- public static function routeBinder(string $value, Route $route): Collection+ public static function routeBinder($guard, string $value, Route $route): Collection{- if (auth()->check()) {+ if ($guard->check()) {$list = [];$incoming = explode(',', $value);foreach ($incoming as $entry) {@@ -53,7 +53,8 @@ class TagList implements BinderInterface}/** @var TagRepositoryInterface $repository */$repository = app(TagRepositoryInterface::class);- $allTags = $repository->get();+ $repository->setUser($guard->user());+ $allTags = $repository->get();$collection = $allTags->filter(function (Tag $tag) use ($list) {diff --git a/app/Support/Binder/UnfinishedJournal.php b/app/Support/Binder/UnfinishedJournal.phpindex 92d03ac75f..703d26d156 100644--- a/app/Support/Binder/UnfinishedJournal.php+++ b/app/Support/Binder/UnfinishedJournal.php@@ -37,13 +37,13 @@ class UnfinishedJournal implements BinderInterface** @return TransactionJournal*/- public static function routeBinder(string $value, Route $route): TransactionJournal+ public static function routeBinder($guard, string $value, Route $route): TransactionJournal{- if (auth()->check()) {- $journal = auth()->user()->transactionJournals()->where('transaction_journals.id', $value)+ if ($guard->check()) {+ $journal = $guard->user()->transactionJournals()->where('transaction_journals.id', $value)->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->where('completed', 0)- ->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);+ ->where('user_id', $guard->user()->id)->first(['transaction_journals.*']);if (!is_null($journal)) {return $journal;}diff --git a/app/User.php b/app/User.phpindex 8745fe5cbf..a06badc51b 100644--- a/app/User.php+++ b/app/User.php@@ -63,13 +63,14 @@ class User extends Authenticatableprotected $table = 'users';/**+ * @param $guard* @param string $value** @return User*/- public static function routeBinder(string $value): User+ public static function routeBinder($guard, string $value): User{- if (auth()->check()) {+ if ($guard->check()) {$userId = intval($value);$user = self::find($userId);if (!is_null($user)) {