mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-25 08:21:08 -06:00
make sure all route binders use guard.
This commit is contained in:
parent
eacc1da157
commit
909dc212fb
@ -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 Model
|
||||
return $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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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.*']);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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.*']);
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -63,13 +63,14 @@ class User extends Authenticatable
|
||||
protected $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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user