make sure all route binders use guard.

This commit is contained in:
James Cole 2018-02-07 11:15:36 +01:00
parent eacc1da157
commit 909dc212fb
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
27 changed files with 86 additions and 84 deletions

View File

@ -118,11 +118,11 @@ class Account extends Model
* *
* @return Account * @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); $accountId = intval($value);
$account = auth()->user()->accounts()->find($accountId); $account = $guard->user()->accounts()->find($accountId);
if (!is_null($account)) { if (!is_null($account)) {
return $account; return $account;
} }
@ -290,6 +290,15 @@ class Account extends Model
return $journal->date; return $journal->date;
} }
/**
* @codeCoverageIgnore
* Get all of the notes.
*/
public function notes()
{
return $this->morphMany(Note::class, 'noteable');
}
/** /**
* @return HasMany * @return HasMany
* @codeCoverageIgnore * @codeCoverageIgnore
@ -345,15 +354,6 @@ class Account extends Model
$this->attributes['iban'] = Crypt::encrypt($value); $this->attributes['iban'] = Crypt::encrypt($value);
} }
/**
* @codeCoverageIgnore
* Get all of the notes.
*/
public function notes()
{
return $this->morphMany(Note::class, 'noteable');
}
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
* *

View File

@ -56,11 +56,11 @@ class Attachment extends Model
* *
* @return Attachment * @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); $attachmentId = intval($value);
$attachment = auth()->user()->attachments()->find($attachmentId); $attachment = $guard->user()->attachments()->find($attachmentId);
if (!is_null($attachment)) { if (!is_null($attachment)) {
return $attachment; return $attachment;
} }

View File

@ -73,11 +73,11 @@ class Bill extends Model
* *
* @return Bill * @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); $billId = intval($value);
$bill = auth()->user()->bills()->find($billId); $bill = $guard->user()->bills()->find($billId);
if (!is_null($bill)) { if (!is_null($bill)) {
return $bill; return $bill;
} }

View File

@ -88,11 +88,11 @@ class Budget extends Model
* *
* @return Budget * @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); $budgetId = intval($value);
$budget = auth()->user()->budgets()->find($budgetId); $budget = $guard->user()->budgets()->find($budgetId);
if (!is_null($budget)) { if (!is_null($budget)) {
return $budget; return $budget;
} }

View File

@ -49,13 +49,13 @@ class BudgetLimit extends Model
* *
* @return mixed * @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); $budgetLimitId = intval($value);
$budgetLimit = self::where('budget_limits.id', $budgetLimitId) $budgetLimit = self::where('budget_limits.id', $budgetLimitId)
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id') ->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.*']); ->first(['budget_limits.*']);
if (!is_null($budgetLimit)) { if (!is_null($budgetLimit)) {
return $budgetLimit; return $budgetLimit;

View File

@ -87,11 +87,11 @@ class Category extends Model
* *
* @return Category * @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); $categoryId = intval($value);
$category = auth()->user()->categories()->find($categoryId); $category = $guard->user()->categories()->find($categoryId);
if (!is_null($category)) { if (!is_null($category)) {
return $category; return $category;
} }

View File

@ -48,11 +48,11 @@ class ExportJob extends Model
* *
* @throws NotFoundHttpException * @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); $key = trim($value);
$exportJob = auth()->user()->exportJobs()->where('key', $key)->first(); $exportJob = $guard->user()->exportJobs()->where('key', $key)->first();
if (null !== $exportJob) { if (null !== $exportJob) {
return $exportJob; return $exportJob;
} }

View File

