mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-29 02:11:12 -06:00
Fixed a bug where certain types of accounts could not be validated.
This commit is contained in:
parent
72166743fa
commit
a4d8bbe3da
@ -2,18 +2,17 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Validation;
|
namespace FireflyIII\Validation;
|
||||||
|
|
||||||
use App;
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Config;
|
use Config;
|
||||||
|
use Crypt;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use Illuminate\Contracts\Encryption\DecryptException;
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
use Navigation;
|
|
||||||
use Crypt;
|
|
||||||
use Log;
|
use Log;
|
||||||
|
use Navigation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FireflyValidator
|
* Class FireflyValidator
|
||||||
@ -91,7 +90,10 @@ class FireflyValidator extends Validator
|
|||||||
* Switch on different cases on which this method can respond:
|
* Switch on different cases on which this method can respond:
|
||||||
*/
|
*/
|
||||||
$hasWhat = isset($this->data['what']);
|
$hasWhat = isset($this->data['what']);
|
||||||
$hasAccountId = isset($this->data['account_type_id']) && isset($this->data['name']);
|
$hasAccountTypeId = isset($this->data['account_type_id']) && isset($this->data['name']);
|
||||||
|
$hasAccountId = isset($this->data['id']);
|
||||||
|
$ignoreId = 0;
|
||||||
|
|
||||||
|
|
||||||
if ($hasWhat) {
|
if ($hasWhat) {
|
||||||
|
|
||||||
@ -99,26 +101,35 @@ class FireflyValidator extends Validator
|
|||||||
$type = AccountType::whereType($search)->first();
|
$type = AccountType::whereType($search)->first();
|
||||||
// this field can be used to find the exact type, and continue.
|
// this field can be used to find the exact type, and continue.
|
||||||
}
|
}
|
||||||
if($hasAccountId) {
|
if ($hasAccountTypeId) {
|
||||||
$type = AccountType::find($this->data['account_type_id']);
|
$type = AccountType::find($this->data['account_type_id']);
|
||||||
}
|
}
|
||||||
|
if ($hasAccountId) {
|
||||||
|
/** @var Account $account */
|
||||||
|
$account = Account::find($this->data['id']);
|
||||||
|
$ignoreId = intval($this->data['id']);
|
||||||
|
$type = AccountType::find($account->account_type_id);
|
||||||
|
unset($account);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to decrypt data just in case:
|
* Try to decrypt data just in case:
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
$value = Crypt::decrypt($value);
|
$value = Crypt::decrypt($value);
|
||||||
} catch(DecryptException $e) {}
|
} catch (DecryptException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (is_null($type)) {
|
if (is_null($type)) {
|
||||||
Log::error('Could not determine type of account to validate.');
|
Log::error('Could not determine type of account to validate.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all accounts with this type, and find the name.
|
// get all accounts with this type, and find the name.
|
||||||
$userId = Auth::check() ? Auth::user()->id : 0;
|
$userId = Auth::check() ? Auth::user()->id : 0;
|
||||||
$set = Account::where('account_type_id', $type->id)->where('user_id', $userId)->get();
|
$set = Account::where('account_type_id', $type->id)->where('id', '!=', $ignoreId)->where('user_id', $userId)->get();
|
||||||
/** @var Account $entry */
|
/** @var Account $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
if ($entry->name == $value) {
|
if ($entry->name == $value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user