mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
make sure all route binders use guard.
This commit is contained in:
@@ -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();
|
||||
|
Reference in New Issue
Block a user