@ -65,11 +65,11 @@ class ImportJob extends Model
* @throws NotFoundHttpException * @throws NotFoundHttpException
* @throws FireflyException * @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); $key = trim($value);
$importJob = auth()->user()->importJobs()->where('key', $key)->first(); $importJob = $guard->user()->importJobs()->where('key', $key)->first();
if (null !== $importJob) { if (null !== $importJob) {
// must have valid status: // must have valid status:
if (!in_array($importJob->status, $importJob->validStatus)) { if (!in_array($importJob->status, $importJob->validStatus)) {

View File

@ -54,9 +54,9 @@ class LinkType extends Model
* *
* @throws NotFoundHttpException * @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); $linkTypeId = intval($value);
$linkType = self::find($linkTypeId); $linkType = self::find($linkTypeId);
if (null !== $linkType) { if (null !== $linkType) {

View File

@ -65,13 +65,13 @@ class PiggyBank extends Model
* *
* @return PiggyBank * @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); $piggyBankId = intval($value);
$piggyBank = self::where('piggy_banks.id', $piggyBankId) $piggyBank = self::where('piggy_banks.id', $piggyBankId)
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id') ->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)) { if (!is_null($piggyBank)) {
return $piggyBank; return $piggyBank;
} }

View File

@ -53,11 +53,11 @@ class Rule extends Model
* *
* @return Rule * @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); $ruleId = intval($value);
$rule = auth()->user()->rules()->find($ruleId); $rule = $guard->user()->rules()->find($ruleId);
if (!is_null($rule)) { if (!is_null($rule)) {
return $rule; return $rule;
} }

View File

@ -56,11 +56,11 @@ class RuleGroup extends Model
* *
* @return RuleGroup * @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); $ruleGroupId = intval($value);
$ruleGroup = auth()->user()->ruleGroups()->find($ruleGroupId); $ruleGroup = $guard->user()->ruleGroups()->find($ruleGroupId);
if (!is_null($ruleGroup)) { if (!is_null($ruleGroup)) {
return $ruleGroup; return $ruleGroup;
} }

View File

@ -91,11 +91,11 @@ class Tag extends Model
* *
* @return Tag * @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); $tagId = intval($value);
$tag = auth()->user()->tags()->find($tagId); $tag = $guard->user()->tags()->find($tagId);
if (!is_null($tag)) { if (!is_null($tag)) {
return $tag; return $tag;
} }

View File

@ -58,9 +58,9 @@ class TransactionCurrency extends Model
* *
* @return TransactionCurrency * @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); $currencyId = intval($value);
$currency = self::find($currencyId); $currency = self::find($currencyId);
if (!is_null($currency)) { if (!is_null($currency)) {

View File

@ -86,11 +86,11 @@ class TransactionJournal extends Model
* *
* @return TransactionJournal * @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); $journalId = intval($value);
$journal = auth()->user()->transactionJournals()->where('transaction_journals.id', $journalId) $journal = $guard->user()->transactionJournals()->where('transaction_journals.id', $journalId)
->first(['transaction_journals.*']); ->first(['transaction_journals.*']);
if (!is_null($journal)) { if (!is_null($journal)) {
return $journal; return $journal;

View File

@ -44,15 +44,15 @@ class TransactionJournalLink extends Model
* *
* @throws NotFoundHttpException * @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); $linkId = intval($value);
$link = self::where('journal_links.id', $linkId) $link = self::where('journal_links.id', $linkId)
->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id') ->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id')
->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id') ->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id')
->where('t_a.user_id', auth()->user()->id) ->where('t_a.user_id', $guard->user()->id)
->where('t_b.user_id', auth()->user()->id) ->where('t_b.user_id', $guard->user()->id)
->first(['journal_links.*']); ->first(['journal_links.*']);
if (!is_null($link)) { if (!is_null($link)) {
return $link; return $link;

View File

@ -72,9 +72,9 @@ class TransactionType extends Model
* *
* @return Model|null|static * @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(); throw new NotFoundHttpException();
} }
$transactionType = self::where('type', ucfirst($type))->first(); $transactionType = self::where('type', ucfirst($type))->first();

View File

@ -39,9 +39,9 @@ class AccountList implements BinderInterface
* *
* @return Collection * @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 = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
@ -53,7 +53,7 @@ class AccountList implements BinderInterface
} }
/** @var \Illuminate\Support\Collection $collection */ /** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->accounts() $collection = $guard->user()->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereIn('accounts.id', $list) ->whereIn('accounts.id', $list)
->get(['accounts.*']); ->get(['accounts.*']);

View File

@ -35,5 +35,5 @@ interface BinderInterface
* *
* @return mixed * @return mixed
*/ */
public static function routeBinder(string $value, Route $route); public static function routeBinder($guard, string $value, Route $route);
} }

View File

@ -38,9 +38,9 @@ class BudgetList implements BinderInterface
* *
* @return Collection * @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 = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
@ -52,7 +52,7 @@ class BudgetList implements BinderInterface
} }
/** @var \Illuminate\Support\Collection $collection */ /** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->budgets() $collection = $guard->user()->budgets()
->where('active', 1) ->where('active', 1)
->whereIn('id', $list) ->whereIn('id', $list)
->get(); ->get();

View File

@ -38,9 +38,9 @@ class CategoryList implements BinderInterface
* *
* @return Collection * @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 = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
@ -52,7 +52,7 @@ class CategoryList implements BinderInterface
} }
/** @var \Illuminate\Support\Collection $collection */ /** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->categories() $collection = $guard->user()->categories()
->whereIn('id', $list) ->whereIn('id', $list)
->get(); ->get();

View File

@ -37,9 +37,9 @@ class CurrencyCode implements BinderInterface
* *
* @return TransactionCurrency * @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(); $currency = TransactionCurrency::where('code', trim($value))->first();
if (null !== $currency) { if (null !== $currency) {
return $currency; return $currency;

View File

@ -40,7 +40,7 @@ class Date implements BinderInterface
* *
* @return Carbon * @return Carbon
*/ */
public static function routeBinder(string $value, Route $route): Carbon public static function routeBinder($guard, string $value, Route $route): Carbon
{ {
/** @var FiscalHelperInterface $fiscalHelper */ /** @var FiscalHelperInterface $fiscalHelper */
$fiscalHelper = app(FiscalHelperInterface::class); $fiscalHelper = app(FiscalHelperInterface::class);

View File

@ -37,9 +37,9 @@ class JournalList implements BinderInterface
* *
* @return mixed * @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 = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
@ -51,7 +51,7 @@ class JournalList implements BinderInterface
} }
/** @var \Illuminate\Support\Collection $collection */ /** @var \Illuminate\Support\Collection $collection */
$collection = auth()->user()->transactionJournals() $collection = $guard->user()->transactionJournals()
->whereIn('transaction_journals.id', $list) ->whereIn('transaction_journals.id', $list)
->where('transaction_journals.completed', 1) ->where('transaction_journals.completed', 1)
->get(['transaction_journals.*']); ->get(['transaction_journals.*']);

View File

@ -39,9 +39,9 @@ class TagList implements BinderInterface
* *
* @return Collection * @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 = []; $list = [];
$incoming = explode(',', $value); $incoming = explode(',', $value);
foreach ($incoming as $entry) { foreach ($incoming as $entry) {
@ -53,6 +53,7 @@ class TagList implements BinderInterface
} }
/** @var TagRepositoryInterface $repository */ /** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class); $repository = app(TagRepositoryInterface::class);
$repository->setUser($guard->user());
$allTags = $repository->get(); $allTags = $repository->get();
$collection = $allTags->filter( $collection = $allTags->filter(

View File

@ -37,13 +37,13 @@ class UnfinishedJournal implements BinderInterface
* *
* @return TransactionJournal * @return TransactionJournal
*/ */
public static function routeBinder(string $value, Route $route): TransactionJournal public static function routeBinder($guard, string $value, Route $route): TransactionJournal
{ {
if (auth()->check()) { if ($guard->check()) {
$journal = auth()->user()->transactionJournals()->where('transaction_journals.id', $value) $journal = $guard->user()->transactionJournals()->where('transaction_journals.id', $value)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->where('completed', 0) ->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)) { if (!is_null($journal)) {
return $journal; return $journal;
} }

View File

@ -63,13 +63,14 @@ class User extends Authenticatable
protected $table = 'users'; protected $table = 'users';
/** /**
* @param $guard
* @param string $value * @param string $value
* *
* @return User * @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); $userId = intval($value);
$user = self::find($userId); $user = self::find($userId);
if (!is_null($user)) { if (!is_null($user)) {